tg3: Bug fixes
Subsystems (3)
Pavan Chebbi
maintainerv3 cover tg3: Bug fixes
This patchset has 4 fixes. The first patch restores probe on 57766 when the 31-bit coherent DMA mask cannot be set. The second patch makes NCSI PLL lock on the TLP clock to fix WOL at 1G speed on 5720. The third patch fixes ethtool -i display on 5719/5720 when NCSI component is missing. The fourth one fixes a possible heap overflow in the NVRAM write path.
v3: Dropped patch #2 (PLL clock source) from the series. It is being
reworked and will be resubmitted after the reporter has tested it. Addressed Sashiko warnings on:
- patch #2 (was #3 in v2) to describe the version register as holding no valid data, instead of "uninitialized memory", to correct the Fixes tag to 165f4d1cb3d7, and to document the return value of tg3_probe_ncsi().
- patch #3 (was #4 in v2) to reject an NVRAM page size that is smaller than 4 or not a power of two, instead of only a zero page size.
v2: Addressed Sashiko warnings on:
- patch #2 such that the PLL clock bit is set only at system suspend and power off, cleared on resume and at probe and updated under the APE lock.
- patch #4 to reject a zero NVRAM page size and to describe the buf advance fix and its reach.
v1:
https://lore.kernel.org/all/[email protected]/
Pavan Chebbi (2):
tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
tg3: Skip management FW version when APE firmware is not ready
Shravya KN (1):
tg3: Fix heap overflow in unbuffered NVRAM write path
drivers/net/ethernet/broadcom/tg3.c | 43 +++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-)
Signature · 1 line
2.52.0
Pavan Chebbi
maintainerPATCH v3 1/3 tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
Commit 614f4d166eee ("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets") lowered the coherent DMA mask to 31 bits as a workaround for a spurious address overflow error in the hardware. The result of dma_set_coherent_mask() is fatal to probe, so on platforms that cannot satisfy such a mask the device fails to probe:
tg3 0000:01:00.0: Unable to obtain 64 bit DMA for consistent allocations tg3 0000:01:00.0: probe with driver tg3 failed with error -5
This was reported on a Mac mini (Macmini6,2, BCM57766) running a kernel built without CONFIG_ZONE_DMA and with IOMMU passthrough as the default. Without CONFIG_ZONE_DMA, dma_direct_supported() only accepts a mask narrower than 32 bits if it covers the highest physical memory address, so with direct mapping a 31-bit coherent mask is rejected whenever memory extends above 2GB.
Treat the 31-bit mask as best effort. If it is refused, warn and fall back to the mask used before 614f4d166eee, so that the device still probes. Platforms that accept the mask are unaffected. Where it is refused, 614f4d166eee never protected the device, it only stopped it from probing, so this restores the behaviour of kernels before that commit. Warn when a status block lands at an address matching the pattern described in 614f4d166eee, so that a resulting TX timeout can be identified.
--- drivers/net/ethernet/broadcom/tg3.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +18 -3
@@ -8867,6 +8867,13 @@ static int tg3_alloc_consistent(struct tg3 *tp)if (!tnapi->hw_status) goto err_out; +if (tg3_asic_rev (tp) ==ASIC_REV_57766 && + (lower_32_bits (tnapi->status_mapping) &0xffff0000 ) == +0xffff0000 ) +dev_warn (&tp->pdev->dev, +"Status block at DMA address %pad may cause TX timeouts on this device\n" , + &tnapi->status_mapping); + sblk = tnapi->hw_status;if (tg3_flag (tp,ENABLE_RSS )) {
@@ -17756,6 +17763,7 @@ static int tg3_init_one(struct pci_dev *pdev,u64 dma_mask, persist_dma_mask;netdev_features_t features =0 ;u8 addr[ETH_ALEN ]__aligned(2) ; +u64 test_dma_mask =0 ; err =pci_enable_device (pdev);if (err) {
@@ -17895,15 +17903,22 @@ static int tg3_init_one(struct pci_dev *pdev, persist_dma_mask = dma_mask =DMA_BIT_MASK (64 );if (tg3_asic_rev (tp) ==ASIC_REV_57766 ) - persist_dma_mask =DMA_BIT_MASK (31 ); + test_dma_mask =DMA_BIT_MASK (31 );/* Configure DMA attributes. */ if (dma_mask >DMA_BIT_MASK (32 )) { err =dma_set_mask (&pdev->dev, dma_mask);if (!err) { features |=NETIF_F_HIGHDMA ; - err =dma_set_coherent_mask (&pdev->dev, - persist_dma_mask); +if (!test_dma_mask || +dma_set_coherent_mask (&pdev->dev, + test_dma_mask)) { +if (test_dma_mask) +dev_warn (&pdev->dev, +"Unable to set 31 bit coherent DMA mask, workaround not applied\n" ); + err =dma_set_coherent_mask (&pdev->dev, + persist_dma_mask); + }if (err <0 ) {dev_err (&pdev->dev,"Unable to obtain 64 bit " "DMA for consistent allocations\n" );
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net v3 1/3] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] On BCM57766, tg3_alloc_consistent() (drivers/net/ethernet/broadcom/tg3.c, around line 8870) can find that…
--
tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
This patch makes the 31-bit coherent DMA mask for BCM57766 best effort. If the platform refuses that mask, the driver falls back to the coherent mask used before 614f4d166eee, so probe no longer fails. It also adds a warning when a status block is allocated at a DMA address that matches the erratum pattern described in 614f4d166eee.
Quoted 5 lines
drivers/net/ethernet/broadcom/tg3.c +0
-0
drivers/net/ethernet/broadcom/tg3.c static int tg3_alloc_consistent(struct tg3 *tp) · line 8876
Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +7
-0@@ -8867,6 +8867,13 @@ static int tg3_alloc_consistent(struct tg3 *tp)if (!tnapi->hw_status) goto err_out; +if (tg3_asic_rev (tp) ==ASIC_REV_57766 && + (lower_32_bits (tnapi->status_mapping) &0xffff0000 ) == +0xffff0000 ) +dev_warn (&tp->pdev->dev, +"Status block at DMA address %pad may cause TX timeouts on this device\n" , + &tnapi->status_mapping); +
[Severity: Low]
When the status block lands at an address that matches the erratum pattern, the driver keeps the buffer. tg3_rings_reset() later writes that address into the chip:
tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, ((u64) tnapi->status_mapping >> 32)); tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, ((u64) tnapi->status_mapping & 0xffffffff));
tg3_alloc_consistent() is only called from tg3_start(). A recovery reset therefore writes the same address again. That covers both the tg3_process_error() "DMA Status error. Resetting chip." path and a TX timeout reset. Only closing and reopening the interface gets a new allocation.
Could the driver hold on to the matching buffer and allocate a replacement instead? That would keep the workaround in effect on platforms that refuse the 31-bit mask.
The warning also gives TX timeouts as the symptom. 614f4d166eee says the hardware sets the overflow bit in the DMA status register, and tg3_process_error() would report that as a DMA status error.
Are TX timeouts the expected symptom here, or should the message also mention the DMA status error?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118105408.1076095-1-pavan.chebbi%40broadcom.com
Simon Horman
reviewerRe: [PATCH net v3 1/3] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
In reply to Pavan ChebbiQuoted 16 lines · Pavan Chebbi
Commit
614f4d166eee("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets") lowered the coherent DMA mask to 31 bits as a workaround for a spurious address overflow error in the hardware. The result ofdma_set_coherent_mask()is fatal to probe, so on platforms that cannot satisfy such a mask the device fails to probe:tg3 0000:01:00.0: Unable to obtain 64 bit DMA for consistent allocations tg3 0000:01:00.0: probe with driver tg3 failed with error -5
This was reported on a Mac mini (Macmini6,2, BCM57766) running a kernel built without
CONFIG_ZONE_DMAand with IOMMU passthrough as the default. WithoutCONFIG_ZONE_DMA,dma_direct_supported()only accepts a mask narrower than 32 bits if it covers the highest physical memory address, so with direct mapping a 31-bit coherent mask is rejected whenever memory extends above 2GB.
Quoted 8 lines
Treat the 31-bit mask as best effort. If it is refused, warn and fall back to the mask used before
614f4d166eee, so that the device still probes. Platforms that accept the mask are unaffected. Where it is refused,614f4d166eeenever protected the device, it only stopped it from probing, so this restores the behaviour of kernels before that commit. Warn when a status block lands at an address matching the pattern described in614f4d166eee, so that a resulting TX timeout can be identified.
Hi Pavan,
I am not following how a BCM57766 device can be used on a system that rejects a 31-bit mask. Is the idea that TX timeouts are infrequent and can be lived with in such an environment?
Quoted 5 lines
Fixes 614f4d166eee ("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets")Reported-by Rui Salvaterra <[email protected]>Link https://lore.kernel.org/netdev/CALjTZvYKHWrD5m+RXimjxODvpFPw7Cq_EOEuzRi1PZT9_JxF+g@mail.gmail.com/ open hereSigned-off-by Pavan Chebbi <[email protected]>
...
Pavan Chebbi
maintainerRe: [PATCH net v3 1/3] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
Quoted 27 lines · Simon Horman
Quoted 16 lines · Pavan Chebbi
Commit
614f4d166eee("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets") lowered the coherent DMA mask to 31 bits as a workaround for a spurious address overflow error in the hardware. The result ofdma_set_coherent_mask()is fatal to probe, so on platforms that cannot satisfy such a mask the device fails to probe:tg3 0000:01:00.0: Unable to obtain 64 bit DMA for consistent allocations tg3 0000:01:00.0: probe with driver tg3 failed with error -5
This was reported on a Mac mini (Macmini6,2, BCM57766) running a kernel built without
CONFIG_ZONE_DMAand with IOMMU passthrough as the default. WithoutCONFIG_ZONE_DMA,dma_direct_supported()only accepts a mask narrower than 32 bits if it covers the highest physical memory address, so with direct mapping a 31-bit coherent mask is rejected whenever memory extends above 2GB.Quoted 8 lines
Treat the 31-bit mask as best effort. If it is refused, warn and fall back to the mask used before
614f4d166eee, so that the device still probes. Platforms that accept the mask are unaffected. Where it is refused,614f4d166eeenever protected the device, it only stopped it from probing, so this restores the behaviour of kernels before that commit. Warn when a status block lands at an address matching the pattern described in614f4d166eee, so that a resulting TX timeout can be identified.
Quoted 6 lines
Hi Pavan,
I am not following how a BCM57766 device can be used on a system that rejects a 31-bit mask. Is the idea that TX timeouts are infrequent and can be lived with in such an environment?
Hi Simon, thanks for the review. The report comes from a late-2012 Mac mini (Macmini6.2) with a BCM57766. Its NIC worked until 614f4d166eee made the 31-bit coherent mask change, which that machine does not accept, so probe has failed there since.
To your question, yes, I think it can be lived with. The erratum is triggered only
when the status block lands at a specific address, and if it does, the driver's reset
logic kicks in and the warning points to the cause. That is better than the device
not probing at all. Platforms that accept the mask are unaffected.
Quoted 7 lines
Quoted 5 lines
Fixes 614f4d166eee ("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets")Reported-by Rui Salvaterra <[email protected]>Link https://lore.kernel.org/netdev/CALjTZvYKHWrD5m+RXimjxODvpFPw7Cq_EOEuzRi1PZT9_JxF+g@mail.gmail.com/ open hereSigned-off-by Pavan Chebbi <[email protected]>...
Re: [PATCH net v3 1/3] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
Quoted 40 lines · Pavan Chebbi
Quoted 27 lines · Simon Horman
Quoted 16 lines · Pavan Chebbi
Commit
614f4d166eee("tg3: Set coherent DMA mask bits to 31 for BCM57766 chipsets") lowered the coherent DMA mask to 31 bits as a workaround for a spurious address overflow error in the hardware. The result ofdma_set_coherent_mask()is fatal to probe, so on platforms that cannot satisfy such a mask the device fails to probe:tg3 0000:01:00.0: Unable to obtain 64 bit DMA for consistent allocations tg3 0000:01:00.0: probe with driver tg3 failed with error -5
This was reported on a Mac mini (Macmini6,2, BCM57766) running a kernel built without
CONFIG_ZONE_DMAand with IOMMU passthrough as the default. WithoutCONFIG_ZONE_DMA,dma_direct_supported()only accepts a mask narrower than 32 bits if it covers the highest physical memory address, so with direct mapping a 31-bit coherent mask is rejected whenever memory extends above 2GB.Quoted 8 lines
Treat the 31-bit mask as best effort. If it is refused, warn and fall back to the mask used before
614f4d166eee, so that the device still probes. Platforms that accept the mask are unaffected. Where it is refused,614f4d166eeenever protected the device, it only stopped it from probing, so this restores the behaviour of kernels before that commit. Warn when a status block lands at an address matching the pattern described in614f4d166eee, so that a resulting TX timeout can be identified.Quoted 6 lines
Hi Pavan,
I am not following how a BCM57766 device can be used on a system that rejects a 31-bit mask. Is the idea that TX timeouts are infrequent and can be lived with in such an environment?
Hi Simon, thanks for the review. The report comes from a late-2012 Mac mini (Macmini6.2) with a BCM57766. Its NIC worked until
614f4d166eeemade the 31-bit coherent mask change, which that machine does not accept, so probe has failed there since.
Quoted 7 lines
To your question, yes, I think it can be lived with. The erratum is triggered only
when the status block lands at a specific address, and if it does, the driver's reset
logic kicks in and the warning points to the cause. That is better than the device
not probing at all. Platforms that accept the mask are unaffected.
Hi Pravan,
Thanks for the clarification. I agree this is a reasonable trade-off.
Pavan Chebbi
maintainerPATCH v3 2/3 tg3: Skip management FW version when APE firmware is not ready
In reply to Pavan ChebbiWhen the APE firmware is not present or not ready, for example when the NCSI component is missing in the NVRAM, tg3_read_fw_ver() still calls tg3_read_dash_ver() after tg3_probe_ncsi(). The signature and ready checks that tg3_read_dash_ver() used to make were moved into tg3_probe_ncsi(), which only sets the NCSI flag and does not stop the caller. The driver then reads the APE firmware version register, which holds no valid data in this state, and ethtool -i shows an invalid "DASH" string with a garbage version.
Make tg3_probe_ncsi() return whether valid, ready APE firmware was found, and read the version only in that case. Otherwise just report the bootcode version.
This was seen by a user on BCM5719/BCM5720 with no NCSI component in the NVRAM. With this change, ethtool -i displays only the bootcode version.
--- drivers/net/ethernet/broadcom/tg3.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +10 -5
@@ -15997,20 +15997,26 @@ static void tg3_read_mgmtfw_ver(struct tg3 *tp) } } -static void tg3_probe_ncsi (struct tg3 *tp) +/* Returns true if valid, ready APE firmware is present, regardless of +* whether it advertises NCSI (it may be DASH or SMASH). Sets APE_HAS_NCSI +* if the NCSI feature is advertised. +*/ +static bool tg3_probe_ncsi (struct tg3 *tp) {u32 apedata; apedata =tg3_ape_read32 (tp,TG3_APE_SEG_SIG );if (apedata !=APE_SEG_SIG_MAGIC ) -return ; +return false; apedata =tg3_ape_read32 (tp,TG3_APE_FW_STATUS );if (!(apedata &APE_FW_STATUS_READY )) -return ; +return false;if (tg3_ape_read32 (tp,TG3_APE_FW_FEATURES ) &TG3_APE_FW_FEATURE_NCSI )tg3_flag_set (tp,APE_HAS_NCSI ); + +return true; }static void tg3_read_dash_ver (struct tg3 *tp)
@@ -16089,8 +16095,7 @@ static void tg3_read_fw_ver(struct tg3 *tp)if (tg3_flag (tp,ENABLE_ASF )) {if (tg3_flag (tp,ENABLE_APE )) { -tg3_probe_ncsi (tp); -if (!vpd_vers) +if (tg3_probe_ncsi (tp) && !vpd_vers)tg3_read_dash_ver (tp); }else if (!vpd_vers) {tg3_read_mgmtfw_ver (tp);
Signature · 1 line
2.52.0
Re: [PATCH net v3 2/3] tg3: Skip management FW version when APE firmware is not ready
Quoted 13 lines · Pavan Chebbi
When the APE firmware is not present or not ready, for example when the NCSI component is missing in the NVRAM,
tg3_read_fw_ver()still callstg3_read_dash_ver()aftertg3_probe_ncsi(). The signature and ready checks thattg3_read_dash_ver()used to make were moved intotg3_probe_ncsi(), which only sets the NCSI flag and does not stop the caller. The driver then reads the APE firmware version register, which holds no valid data in this state, and ethtool -i shows an invalid "DASH" string with a garbage version.Make
tg3_probe_ncsi()return whether valid, ready APE firmware was found, and read the version only in that case. Otherwise just report the bootcode version.
Quoted 6 lines
This was seen by a user on BCM5719/BCM5720 with no NCSI component in the NVRAM. With this change, ethtool -i displays only the bootcode version.
Fixes 165f4d1cb3d7 ("tg3: Fix the setting of the APE_HAS_NCSI flag")Signed-off-by Pavan Chebbi <[email protected]>
Pavan Chebbi
maintainerPATCH v3 3/3 tg3: Fix heap overflow in unbuffered NVRAM write path
In reply to Pavan ChebbiFrom: Shravya KN <[email protected]>
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.
--- drivers/net/ethernet/broadcom/tg3.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/tg3.c +6 -1
@@ -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);
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
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.
Quoted 4 lines
drivers/net/ethernet/broadcom/tg3.c +0
-0
[ ... ]
drivers/net/ethernet/broadcom/tg3.c static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, · line 3385
Quoted 7 lines
drivers/net/ethernet/broadcom/tg3.c +3
-0@@ -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?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118105408.1076095-1-pavan.chebbi%40broadcom.com
Pavan Chebbi
maintainerRe: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
Quoted 88 lines · On Sun, Nov 22, 2026 at 4:37 PM <[email protected]> wrote:
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 annvram_pagesizethat is smaller than 4 or not a power of two, so ethtool -E fails with-EINVALin those cases.Quoted 4 lines
drivers/net/ethernet/broadcom/tg3.c +0
-0[ ... ]
drivers/net/ethernet/broadcom/tg3.c static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, · line 3385
Quoted 7 lines
drivers/net/ethernet/broadcom/tg3.c +3
-0@@ -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 withoutNVRAM_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.has:#define
SST_25VF0X0_PAGE_SIZE4098FLASH 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. Sotg3_set_eeprom()->tg3_nvram_write_block()->tg3_nvram_write_block_unbuffered()returns-EINVALevery 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-EINVALin these cases.
Quoted 6 lines
It does not say that a flash vendor the driver supports now always fails.
Should
SST_25VF0X0_PAGE_SIZEbe changed to 4096 as part of this fix? If not, could the commit message mention the SST case for maintainers and stable backporters?
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.
Re: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path
Quoted 1 line · Pavan Chebbi
On Sun, Nov 22, 2026 at 4:37 PM <[email protected]> wrote:
...
Quoted 11 lines
Yes, ethtool -E will now fail with
-EINVALon 5750/5780 boards with SST flash, sinceSST_25VF0X0_PAGE_SIZEis 4098. But the unbuffered path cannot work correctly with a non power of two page size. With pagemask as0x1001,phy_addris 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, andNVRAM_CMD_LASTis 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.
Quoted 3 lines
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.
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Wed, 18 Nov 2026 16:24:05 +0530 you wrote:
This patchset has 4 fixes. The first patch restores probe on 57766 when the 31-bit coherent DMA mask cannot be set. The second patch makes NCSI PLL lock on the TLP clock to fix WOL at 1G speed on 5720. The third patch fixes ethtool -i display on 5719/5720 when NCSI component is missing. The fourth one fixes a possible heap overflow in the NVRAM write path.
[...]
Here is the summary with links:
- [net,v3,1/3] tg3: Don't fail probe if 31-bit coherent DMA mask is unsupported
https://git.kernel.org/netdev/net/c/686b8dbcedf8 - [net,v3,2/3] tg3: Skip management FW version when APE firmware is not ready https://git.kernel.org/netdev/net/c/70e57e1255e0 - [net,v3,3/3] tg3: Fix heap overflow in unbuffered NVRAM write path https://git.kernel.org/netdev/net/c/0323a4270524
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html