mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Freeman Liu <freeman.liu@unisoc.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Orson Zhai <orsonzhai@gmail.com>,
	Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog()
Date: Thu,  3 Dec 2026 08:26:04 +0000	[thread overview]
Message-ID: <ad902fb6d65b617d55dd5819275b60e05be82ee9.1796286324.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796286324.git.lee@kernel.org>

sprd_efuse_write() allows partial-block writes smaller than
SPRD_EFUSE_BLOCK_WIDTH (4 bytes) because the device registers with
word_size and stride set to 1.  Passing val directly to
sprd_efuse_raw_prog() as u32 * and dereferencing *data performs a 4-byte
out-of-bounds heap read past short buffers and burns slab contents into
hardware eFuses, while writes larger than 4 bytes are silently
truncated.

Validate that bytes is in [1, SPRD_EFUSE_BLOCK_WIDTH], copy bytes into a
zero-initialised __le32 local variable, and pass the converted u32 value
to sprd_efuse_raw_prog() by value.

Fixes: 096030e7f449 ("nvmem: sprd: Add Spreadtrum SoCs eFuse support")
Closes: https://sashiko.dev/#/bug/linux-7e0bb49f-4129-4a8d-a023-a0dbab6773f6
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Freeman Liu <freeman.liu@unisoc.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/sprd-efuse.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/sprd-efuse.c b/drivers/nvmem/sprd-efuse.c
index 82995f8bce47..6b764c510d94 100644
--- a/drivers/nvmem/sprd-efuse.c
+++ b/drivers/nvmem/sprd-efuse.c
@@ -193,7 +193,7 @@ static void sprd_efuse_set_prog_en(struct sprd_efuse *efuse, bool en)
 }
 
 static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub,
-			       bool lock, u32 *data)
+			       bool lock, u32 data)
 {
 	u32 status;
 	int ret = 0;
@@ -221,7 +221,7 @@ static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub,
 	if (lock)
 		sprd_efuse_set_auto_check(efuse, true);
 
-	writel(*data, efuse->base + SPRD_EFUSE_MEM(blk));
+	writel(data, efuse->base + SPRD_EFUSE_MEM(blk));
 
 	/* Disable auto-check and data double after programming */
 	if (lock)
@@ -336,9 +336,15 @@ static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
 {
 	struct sprd_efuse *efuse = context;
 	bool blk_double = efuse->data->blk_double;
+	__le32 data = 0;
 	bool lock;
 	int ret;
 
+	if (!bytes || bytes > SPRD_EFUSE_BLOCK_WIDTH)
+		return -EINVAL;
+
+	memcpy(&data, val, bytes);
+
 	ret = sprd_efuse_lock(efuse);
 	if (ret)
 		return ret;
@@ -360,7 +366,8 @@ static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
 	else
 		lock = true;
 
-	ret = sprd_efuse_raw_prog(efuse, offset, blk_double, lock, val);
+	ret = sprd_efuse_raw_prog(efuse, offset, blk_double, lock,
+				  le32_to_cpu(data));
 
 	clk_disable_unprepare(efuse->clk);
 
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-03  8:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  8:26 [PATCH 00/10] nvmem: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03  8:26 ` [PATCH 01/10] nvmem: meson-efuse: Reject negative or zero SMC size in meson_efuse_probe() Lee Jones
2026-12-03  8:26 ` [PATCH 02/10] nvmem: core: Prevent integer underflow in nvmem_cell_attr_read() Lee Jones
2026-12-03  8:26 ` Lee Jones [this message]
2026-12-03  8:26 ` [PATCH 04/10] nvmem: core: Handle multi-byte bit offsets in nvmem_cell_prepare_write_buffer() Lee Jones
2026-12-03  8:26 ` [PATCH 05/10] nvmem: core: Serialise writes when toggling the write-protect GPIO Lee Jones
2026-12-03  8:26 ` [PATCH 06/10] nvmem: eeprom_93xx46: Reject unaligned writes on 16-bit devices Lee Jones
2026-12-03  8:26 ` [PATCH 07/10] nvmem: eeprom_93xx46: Hold device lock across erase/write enable sequences Lee Jones
2026-12-03  8:26 ` [PATCH 08/10] nvmem: eeprom_93xx46: Use DMA-safe command buffer for SPI transfers Lee Jones
2026-12-03  8:26 ` [PATCH 09/10] nvmem: meson-efuse: Detect short reads and writes from Secure Monitor Lee Jones
2026-12-03  8:26 ` [PATCH 10/10] nvmem: stm32: Avoid OP-TEE session leak on unaligned writes Lee Jones
2026-12-03 10:16   ` Patrick DELAUNAY

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=ad902fb6d65b617d55dd5819275b60e05be82ee9.1796286324.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=freeman.liu@unisoc.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=srini@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=zhang.lyra@gmail.com \
    /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

all inboxes | Powered by JetHome®