From: Pavan Chebbi <pavan.chebbi@broadcom.com>
To: michael.chan@broadcom.com, kuba@kernel.org
Cc: andrew+netdev@lunn.ch, andrew.gospodarek@broadcom.com,
davem@davemloft.net, edumazet@kernel.org, netdev@vger.kernel.org,
pabeni@redhat.com, Shravya KN <shravya.k-n@broadcom.com>,
Vishvambar Panth S <vishvambar.panth-s@broadcom.com>,
Pavan Chebbi <pavan.chebbi@broadcom.com>
Subject: [PATCH net v2 4/4] tg3: Fix heap overflow in unbuffered NVRAM write path
Date: Wed, 11 Nov 2026 18:09:16 +0530 [thread overview]
Message-ID: <20261111123917.910416-5-pavan.chebbi@broadcom.com> (raw)
In-Reply-To: <20261111123917.910416-1-pavan.chebbi@broadcom.com>
From: Shravya KN <shravya.k-n@broadcom.com>
tg3_nvram_write_block_unbuffered() reads a whole NVRAM page into a
buffer of pagesize bytes, copies the caller's data into it at page_off,
and writes the page back. The copy size was clamped to pagesize rather
than to the room left in the page, pagesize - page_off, so a write at an
offset that is not page aligned, as ETHTOOL_SEEPROM allows, copies past
the end of the buffer and corrupts the kernel heap.
Clamp size to pagesize - page_off. Also advance buf by size on each
iteration. Without this, a write that spans more than one page
programmed every page after the first with the data of the first page,
and a write that did not start on a page boundary lost the tail of the
data without reporting an error.
Reject a zero nvram_pagesize, which would otherwise make the new size
calculation wrap.
This was found by an AI code review scan. It has not been observed on
hardware, but it can be reached with ethtool -E on devices with
unbuffered flash.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reviewed-by: Vishvambar Panth S <vishvambar.panth-s@broadcom.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: Shravya KN <shravya.k-n@broadcom.com>
Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
---
drivers/net/ethernet/broadcom/tg3.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 4becd1a0b009..7558f4f164ac 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -3379,6 +3379,9 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
u32 nvram_cmd;
u8 *tmp;
+ if (!pagesize)
+ return -EINVAL;
+
tmp = kmalloc(pagesize, GFP_KERNEL);
if (tmp == NULL)
return -ENOMEM;
@@ -3399,13 +3402,14 @@ static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len,
break;
page_off = offset & pagemask;
- size = pagesize;
+ size = pagesize - page_off;
if (len < size)
size = len;
len -= size;
memcpy(tmp + page_off, buf, size);
+ buf += size;
offset = offset + (pagesize - page_off);
--
2.52.0
prev parent reply other threads:[~2026-11-11 12:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:39 [PATCH net v2 0/4] tg3: Bug fixes Pavan Chebbi
2026-11-11 12:39 ` [PATCH net v2 1/4] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported Pavan Chebbi
2026-11-11 12:39 ` [PATCH net v2 2/4] tg3: Select PLL clock when preparing for shutdown Pavan Chebbi
2026-11-11 12:39 ` [PATCH net v2 3/4] tg3: Skip querying for management FW when no NCSI present Pavan Chebbi
2026-11-11 12:39 ` Pavan Chebbi [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=20261111123917.910416-5-pavan.chebbi@broadcom.com \
--to=pavan.chebbi@broadcom.com \
--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=shravya.k-n@broadcom.com \
--cc=vishvambar.panth-s@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