🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by netdev-bot+sashiko Sun, 22 Nov 2026 11:07
Re: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
#20403
Author: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 11:07
129 lines
12549 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The new guard `if (pagesize < 4 || !is_power_of_2(pagesize))
  return -EINVAL;` in tg3_nvram_write_block_unbuffered()…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch only
  partly closes it.

--

tg3: Fix heap overflow in unbuffered NVRAM write path

This patch changes tg3_nvram_write_block_unbuffered() to clamp the copy
size to the room left in the current page and to advance buf on each
iteration. It also rejects an nvram_pagesize that is smaller than 4 or
not a power of two, so ethtool -E fails with -EINVAL in those cases.

> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> index 5a0e247a4c463..12f199355984b 100644
> --- a/drivers/net/ethernet/broadcom/tg3.c
> +++ b/drivers/net/ethernet/broadcom/tg3.c

[ ... ]

> @@ -3379,6 +3380,9 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
>  	u32 nvram_cmd;
>  	u8 *tmp;
>  
> +	if (pagesize < 4 || !is_power_of_2(pagesize))
> +		return -EINVAL;
> +

[Severity: Medium]
Will this check reject every NVRAM write on 5750/5780 boards that use SST
flash?

tg3_get_nvram_info() sets up the SST parts without NVRAM_BUFFERED:

drivers/net/ethernet/broadcom/tg3.c:tg3_get_nvram_info() {
    ...
		case FLASH_VENDOR_SST_SMALL:
		case FLASH_VENDOR_SST_LARGE:
			tp->nvram_jedecnum = JEDEC_SST;
			tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE;
			break;
    ...
}

The constant is defined in tg3.h as:

#define SST_25VF0X0_PAGE_SIZE		4098

FLASH is set from NVRAM_CFG1_FLASHIF_ENAB. Because of that,
tg3_nvram_write_block() sends these devices down the unbuffered path:

	if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) {
		ret = tg3_nvram_write_block_buffered(tp, offset, len,
			buf);
	} else {
		/* unbuffered writer */

is_power_of_2(4098) is false. So tg3_set_eeprom() -> tg3_nvram_write_block()
-> tg3_nvram_write_block_unbuffered() returns -EINVAL every time.

The value 4098 looks like a typo for 4096, since SST25VF0x0 parts use
4 KiB sectors. Before this patch these boards were already broken: pagemask
was 0x1001, and the read loop wrote 4 bytes at tmp + 4096 into a 4098 byte
buffer. The new check stops that overflow, but it does so by refusing the
write rather than fixing the page size.

The commit message says:

    A page size of 0, which tg3_get_nvram_info() leaves unset for
    an unhandled flash vendor, also made the loop issue erase commands at
    address 0 forever with the rtnl and NVRAM locks held.  ethtool -E now
    fails with -EINVAL in these cases.

It does not say that a flash vendor the driver supports now always fails.

Should SST_25VF0X0_PAGE_SIZE be changed to 4096 as part of this fix? If
not, could the commit message mention the SST case for maintainers and
stable backporters?

[Severity: High]
This is a pre-existing issue, not one introduced by this patch, but the
unset page size case named in the commit message is only partly covered.
The new check only exists in the unbuffered writer.
tg3_nvram_write_block_buffered() still divides by the page size without
checking it:

drivers/net/ethernet/broadcom/tg3.c:tg3_nvram_write_block_buffered() {
    ...
		page_off = offset % tp->nvram_pagesize;
    ...
}

tg3_nvram_write_block() takes this path whenever FLASH is clear.

The vendor switches in tg3_get_5755_nvram_info(), tg3_get_5787_nvram_info()
and tg3_get_5761_nvram_info() have no default case, and FLASH is only set
inside matched cases. tg3_get_nvram_info() on 5750/5780 class parts is the
same when NVRAM_CFG1_FLASHIF_ENAB is clear and the vendor does not match.
In all of these cases nvram_pagesize stays 0 and FLASH stays clear.

tg3_get_nvram_size() still sets nvram_size, so ethtool_set_eeprom() passes
its length checks. The call chain is then:

tg3_set_eeprom()
  tg3_nvram_write_block()
    tg3_nvram_write_block_buffered()
      offset % 0

Can this hit a divide error oops while rtnl and the NVRAM lock are held?
If so, would it make sense to do the same page size check in
tg3_nvram_write_block() so that both writers are covered?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118105408.1076095-1-pavan.chebbi%40broadcom.com
Re: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
#21741
Author: Simon Horman
Date: Tue, 24 Nov 2026 11:54
22 lines
8999 bytes
On Sun, Nov 22, 2026 at 05:13:51PM +0530, Pavan Chebbi wrote:
> On Sun, Nov 22, 2026 at 4:37 PM <netdev-bot+sashiko@kernel.org> wrote:

...

> Yes, ethtool -E will now fail with -EINVAL on 5750/5780 boards with SST
> flash, since SST_25VF0X0_PAGE_SIZE is 4098.  But the unbuffered path
> cannot work correctly with a non power of two page size.  With pagemask as
> 0x1001, phy_addr is not always page aligned, the read loop runs to
> j = 4096 and writes 4 bytes at tmp + 4096 of a 4098 byte kmalloc buffer,
> which KASAN reports as out of bounds, the program loop then programs 4100
> bytes, and NVRAM_CMD_LAST is never set because pagesize - 4 is 4094. I
> have no such board to test, so I cannot say how these writes behaved
> in practice,
> but refusing them looks better than erasing a sector and programming past it.
> 
> Also I would rather not change the constant to 4096 in this patch.  That
> would enable the unbuffered erase and program sequence on SST parts for
> the first time, and I cannot validate it on hardware.

Reviewed-by: Simon Horman <horms@kernel.org>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads