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=1796167648; b=OyPTZz86QLy5s2CLDmd/Q+uzwY2DkjPAX9zZGc022+SjuT5216pbHJGDqdvPHuOn4fnO XappSBmhlg9u1FJ2Va7d90ICZTLqylUqTUiNdoLmxtAq5guI8iWLEY6omvkPJBIgs+Fym iY8cvRlDmESkdDealGaZ4qYi5nUcy3X3WNOE3Tn+wY15aqQZ8ykCDv0gl8z3EPKgPF5pN 7Z6RXaWinv+71MW0LxYViV9w0OHuZQW6lOO0oN48XaiBHzVXNU0qINuu5wpTUpBgDOdyN yfLkqjvbp0vya3+nCt6GP3kScUAFzFtNQM5d74rGPmCF2Fq9+6/iGswMFUKe5C4Cyag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167648; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=tBA0GdaHI+Gx+DMzdn74kCGOx5wVOi5W4mNVYAnbk9I=; b=adgLAmlNFDKhiePJJtdbX/41lHBHZ0oi/c1mUtl8RjkR+HwCdgWLg5n+eK8tvFyE4Rsd GpXEyr0EJBZIA0Bna01V06hbUaQhweZ05g61Dq5/ei6O8DWC/HsLDEbGMlLYxlbyazrc3 bAwhBD1NFU9BaAE//87PyYFxw6NXLyzpY01ujotr0u+tLkFgzRzlwD1lUPE72UaeKSFJ2 e/HUo4whZYxvbAm+hgNF0X7cwQQm0RspxZZvP6nrAIOsZXqSFrXbO2AssTEC4FUNI8VGG Fc/Xm/3EpwfEDNHRpI0iBg00/YaWUcmJbOS1qm/xRY3B0gZQVNF5ifI9lzCmXRDPbqg== 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=ArqgRdFO; 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 7D5E2606A320; Tue, 1 Dec 2026 23:27:28 +0000 (UTC) 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=ArqgRdFO Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAA6B1F0089B; Tue, 1 Dec 2026 23:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796167648; bh=tBA0GdaHI+Gx+DMzdn74kCGOx5wVOi5W4mNVYAnbk9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ArqgRdFOtZt7JBqnl6dM0UJpJlQpnBTDUghuno8ldhX8wtPiikTxfmLAXjX6dj//8 +Yjfeda7qBkc7nL6Bpp7i6CZNu+oRfSaxYoVuzvdLET3+avEI3927TpgQMp5HJfc0a oR+claRsXbDq4Y0GyzIlowNd65lUfVuJBUHDFv9XAyDeMLWmrJvz+AEGcRFzGz934M 2soOYo63eoCrk6awBICAD4afiCtX5bz3y1CfxYEvtbDLyKmyZgK1/SuCvn0+nn5//o Sw/szE6xG2DVfxEJdWBBta5X1cQcOqWxYwAUF9+buY2WA18+z7PYhU28GaW1QN0lep XP/MnsqkRc4Pw== From: srini@kernel.org To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Sanman Pradhan , stable@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH 10/10] nvmem: sprd: fix out-of-bounds read in sprd_efuse_read() Date: Tue, 1 Dec 2026 23:26:57 +0000 Message-ID: <20261201232657.537736-11-srini@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201232657.537736-1-srini@kernel.org> References: <20261201232657.537736-1-srini@kernel.org> 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 From: Sanman Pradhan sprd_efuse_read() reads a single four-byte block into the stack variable "data" and then copies the caller's full "bytes" length from it. The provider advertises word_size and stride of 1, so a whole-device sysfs read reaches the callback as a single 96-byte request, and __nvmem_cell_read() likewise submits cell->raw_len in one call. Reading the whole device (96 bytes for ums312_data) therefore copies 92 bytes past the end of the four-byte stack variable into the caller's buffer. The read is reachable from the nvmem sysfs file when CONFIG_NVMEM_SYSFS is enabled, and from any DT cell wider than four bytes. Only the first block is read, so the returned data is also incorrect: later blocks are never fetched. Read and copy one block at a time, capping each copy to the bytes left in the block so it cannot exceed sizeof(data), and account for an unaligned starting offset. Fixes: 096030e7f449 ("nvmem: sprd: Add Spreadtrum SoCs eFuse support") Cc: stable@vger.kernel.org Signed-off-by: Sanman Pradhan Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/sprd-efuse.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/sprd-efuse.c b/drivers/nvmem/sprd-efuse.c index 5395eb460d34..c4d242326808 100644 --- a/drivers/nvmem/sprd-efuse.c +++ b/drivers/nvmem/sprd-efuse.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -297,6 +298,7 @@ static int sprd_efuse_read(void *context, u32 offset, void *val, size_t bytes) bool blk_double = efuse->data->blk_double; u32 index = offset / SPRD_EFUSE_BLOCK_WIDTH + efuse->data->blk_offset; u32 blk_offset = (offset % SPRD_EFUSE_BLOCK_WIDTH) * BITS_PER_BYTE; + u8 *buf = val; u32 data; int ret; @@ -308,10 +310,19 @@ static int sprd_efuse_read(void *context, u32 offset, void *val, size_t bytes) if (ret) goto unlock; - ret = sprd_efuse_raw_read(efuse, index, &data, blk_double); - if (!ret) { + while (bytes) { + size_t avail = SPRD_EFUSE_BLOCK_WIDTH - blk_offset / BITS_PER_BYTE; + size_t count = min(bytes, avail); + + ret = sprd_efuse_raw_read(efuse, index++, &data, blk_double); + if (ret) + break; + data >>= blk_offset; - memcpy(val, &data, bytes); + memcpy(buf, &data, count); + buf += count; + bytes -= count; + blk_offset = 0; } clk_disable_unprepare(efuse->clk); -- 2.53.0