🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20403

Re: [PATCH net v3 3/3] tg3: Fix heap overflow in unbuffered NVRAM write path

#20403
From: 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
Technical Details
Message-ID: <179534562327.3135.6438737872601204289@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368665-linux-kernel-netdev=dewy.ru
References: <20261118105408.1076095-4-pavan.chebbi@broadcom.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368665-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <179534562327.3135.6438737872601204289@kernel.org>
References: <20261118105408.1076095-4-pavan.chebbi@broadcom.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3618525"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:g6dMF44TGPxAGU5TalU+STV4WpM= sha256:kCL12ZcWbq/fWFeIXMWDCd499pIRkiap0yxjiADqS4M=
	sha1:/y+CQbAywJ0GAS0W+3DzGUVhYTE= sha256:uOJE/KlA5XYOGz3c7FndDJa9LMymGtTv2iZUR7yq52g=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 83623125D76; Sun, 22 Nov 2026 14:07:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id yi3WqvaSIWFA;
	Sun, 22 Nov 2026 14:07:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368665-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 0F83E125D74; Sun, 22 Nov 2026 14:07:07 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 90C5630326; Sun, 22 Nov 2026 11:07:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795345625;
	b=UPxanPOGcV3/rjJuhzqu9/hdBiu6nYreGflRjMNih31Crs0Wc3ifNm0nYrvotuKbwBvc
	 5tK2A5DiautaLza2TzVhHLTrE/aZKcLOZ47oupz/yy0Fc0f6wQsBeh/pOgjoQGKbW7n2n
	 N3Jl8+SQfU2tFZZUYGlqQt55Ezns191PzLgnyv0VHn0xutPzxFFfB98CGmuvr1FpMgKJo
	 UFLF6hceK3ypMNFYpDgZ5Mpq4k0hB+FV/OMOHI4K7dIpKSpomumEt6mVrMjKanjSsvN0J
	 tgVNWqigg2CaCnXOSEIEB846lxJCN1CAnxUr5f0pJX7W66an9upQU8UkPT3H6YxJpQQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795345625;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=zUKT31+fsFikHOky0ekP/ZplaKlU9TPjOWWiMxjY2Uw=;
	b=qm1GjMuHzt7XpKudclYAbjACdGGvDlTic6qXdy1NvP0SM5IINWWTejaE1sw6zrSj3jxj
	 YT1m4gLtw0Ahrw+8M65ejrJzx7U9GaWP2dFQy270jNeraWLxY1DSVcw7+HxH628KYnf27
	 Dmf6StKrbvdOAiMibrFLTjKtGpBTryyUe9JXp+9DvDMt4NOL9CHXpLu9tOhGcCdPok7lv
	 7PUky8PzZcyegBEwl3gbHkj+T/xn7WGwprFzIN90BruW0F9hEAq9mb9cB4SKoId3wkoCt
	 0XDeDYBy7W1JrqaO/hezRLOuCpqTfNYc072feK7bkvX36uTCB64gvmrmEQi0RzpiwSA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NjZDLg+R;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 300E8606A332;
	Sun, 22 Nov 2026 11:07:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NjZDLg+R
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795345624;
	b=MPwWV20L4JJiNVTKtPLHI4fuwhpThxL30wt8CBO1bEzuW2ZtwuPsSs5rxFs36a43GNN2
	 1HRKCNgIMpT9ZzLvmqou3tsWP0L6CqqVo67sQYIwX1HtKsZzFJcBxnKwIzsVpsqsO61y1
	 kdMvYcUQZ8VWHTyvXyCcZeuaaIxQKzVKo0MgZwh2JBRCoPv1uRtuCM0RnqJsvOBMG8zlI
	 Zxkux5goNm7Ln9ESeC69XxA3xewNnsCICXnBRwanM/9c/Vev7HEz2256b5bdhmbS+ES5q
	 rLLUjyZlpnE8yQPv2BjIRruqXktwMkCsxaJDRUFtH6l/6Blz3TBG73UlssHzAOhqgbA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795345624;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=zUKT31+fsFikHOky0ekP/ZplaKlU9TPjOWWiMxjY2Uw=;
	b=isrpmG1JquP2XQWMyaE4eu251IlLaVyzph/I7prq0IcaVZYiVC9cN7bU6FOPmzUHGCQS
	 ZDaiRX/RhXnakXGycclhySBXsnKJrBzu1ngpFB+hk+Owegyuuq5hIk1AmOowodv01mGSf
	 ZCwoNvA5EfJE5l04q/IfHpYq3JHZGDVxAF+jfL6giXhJ1r96fr/yCbuqgb9A4wQMRT57w
	 vm+OQwYyGYglSnNcGAh7g7xcVTgUTaGZUYrYawABLqiCVpwU4qxOIy3OTY+A344d6b45C
	 yfIRaWITcIdcif8QwkH/0TRg4+PpX7tT+TUPdCX5r5bAqenMHzWIAr5mhhOKyvLkU2Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NjZDLg+R;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FF0A606A32A
	for <netdev@vger.kernel.org>; Sun, 22 Nov 2026 11:07:04 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA3BA1F000C0;
	Sun, 22 Nov 2026 11:07:03 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795345624;
	bh=zUKT31+fsFikHOky0ekP/ZplaKlU9TPjOWWiMxjY2Uw=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=NjZDLg+RQcm61B+JYBmVExpTSCsR7dMc0g0Su7LcjYUrMmBP8NhIrMWwfTYuIGGLy
	 oU4+CBfe/8WT4k/vDDqu7+7+bIhuxmu/a6ZfjIMOwaTMxgXXyO981auCFaIPDXesfV
	 mYDZKSZjr6YF182HsyliZjGuno8bdyQmWwYQkqnoxtrUCLR3Pz653SBlo9HzCR2GVE
	 D7tjyOp9Uy6UjBJQ3k8FKGF8rB7/lc7MEb+6CWSl48np9ahha0jTYzMcpJj9ISjTaM
	 tU1PQLluhQal5xtFiQqDbdJZ8R7sLAs67S/cCbI3UO/CuLA+wGhzEjeEBuBuhOb7Y1
	 R31ZRU38Bfi2Q==
X-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
X-In-Reply-To: <20261118105408.1076095-4-pavan.chebbi@broadcom.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list