From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383651; b=VwCzb420U6L1Q3tGTiJj4ZrjLxNILjap/B0iYdfAT4ZKMzDbPNgEN+rQX/HOpAJBR+x9 jidpH9+eO6i+LPEdquqvsi6SFyBwGt3XvhN7n3ekx7hcQXefz/hpRNY9kPvRNzemVhpcU D+7Ejzz5olBS/rTBEJ18GctsdevUzmXuKZyrQC069WEj+B9URfLYLJg5BKUMNEIxu6/Dq X48VmhcuwwvT0UXXY1S3h5AxVjkSAp5kbU2gJeYfXqr/Jzp7X8hG3iN7G/KPQn2SkkH/O CNHIHuwWfZEb4/EbDGwhWXoMYz0cjceCvbA3SK8SgglZIjGdO8OnkFBVECQFSW2hpXw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383651; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=WusfsptxOWFGA7ENZP7mrY/MTll0O9Hmj06dP4ctBQs=; b=lg8uZTPpPRUSiS9uiyBigKz1hnva5DoaExaJbU3DLSoT0IU9nteMWj9ZGGSP7eGfOROA uSG5TcSDE1vKcJU0lpNphzEYUxhDIkevzk/jROBzilDFuR1wjLA/Ywp/LOP4199hTUSvl 8QqkP9e4ncl7Qh8//t7lGJK+RtPOtoIQP2k6+f7756zTUYZLRmxCqpeZCKjn8BSMueAEw 3Lic2Np8gyKzvc53TU3gxHoFrYslvPo7BVGAvtKLexhd+CucFZHDgzfAjXAJXJfurZzcz 9ZjpAn9fNc5TGxlXDIe9y44EFJoPvQWquOxpZV4EtEDNr//u2ht2bIAX8ViU0QkZH1w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VYg9IcY9; arc=none smtp.remote-ip=100.103.45.18 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 D7796606A322; Fri, 4 Dec 2026 11:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VYg9IcY9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52FEE1F00897; Fri, 4 Dec 2026 11:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383651; bh=WusfsptxOWFGA7ENZP7mrY/MTll0O9Hmj06dP4ctBQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VYg9IcY9pxy2FAVgdNXVDnJN3QcW31iMudBZxxxmEqBF2blY7HRyLMHBlGJZBdlSQ yw7RHcmjwuvel/A5ip9MTc83/hP0n4+Xd4OZL7jXBS7ylFdBDd3T24RKsQ9oImARZF gDS6SSxpedqW9DbyJV7sgP9UPmYDxhiJzjgUrnUo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shravya KN , Pavan Chebbi , Simon Horman , Paolo Abeni , Sasha Levin Subject: [PATCH 6.12 312/555] tg3: Fix heap overflow in unbuffered NVRAM write path Date: Fri, 4 Dec 2026 19:05:55 +0900 Message-ID: <20261204100621.361719386@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shravya KN [ Upstream commit 0323a427052447e2c41c650fc98a6c04bf417e5d ] 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 Signed-off-by: Pavan Chebbi Reviewed-by: Simon Horman Link: https://patch.msgid.link/20261118105408.1076095-4-pavan.chebbi@broadcom.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- 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 a243c38a16f2e..9c29abeb48dfb 100644 --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -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.53.0