From: netdev-bot+sashiko@kernel.org
To: pavan.chebbi@broadcom.com
Cc: michael.chan@broadcom.com, kuba@kernel.org,
andrew+netdev@lunn.ch, andrew.gospodarek@broadcom.com,
davem@davemloft.net, edumazet@kernel.org, netdev@vger.kernel.org,
pabeni@redhat.com, shravya.k-n@broadcom.com
Subject: Re: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
Date: Sun, 22 Nov 2026 11:07:03 +0000 [thread overview]
Message-ID: <179534562327.3135.6438737872601204289@kernel.org> (raw)
In-Reply-To: <20261118105408.1076095-4-pavan.chebbi@broadcom.com>
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
prev parent reply other threads:[~2026-11-22 11:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 10:54 [PATCH net v3 0/3] tg3: Bug fixes Pavan Chebbi
2026-11-18 10:52 ` netdev-bot+sinfo
2026-11-18 10:54 ` [PATCH net v3 1/3] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported Pavan Chebbi
2026-11-22 11:07 ` netdev-bot+sashiko
2026-11-18 10:54 ` [PATCH net v3 2/3] tg3: Skip management FW version when APE firmware is not ready Pavan Chebbi
2026-11-18 10:54 ` [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path Pavan Chebbi
2026-11-22 11:07 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179534562327.3135.6438737872601204289@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=andrew.gospodarek@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=shravya.k-n@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox