From: srini@kernel.org
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org,
Sanman Pradhan <psanman@juniper.net>,
stable@vger.kernel.org, Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 10/10] nvmem: sprd: fix out-of-bounds read in sprd_efuse_read()
Date: Tue, 1 Dec 2026 23:26:57 +0000 [thread overview]
Message-ID: <20261201232657.537736-11-srini@kernel.org> (raw)
In-Reply-To: <20261201232657.537736-1-srini@kernel.org>
From: Sanman Pradhan <psanman@juniper.net>
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 <psanman@juniper.net>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
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 <linux/delay.h>
#include <linux/hwspinlock.h>
#include <linux/io.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/nvmem-provider.h>
#include <linux/of.h>
@@ -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
prev parent reply other threads:[~2026-12-01 23:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 23:26 [PATCH 00/10] nvmem: fixes for v7.4 srini
2026-12-01 23:26 ` [PATCH 01/10] nvmem: layouts: onie-tlv: check both field header and value bounds srini
2026-12-01 23:26 ` [PATCH 02/10] nvmem: core: validate DT cell bits before allocating the name srini
2026-12-01 23:26 ` [PATCH 03/10] nvmem: retain the provider node until device release srini
2026-12-01 23:26 ` [PATCH 04/10] nvmem: drain keepout and cell post-processing accesses srini
2026-12-01 23:26 ` [PATCH 05/10] nvmem: exclude disconnected providers from callback admission srini
2026-12-01 23:26 ` [PATCH 06/10] nvmem: release write protection when the provider disconnects srini
2026-12-01 23:26 ` [PATCH 07/10] nvmem: airoha-smc-efuses: Fix the SMC function ID for eFuse read srini
2026-12-01 23:26 ` [PATCH 08/10] nvmem: imx-ocotp-scu: assign nvmem_cell_info::raw_len srini
2026-12-01 23:26 ` [PATCH 09/10] nvmem: core: reject reads and writes beyond the device size srini
2026-12-01 23:26 ` srini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201232657.537736-11-srini@kernel.org \
--to=srini@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=psanman@juniper.net \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox