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=1796382138; b=WumCk/qn8351tz5zak4fTz5HlnSVSN3RQlkQn8f+0S/eRMOkduzACOeVVgJEsLDMlf9m W0ZTrZg1TxwBHyXbh6HVjCehz99XK3kDAMyALxTKRUHEUh9vn1phSVG/0dHkd8SOQmRJX VaeNYOdisMJPgHZOkBuxRQJHhlNw9wmcjcNjou3BnPUlJaFQyTlGtpkizl9khaqdO1s0o MoHZK0RNCrsMYAKHhheEt/dPBDUM5r1GDGAqrtS83yn+f0VnYPQ/U7oxT4MDIyjG+xS/N ndW/VqUX6m4zSii1ubG3Xj/gyNMyWqhitf4Cqhqqyc4mVNkzXcfWcuK8TvkdYrudzcg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382138; 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=DENUkHwffjsvbiwC7Frw+Vn7mrFK9IWiOJu+XmVFeog=; b=wxGC1U6TMRcbMi88naJfHINJuhuO45bRbl29yV4wpZ473XnpsYGHeO6hEhvmBwPlIYJQ MV/qXhcRC79s8mfQjDddZzzujZ2ir2GXmJYIrHt079n3mOp4bxLJ/dHMwP2SL7rAiO5fE fvHf0Hqv4g890FtwnZFWC9Ku46HeqiacjsrqgTs0ASlMOOQXGHrn11t9AJQ0dLGErMcHx tgw9BEhipvKMHMxlOwogxxbfZi2qJ67JcTVLCymNIVPJ1hlPunsEsVQkWmrjZlXsBxPkn XSChrcoucKCUr0ywpUpYBLnPLdSbd+IKJgxbSnu4pDKw5s5dR0VRvDOPwqvRqJ915Fg== 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=pRl6OSyd; 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 931C5606A322; Fri, 4 Dec 2026 11:02:18 +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=pRl6OSyd Received: by smtp.kernel.org (Postfix) with ESMTPSA id 110F01F000C2; Fri, 4 Dec 2026 11:02:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382138; bh=DENUkHwffjsvbiwC7Frw+Vn7mrFK9IWiOJu+XmVFeog=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pRl6OSydh2tK/rjYkHkJwu6e3azFQZUePSM/zf96vMklUncTAhgkShrWle7EeeIGK 6D4OPztdMUy2vglGBXhID4S3nnGtaolOYAC02LUsVNszSgZbhqYR4o1rX4nOG+adcY dqOXK9QKSKRmHQCa2/6zGPNCkY9glb5uB564i7vw= 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.18 326/703] tg3: Fix heap overflow in unbuffered NVRAM write path Date: Fri, 4 Dec 2026 19:03:45 +0900 Message-ID: <20261204100636.457219897@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 2075d9eb8f367..f3cdf081c8ab2 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