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>,
Pavan Chebbi <pavan.chebbi@broadcom.com>
Subject: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
Date: Wed, 18 Nov 2026 16:24:08 +0530 [thread overview]
Message-ID: <20261118105408.1076095-4-pavan.chebbi@broadcom.com> (raw)
In-Reply-To: <20261118105408.1076095-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 an nvram_pagesize that is smaller than 4 or not a power of two.
The page mask is pagesize - 1, which is only a valid mask for a power
of two. 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.
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")
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 | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 5a0e247a4c46..12f199355984 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -56,6 +56,7 @@
#include <linux/hwmon-sysfs.h>
#include <linux/crc32.h>
#include <linux/dmi.h>
+#include <linux/log2.h>
#include <net/checksum.h>
#include <net/gso.h>
@@ -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;
+
tmp = kmalloc(pagesize, GFP_KERNEL);
if (tmp == NULL)
return -ENOMEM;
@@ -3399,13 +3403,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-18 10:51 UTC|newest]
Thread overview: 5+ 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-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 ` 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=20261118105408.1076095-4-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 \
/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