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=1796380622; b=yvr3mOYbKiaJ/FgCEy1mVczoKDdV/5mkfMyWc+vaeZY7KeHElyKl9ZRhCuv5onmcqMbU lXjpleNZPGErljWVJ55Vr1ugbUv6Ekv9tgZrjPTS69mg4fuV1nF1kD5fKOchcm+2Z9w/9 Fqgx+vcvOMgaOaj0L0e/GfJorXBX4RgHxSrtr9sdK8RhUjl2jym2gY0gKH7PTuVnIu1Lx WbEqvCNK5DrGAaFpSPPcoYt5i1UHxPDQFY7QWnoqRWvLLQxnm97J4exeQGVvzTCP7+8Qc 7+6wuJTQmqi2rk4OfzddcxZSeRYGc7Z80883a57mgOb80L6G3NiNx0Gj7XjJ//0hGnw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380622; 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=YnB0NM7acu/1dkb6wAu5MOtzyGwxaKD2NLTwjz5v2Pk=; b=wD5BIZE++psHTj4o3CZReBuaTtqklZmfgKc45Mda5sGfyXZJFkO/UEQF5gP9p/GgW6PS 1y1rUmpXb1v9qu95kKWPYlxeGd6nvUuhJPjuASS7aXZsgyTF6OXZPQu5/z4tdF1KH0ZOe Uk10HglxFUNJAbn8mnDn40HjMUNzotp60WdKOO928quS5pnmrVqNTFMhx2e1b1Flh6GsB ly0HwUJTMTVS7Kcobzb3tZLI4GnhSjNL67zEG5aP7vrkDY6ldoKy4TnTPdiFgOeB5mCDQ aBLkpB8WKivCvCJ8Ix/SU/95Dot+vG5XQTfjaHfTUOpp+qPq5sd3grW4Hq+1pjMwjJA== 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=VXFLiRYL; 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 CEABA606A688; Fri, 4 Dec 2026 10:37:02 +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=VXFLiRYL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D6AC1F0092C; Fri, 4 Dec 2026 10:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380622; bh=YnB0NM7acu/1dkb6wAu5MOtzyGwxaKD2NLTwjz5v2Pk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VXFLiRYLbA9RNgUeQcHp1qQDysSdWfsacvxaPj20xEB7YJEjDchHqSC4LB1Cl47w+ nGiJCCxDBOn/HQCLj3D7LgRK76O2ILPcsPb0V+0kdUfwFbt9tf72dpNqIQDi9eadnj VzWr35Fx445h0rwFql/Xq5PcAmMb12HbZmU/Mi3w= 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 7.3 312/742] tg3: Fix heap overflow in unbuffered NVRAM write path Date: Fri, 4 Dec 2026 19:02:56 +0900 Message-ID: <20261204100643.320429218@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 4bd64124bdd9f..4154a765767c3 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