Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 01/10] nvmem: meson-efuse: Reject negative or zero SMC size in meson_efuse_probe()
       [not found] <cover.1796286324.git.lee@kernel.org>
@ 2026-12-03  8:26 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 02/10] nvmem: core: Prevent integer underflow in nvmem_cell_attr_read() Lee Jones
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Carlo Caione, Jerome Brunet, Kevin Hilman,
	linux-amlogic, linux-arm-kernel, Martin Blumenstingl,
	Neil Armstrong, Srinivas Kandagatla

meson_sm_call() writes the signed Secure Monitor return value into its
s32 output pointer and returns 0 whenever the command ID is valid.
meson_efuse_probe() passes an unsigned int pointer to meson_sm_call()
and only checks for a negative return value from meson_sm_call() itself.
If firmware returns a negative SMC error code (such as
SMCCC_RET_NOT_SUPPORTED), size wraps to a large unsigned value and is
assigned to econfig->size.

Change size to s32 and reject negative or zero values from
SM_EFUSE_USER_MAX with -EINVAL.

Fixes: ad855eae6caf ("nvmem: amlogic: Add Amlogic Meson EFUSE driver")
Closes: https://sashiko.dev/#/bug/linux-0667e60b-53c5-4a5a-b9b4-bb6f8d7eb500
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Carlo Caione <carlo@endlessm.com>
Cc: Jerome Brunet <jbrunet@baylibre.com>
Cc: Kevin Hilman <khilman@baylibre.com>
Cc: linux-amlogic@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/meson-efuse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index d7f9ac99a212..e8f384098be5 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -51,7 +51,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
 	struct nvmem_device *nvmem;
 	struct nvmem_config *econfig;
 	struct clk *clk;
-	unsigned int size;
+	s32 size;
 	struct device_node *sm_np __free(device_node) =
 			of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
 
@@ -68,7 +68,8 @@ static int meson_efuse_probe(struct platform_device *pdev)
 	if (IS_ERR(clk))
 		return dev_err_probe(dev, PTR_ERR(clk), "failed to get efuse gate");
 
-	if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) {
+	if (meson_sm_call(fw, SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0 ||
+	    size <= 0) {
 		dev_err(dev, "failed to get max user");
 		return -EINVAL;
 	}
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 02/10] nvmem: core: Prevent integer underflow in nvmem_cell_attr_read()
       [not found] <cover.1796286324.git.lee@kernel.org>
  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 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog() Lee Jones
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Greg Kroah-Hartman, Maxime Ripard,
	Miquel Raynal, Srinivas Kandagatla

sysfs_kf_bin_read() skips its pos >= size check when the binary
attribute has i_size == 0.  For a zero-length NVMEM cell, a userspace
read with a non-zero offset therefore reaches nvmem_cell_attr_read(),
where cell_sz - pos underflows as unsigned int, causing memcpy() to
dereference ZERO_SIZE_PTR + pos.

Check whether pos is negative or at least cell_sz before computing
read_len and copying into buf, returning 0 bytes when out of range.

Fixes: 0331c611949f ("nvmem: core: Expose cells through sysfs")
Closes: https://sashiko.dev/#/bug/linux-d9f2bf28-bfff-430b-88b3-f5d6e0263229
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index cf263633a4a2..83ed6d4e3c5f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -384,8 +384,12 @@ static ssize_t nvmem_cell_attr_read(struct file *filp, struct kobject *kobj,
 		goto destroy_cell;
 	}
 
-	read_len = min_t(unsigned int, cell_sz - pos, count);
-	memcpy(buf, content + pos, read_len);
+	if (pos < 0 || pos >= cell_sz) {
+		read_len = 0;
+	} else {
+		read_len = min_t(size_t, cell_sz - pos, count);
+		memcpy(buf, content + pos, read_len);
+	}
 	kfree(content);
 
 destroy_cell:
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog()
       [not found] <cover.1796286324.git.lee@kernel.org>
  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
  2026-12-04  1:27   ` Baolin Wang
  2026-12-03  8:26 ` [PATCH 04/10] nvmem: core: Handle multi-byte bit offsets in nvmem_cell_prepare_write_buffer() Lee Jones
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Baolin Wang, Chunyan Zhang, Freeman Liu,
	Greg Kroah-Hartman, Orson Zhai, Srinivas Kandagatla

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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 04/10] nvmem: core: Handle multi-byte bit offsets in nvmem_cell_prepare_write_buffer()
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (2 preceding siblings ...)
  2026-12-03  8:26 ` [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog() Lee Jones
@ 2026-12-03  8:26 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 05/10] nvmem: core: Serialise writes when toggling the write-protect GPIO Lee Jones
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Dmitry Baryshkov, Greg Kroah-Hartman,
	Maxime Ripard, Srinivas Kandagatla

nvmem_cell_prepare_write_buffer() assumes cell->bit_offset is less than
BITS_PER_BYTE.  When cell->bit_offset is 8 or greater, shifting by
bit_offset and passing negative shift counts to GENMASK() or right
shifts triggers undefined behaviour, leaves leading bytes overwritten
with zero, and places the payload at byte 0 instead of
bit_offset / BITS_PER_BYTE.  In addition, the carry shift used
BITS_PER_BYTE - 1 - bit_offset instead of BITS_PER_BYTE - bit_offset,
and the trailing-byte pointer p was left at byte 0 when bit_offset was
zero.

Split cell->bit_offset into bytes_offset and bit_offset modulo
BITS_PER_BYTE, reject bytes_offset >= cell->bytes, preserve existing
leading bytes via an aligned read from cell->offset, bound the payload
copy to cell->bytes - bytes_offset, fix the carry shift and trailing
byte pointer, and mask the trailing byte before preserving its upper
bits.

Fixes: 7a06ef751077 ("nvmem: core: fix bit offsets of more than one byte")
Closes: https://sashiko.dev/#/bug/linux-aad5e2e4-4b14-43ee-83a5-ed1a2760358e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Dmitry Baryshkov <lumag@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/core.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 83ed6d4e3c5f..e7c687cb6ce6 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1765,33 +1765,46 @@ static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell_entry *cell,
 					     u8 *_buf, int len)
 {
 	struct nvmem_device *nvmem = cell->nvmem;
-	int i, rc, nbits, bit_offset = cell->bit_offset;
-	u8 v, *p, *buf, *b, pbyte, pbits;
+	int i, rc, nbits, bytes_offset, bit_offset;
+	u8 v = 0, *p, *buf, *b, pbyte, pbits;
+	size_t copy_len, lead_bytes;
 
 	nbits = cell->nbits;
+	bytes_offset = cell->bit_offset / BITS_PER_BYTE;
+	bit_offset = cell->bit_offset % BITS_PER_BYTE;
+	if (bytes_offset >= cell->bytes)
+		return ERR_PTR(-EINVAL);
+
 	buf = kzalloc(cell->bytes, GFP_KERNEL);
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
 
-	memcpy(buf, _buf, len);
-	p = b = buf;
+	lead_bytes = bytes_offset + (bit_offset ? 1 : 0);
+	if (lead_bytes) {
+		rc = nvmem_access_locked(nvmem, ops, cell->offset, buf,
+					 lead_bytes, false);
+		if (rc)
+			goto err;
+		v = buf[bytes_offset];
+	}
+
+	copy_len = min_t(size_t, len, cell->bytes - bytes_offset);
+	memcpy(buf + bytes_offset, _buf, copy_len);
+	b = buf + bytes_offset;
+	p = buf + cell->bytes - 1;
 
 	if (bit_offset) {
 		pbyte = *b;
 		*b <<= bit_offset;
 
 		/* setup the first byte with lsb bits from nvmem */
-		rc = nvmem_access_locked(nvmem, ops, cell->offset, &v, 1, false);
-		if (rc)
-			goto err;
 		*b++ |= GENMASK(bit_offset - 1, 0) & v;
 
 		/* setup rest of the byte if any */
-		for (i = 1; i < cell->bytes; i++) {
+		for (i = bytes_offset + 1; i < cell->bytes; i++) {
 			/* Get last byte bits and shift them towards lsb */
-			pbits = pbyte >> (BITS_PER_BYTE - 1 - bit_offset);
+			pbits = pbyte >> (BITS_PER_BYTE - bit_offset);
 			pbyte = *b;
-			p = b;
 			*b <<= bit_offset;
 			*b++ |= pbits;
 		}
@@ -1804,8 +1817,8 @@ static void *nvmem_cell_prepare_write_buffer(struct nvmem_cell_entry *cell,
 					 &v, 1, false);
 		if (rc)
 			goto err;
+		*p &= GENMASK(((nbits + bit_offset) % BITS_PER_BYTE) - 1, 0);
 		*p |= GENMASK(7, (nbits + bit_offset) % BITS_PER_BYTE) & v;
-
 	}
 
 	return buf;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 05/10] nvmem: core: Serialise writes when toggling the write-protect GPIO
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (3 preceding siblings ...)
  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 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 06/10] nvmem: eeprom_93xx46: Reject unaligned writes on 16-bit devices Lee Jones
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Bartosz Golaszewski, Greg Kroah-Hartman,
	Khouloud Touil, Linus Walleij, Maxime Ripard, Srinivas Kandagatla

nvmem_access_chunk() deasserts nvmem->wp_gpio, calls ops->reg_write(),
and re-asserts nvmem->wp_gpio while callers hold only the shared SRCU
read lock.  Concurrent writers can therefore overlap, allowing one
writer to re-assert write protection while another writer is still
executing ops->reg_write().

Add a per-device wp_lock mutex to struct nvmem_device and hold it
across the WP GPIO deassert, ops->reg_write(), and WP GPIO re-assert
sequence whenever nvmem->wp_gpio is present.

Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
Closes: https://sashiko.dev/#/bug/linux-d7d845df-786a-40cf-b43c-f4ce2e295c82
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Khouloud Touil <ktouil@baylibre.com>
Cc: Linus Walleij <linusw@kernel.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/core.c      | 7 +++++++
 drivers/nvmem/internals.h | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index e7c687cb6ce6..2ba1ab037907 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -70,6 +70,11 @@ static int nvmem_access_chunk(struct nvmem_device *nvmem,
 	if (!ops->reg_write)
 		return -EOPNOTSUPP;
 
+	if (!nvmem->wp_gpio)
+		return ops->reg_write(nvmem->priv, offset, val, bytes);
+
+	guard(mutex)(&nvmem->wp_lock);
+
 	ret = gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
 	if (ret)
 		return ret;
@@ -574,6 +579,7 @@ static void nvmem_release(struct device *dev)
 	nvmem_device_remove_all_cells(nvmem);
 	ida_free(&nvmem_ida, nvmem->id);
 	of_node_put(nvmem->dev.of_node);
+	mutex_destroy(&nvmem->wp_lock);
 	cleanup_srcu_struct(&nvmem->srcu);
 	kfree(nvmem);
 }
@@ -983,6 +989,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 		return ERR_PTR(rval);
 	}
 
+	mutex_init(&nvmem->wp_lock);
 	rcu_assign_pointer(nvmem->ops, ops);
 
 	device_initialize(&nvmem->dev);
diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h
index bc7a99f5aefb..3d59ac799170 100644
--- a/drivers/nvmem/internals.h
+++ b/drivers/nvmem/internals.h
@@ -4,6 +4,7 @@
 #define _LINUX_NVMEM_INTERNALS_H
 
 #include <linux/device.h>
+#include <linux/mutex.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/nvmem-provider.h>
 #include <linux/srcu.h>
@@ -34,6 +35,7 @@ struct nvmem_device {
 	const struct nvmem_keepout *keepout;
 	unsigned int		nkeepout;
 	struct gpio_desc	*wp_gpio;
+	struct mutex		wp_lock;	/* serialises WP GPIO writes */
 	struct nvmem_layout	*layout;
 	struct nvmem_operations __rcu *ops;
 	void *priv;
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 06/10] nvmem: eeprom_93xx46: Reject unaligned writes on 16-bit devices
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (4 preceding siblings ...)
  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 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 07/10] nvmem: eeprom_93xx46: Hold device lock across erase/write enable sequences Lee Jones
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Anatolij Gustschin, Greg Kroah-Hartman,
	Srinivas Kandagatla

eeprom_93xx46_probe() hardcodes nvmem_config.word_size to 1 even for
16-bit (EE_ADDR16) devices, while eeprom_93xx46_write() silently masks
off the low bit of count and returns 0 on success.  A 1-byte write
therefore silently writes nothing and reports success, and an odd
offset is shifted down by eeprom_93xx46_write_word(), overwriting the
adjacent byte.

Set nvmem_config.word_size to 2 for EE_ADDR16 devices and reject odd
offsets or byte counts in eeprom_93xx46_write() with -EINVAL.

Fixes: a8ab316ab125 ("nvmem: 93xx46: remove nvmem regmap dependency")
Closes: https://sashiko.dev/#/bug/linux-2aded405-6835-472f-bb94-d76d40cc2d96
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Anatolij Gustschin <agust@denx.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/eeprom_93xx46.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index f9c3ab52c2f9..6b159d5fa08e 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -282,10 +282,11 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
 	if (unlikely(!count))
 		return count;
 
-	/* only write even number of bytes on 16-bit devices */
+	/* only write even offsets and counts on 16-bit devices */
 	if (edev->pdata->flags & EE_ADDR16) {
+		if ((off & 1) || (count & 1))
+			return -EINVAL;
 		step = 2;
-		count &= ~1;
 	}
 
 	/* erase/write enable */
@@ -513,7 +514,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
 	edev->nvmem_config.reg_write = eeprom_93xx46_write;
 	edev->nvmem_config.priv = edev;
 	edev->nvmem_config.stride = 4;
-	edev->nvmem_config.word_size = 1;
+	edev->nvmem_config.word_size = (pd->flags & EE_ADDR16) ? 2 : 1;
 	edev->nvmem_config.size = edev->size;
 
 	edev->nvmem = devm_nvmem_register(&spi->dev, &edev->nvmem_config);
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 07/10] nvmem: eeprom_93xx46: Hold device lock across erase/write enable sequences
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (5 preceding siblings ...)
  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 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 08/10] nvmem: eeprom_93xx46: Use DMA-safe command buffer for SPI transfers Lee Jones
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Anatolij Gustschin, Andrew Morton,
	Randy Dunlap, Srinivas Kandagatla

eeprom_93xx46_ew() and eeprom_93xx46_eral() each acquire and release
edev->lock internally, leaving edev->lock unheld between enabling
erase/write mode, issuing the write or erase commands, and disabling
erase/write mode again.  A concurrent writer or eraser can therefore
send EWDS before the first caller writes, causing the EEPROM to ignore
writes silently while returning 0.  In addition, erase_store() returned
early on an erase error without sending EWDS.

Move locking to the callers (eeprom_93xx46_write() and erase_store())
so edev->lock is held across the entire EWEN, write/erase, and EWDS
sequence, assert the lock in eeprom_93xx46_ew() and
eeprom_93xx46_eral(), and always send EWDS after eeprom_93xx46_eral()
in erase_store().

Fixes: 06b4501e88ad ("misc/eeprom: add driver for microwire 93xx46 EEPROMs")
Closes: https://sashiko.dev/#/bug/linux-f81c5c58-cfcf-4b32-95d1-2f722f5dd347
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Anatolij Gustschin <agust@denx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/eeprom_93xx46.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index 6b159d5fa08e..35966552ddbd 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -7,10 +7,12 @@
 
 #include <linux/array_size.h>
 #include <linux/bits.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/gpio/consumer.h>
 #include <linux/kstrtox.h>
+#include <linux/lockdep.h>
 #include <linux/log2.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -207,7 +209,7 @@ static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on)
 
 	spi_message_init_with_transfers(&m, &t, 1);
 
-	mutex_lock(&edev->lock);
+	lockdep_assert_held(&edev->lock);
 
 	gpiod_set_value_cansleep(edev->pdata->select, 1);
 
@@ -220,7 +222,6 @@ static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on)
 
 	gpiod_set_value_cansleep(edev->pdata->select, 0);
 
-	mutex_unlock(&edev->lock);
 	return ret;
 }
 
@@ -289,13 +290,13 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
 		step = 2;
 	}
 
+	guard(mutex)(&edev->lock);
+
 	/* erase/write enable */
 	ret = eeprom_93xx46_ew(edev, 1);
 	if (ret)
 		return ret;
 
-	mutex_lock(&edev->lock);
-
 	gpiod_set_value_cansleep(edev->pdata->select, 1);
 
 	for (i = 0; i < count; i += step) {
@@ -308,8 +309,6 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
 
 	gpiod_set_value_cansleep(edev->pdata->select, 0);
 
-	mutex_unlock(&edev->lock);
-
 	/* erase/write disable */
 	eeprom_93xx46_ew(edev, 0);
 	return ret;
@@ -341,7 +340,7 @@ static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev)
 
 	spi_message_init_with_transfers(&m, &t, 1);
 
-	mutex_lock(&edev->lock);
+	lockdep_assert_held(&edev->lock);
 
 	gpiod_set_value_cansleep(edev->pdata->select, 1);
 
@@ -353,7 +352,6 @@ static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev)
 
 	gpiod_set_value_cansleep(edev->pdata->select, 0);
 
-	mutex_unlock(&edev->lock);
 	return ret;
 }
 
@@ -369,15 +367,19 @@ static ssize_t erase_store(struct device *dev, struct device_attribute *attr,
 		return ret;
 
 	if (erase) {
+		int ewds_ret;
+
+		guard(mutex)(&edev->lock);
+
 		ret = eeprom_93xx46_ew(edev, 1);
 		if (ret)
 			return ret;
 		ret = eeprom_93xx46_eral(edev);
+		ewds_ret = eeprom_93xx46_ew(edev, 0);
 		if (ret)
 			return ret;
-		ret = eeprom_93xx46_ew(edev, 0);
-		if (ret)
-			return ret;
+		if (ewds_ret)
+			return ewds_ret;
 	}
 	return count;
 }
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 08/10] nvmem: eeprom_93xx46: Use DMA-safe command buffer for SPI transfers
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (6 preceding siblings ...)
  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 ` 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
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Anatolij Gustschin, Andrew Morton,
	Randy Dunlap, Srinivas Kandagatla

eeprom_93xx46_read(), eeprom_93xx46_ew(), eeprom_93xx46_write_word(),
and eeprom_93xx46_eral() all pass a stack-allocated u16 cmd_addr as
tx_buf to spi_sync().  Stack memory is not DMA-safe under
CONFIG_VMAP_STACK or DMA-capable SPI controllers.

Move cmd_addr into the heap-allocated struct eeprom_93xx46_dev with
cacheline alignment, serialised under edev->lock across all four SPI
operations.

Fixes: 06b4501e88ad ("misc/eeprom: add driver for microwire 93xx46 EEPROMs")
Closes: https://sashiko.dev/#/bug/linux-d67d0811-56d4-4dbc-a558-75418ab48ad0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Anatolij Gustschin <agust@denx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/eeprom_93xx46.c | 58 ++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index 35966552ddbd..e191ac2e3745 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -7,6 +7,7 @@
 
 #include <linux/array_size.h>
 #include <linux/bits.h>
+#include <linux/cache.h>
 #include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -87,6 +88,7 @@ struct eeprom_93xx46_dev {
 	struct nvmem_device *nvmem;
 	int addrlen;
 	int size;
+	u16 cmd_addr ____cacheline_aligned;
 };
 
 static inline bool has_quirk_single_word_read(struct eeprom_93xx46_dev *edev)
@@ -129,28 +131,29 @@ static int eeprom_93xx46_read(void *priv, unsigned int off,
 	while (count) {
 		struct spi_message m;
 		struct spi_transfer t[2] = {};
-		u16 cmd_addr = OP_READ << edev->addrlen;
 		size_t nbytes = count;
 
+		edev->cmd_addr = OP_READ << edev->addrlen;
+
 		if (edev->pdata->flags & EE_ADDR8) {
-			cmd_addr |= off;
+			edev->cmd_addr |= off;
 			if (has_quirk_single_word_read(edev))
 				nbytes = 1;
 		} else {
-			cmd_addr |= (off >> 1);
+			edev->cmd_addr |= (off >> 1);
 			if (has_quirk_single_word_read(edev))
 				nbytes = 2;
 		}
 
 		dev_dbg(&edev->spi->dev, "read cmd 0x%x, %d Hz\n",
-			cmd_addr, edev->spi->max_speed_hz);
+			edev->cmd_addr, edev->spi->max_speed_hz);
 
 		if (has_quirk_extra_read_cycle(edev)) {
-			cmd_addr <<= 1;
+			edev->cmd_addr <<= 1;
 			bits += 1;
 		}
 
-		t[0].tx_buf = (char *)&cmd_addr;
+		t[0].tx_buf = &edev->cmd_addr;
 		t[0].len = 2;
 		t[0].bits_per_word = bits;
 
@@ -187,30 +190,29 @@ static int eeprom_93xx46_ew(struct eeprom_93xx46_dev *edev, int is_on)
 	struct spi_message m;
 	struct spi_transfer t = {};
 	int bits, ret;
-	u16 cmd_addr;
+
+	lockdep_assert_held(&edev->lock);
 
 	/* The opcode in front of the address is three bits. */
 	bits = edev->addrlen + 3;
 
-	cmd_addr = OP_START << edev->addrlen;
-	cmd_addr |= (is_on ? ADDR_EWEN : ADDR_EWDS) << (edev->addrlen - 6);
+	edev->cmd_addr = OP_START << edev->addrlen;
+	edev->cmd_addr |= (is_on ? ADDR_EWEN : ADDR_EWDS) << (edev->addrlen - 6);
 
 	if (has_quirk_instruction_length(edev)) {
-		cmd_addr <<= 2;
+		edev->cmd_addr <<= 2;
 		bits += 2;
 	}
 
 	dev_dbg(&edev->spi->dev, "ew %s cmd 0x%04x, %d bits\n",
-		str_enable_disable(is_on), cmd_addr, bits);
+		str_enable_disable(is_on), edev->cmd_addr, bits);
 
-	t.tx_buf = &cmd_addr;
+	t.tx_buf = &edev->cmd_addr;
 	t.len = 2;
 	t.bits_per_word = bits;
 
 	spi_message_init_with_transfers(&m, &t, 1);
 
-	lockdep_assert_held(&edev->lock);
-
 	gpiod_set_value_cansleep(edev->pdata->select, 1);
 
 	ret = spi_sync(edev->spi, &m);
@@ -232,7 +234,8 @@ eeprom_93xx46_write_word(struct eeprom_93xx46_dev *edev,
 	struct spi_message m;
 	struct spi_transfer t[2] = {};
 	int bits, data_len, ret;
-	u16 cmd_addr;
+
+	lockdep_assert_held(&edev->lock);
 
 	if (unlikely(off >= edev->size))
 		return -EINVAL;
@@ -240,19 +243,19 @@ eeprom_93xx46_write_word(struct eeprom_93xx46_dev *edev,
 	/* The opcode in front of the address is three bits. */
 	bits = edev->addrlen + 3;
 
-	cmd_addr = OP_WRITE << edev->addrlen;
+	edev->cmd_addr = OP_WRITE << edev->addrlen;
 
 	if (edev->pdata->flags & EE_ADDR8) {
-		cmd_addr |= off;
+		edev->cmd_addr |= off;
 		data_len = 1;
 	} else {
-		cmd_addr |= (off >> 1);
+		edev->cmd_addr |= (off >> 1);
 		data_len = 2;
 	}
 
-	dev_dbg(&edev->spi->dev, "write cmd 0x%x\n", cmd_addr);
+	dev_dbg(&edev->spi->dev, "write cmd 0x%x\n", edev->cmd_addr);
 
-	t[0].tx_buf = (char *)&cmd_addr;
+	t[0].tx_buf = &edev->cmd_addr;
 	t[0].len = 2;
 	t[0].bits_per_word = bits;
 
@@ -319,29 +322,28 @@ static int eeprom_93xx46_eral(struct eeprom_93xx46_dev *edev)
 	struct spi_message m;
 	struct spi_transfer t = {};
 	int bits, ret;
-	u16 cmd_addr;
+
+	lockdep_assert_held(&edev->lock);
 
 	/* The opcode in front of the address is three bits. */
 	bits = edev->addrlen + 3;
 
-	cmd_addr = OP_START << edev->addrlen;
-	cmd_addr |= ADDR_ERAL << (edev->addrlen - 6);
+	edev->cmd_addr = OP_START << edev->addrlen;
+	edev->cmd_addr |= ADDR_ERAL << (edev->addrlen - 6);
 
 	if (has_quirk_instruction_length(edev)) {
-		cmd_addr <<= 2;
+		edev->cmd_addr <<= 2;
 		bits += 2;
 	}
 
-	dev_dbg(&edev->spi->dev, "eral cmd 0x%04x, %d bits\n", cmd_addr, bits);
+	dev_dbg(&edev->spi->dev, "eral cmd 0x%04x, %d bits\n", edev->cmd_addr, bits);
 
-	t.tx_buf = &cmd_addr;
+	t.tx_buf = &edev->cmd_addr;
 	t.len = 2;
 	t.bits_per_word = bits;
 
 	spi_message_init_with_transfers(&m, &t, 1);
 
-	lockdep_assert_held(&edev->lock);
-
 	gpiod_set_value_cansleep(edev->pdata->select, 1);
 
 	ret = spi_sync(edev->spi, &m);
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 09/10] nvmem: meson-efuse: Detect short reads and writes from Secure Monitor
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (7 preceding siblings ...)
  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 ` Lee Jones
  2026-12-03  8:26 ` [PATCH 10/10] nvmem: stm32: Avoid OP-TEE session leak on unaligned writes Lee Jones
  9 siblings, 0 replies; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Carlo Caione, Dan Carpenter,
	Greg Kroah-Hartman, Jerome Brunet, Joy Chakraborty, Kevin Hilman,
	linux-amlogic, linux-arm-kernel, Martin Blumenstingl,
	Neil Armstrong, Srinivas Kandagatla

meson_efuse_read() and meson_efuse_write() treat any non-negative byte
count returned by meson_sm_call_read() or meson_sm_call_write() as
success and return 0, silently hiding partial reads or writes.

Return -EIO when meson_sm_call_write() reports a byte count other than
bytes, or when meson_sm_call_read() returns a non-zero byte count that
does not match bytes (preserving the 0 return convention documented by
meson_sm_call_read()).

Fixes: 7a0a6d0a7c80 ("nvmem: meson-efuse: Fix return value of nvmem callbacks")
Closes: https://sashiko.dev/#/bug/linux-990a1e10-e629-4b29-956e-2b2d39ac8f4a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Carlo Caione <carlo@endlessm.com>
Cc: Dan Carpenter <error27@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jerome Brunet <jbrunet@baylibre.com>
Cc: Joy Chakraborty <joychakr@google.com>
Cc: Kevin Hilman <khilman@baylibre.com>
Cc: linux-amlogic@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/meson-efuse.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index e8f384098be5..383ee9281693 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -22,8 +22,12 @@ static int meson_efuse_read(void *context, unsigned int offset,
 
 	ret = meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
 				 bytes, 0, 0, 0);
+	if (ret < 0)
+		return ret;
+	if (ret && ret != bytes)
+		return -EIO;
 
-	return ret < 0 ? ret : 0;
+	return 0;
 }
 
 static int meson_efuse_write(void *context, unsigned int offset,
@@ -34,8 +38,12 @@ static int meson_efuse_write(void *context, unsigned int offset,
 
 	ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
 				  bytes, 0, 0, 0);
+	if (ret < 0)
+		return ret;
+	if (ret != bytes)
+		return -EIO;
 
-	return ret < 0 ? ret : 0;
+	return 0;
 }
 
 static const struct of_device_id meson_efuse_match[] = {
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 10/10] nvmem: stm32: Avoid OP-TEE session leak on unaligned writes
       [not found] <cover.1796286324.git.lee@kernel.org>
                   ` (8 preceding siblings ...)
  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 ` Lee Jones
  2026-12-03 10:16   ` Patrick DELAUNAY
  9 siblings, 1 reply; 12+ messages in thread
From: Lee Jones @ 2026-12-03  8:26 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, stable, Alexandre Torgue, Etienne Carriere,
	Greg Kroah-Hartman, linux-arm-kernel, linux-stm32,
	Maxime Coquelin, Patrick Delaunay, Srinivas Kandagatla

stm32_bsec_optee_ta_write() opens a TEE session via
stm32_bsec_ta_open_session() before validating that offset and bytes
are 4-byte aligned.  Because the parent NVMEM device registers with
word_size and stride set to 1, an unaligned write reaches this function
and returns -EINVAL directly without closing the opened TEE session.

Validate offset and bytes alignment before opening the OP-TEE session.

Fixes: 6a0bc3522e74 ("nvmem: stm32: add OP-TEE support for STM32MP13x")
Closes: https://sashiko.dev/#/bug/linux-b95e4408-6d2d-4b55-a422-f96cba011647
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Etienne Carriere <etienne.carriere@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/stm32-bsec-optee-ta.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/stm32-bsec-optee-ta.c b/drivers/nvmem/stm32-bsec-optee-ta.c
index f89ce791dd12..7ffeaa4258a1 100644
--- a/drivers/nvmem/stm32-bsec-optee-ta.c
+++ b/drivers/nvmem/stm32-bsec-optee-ta.c
@@ -211,14 +211,14 @@ int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
 	int ret;
 	u32 session_id;
 
-	ret = stm32_bsec_ta_open_session(ctx, &session_id);
-	if (ret)
-		return ret;
-
 	/* Allow only writing complete 32-bits aligned words */
 	if ((bytes % 4) || (offset % 4))
 		return -EINVAL;
 
+	ret = stm32_bsec_ta_open_session(ctx, &session_id);
+	if (ret)
+		return ret;
+
 	memset(&arg, 0, sizeof(arg));
 	memset(&param, 0, sizeof(param));
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 10/10] nvmem: stm32: Avoid OP-TEE session leak on unaligned writes
  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
  0 siblings, 0 replies; 12+ messages in thread
From: Patrick DELAUNAY @ 2026-12-03 10:16 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-kernel, stable, Alexandre Torgue, Etienne Carriere,
	Greg Kroah-Hartman, linux-arm-kernel, linux-stm32,
	Maxime Coquelin, Srinivas Kandagatla

Hi,

On 12/3/26 09:26, Lee Jones wrote:
> stm32_bsec_optee_ta_write() opens a TEE session via
> stm32_bsec_ta_open_session() before validating that offset and bytes
> are 4-byte aligned.  Because the parent NVMEM device registers with
> word_size and stride set to 1, an unaligned write reaches this function
> and returns -EINVAL directly without closing the opened TEE session.
>
> Validate offset and bytes alignment before opening the OP-TEE session.
>
> Fixes: 6a0bc3522e74 ("nvmem: stm32: add OP-TEE support for STM32MP13x")
> Closes: https://sashiko.dev/#/bug/linux-b95e4408-6d2d-4b55-a422-f96cba011647
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: Etienne Carriere <etienne.carriere@linaro.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-stm32@st-md-mailman.stormreply.com
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Cc: Srinivas Kandagatla <srini@kernel.org>
>
>   drivers/nvmem/stm32-bsec-optee-ta.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/nvmem/stm32-bsec-optee-ta.c b/drivers/nvmem/stm32-bsec-optee-ta.c
> index f89ce791dd12..7ffeaa4258a1 100644
> --- a/drivers/nvmem/stm32-bsec-optee-ta.c
> +++ b/drivers/nvmem/stm32-bsec-optee-ta.c
> @@ -211,14 +211,14 @@ int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
>   	int ret;
>   	u32 session_id;
>   
> -	ret = stm32_bsec_ta_open_session(ctx, &session_id);
> -	if (ret)
> -		return ret;
> -
>   	/* Allow only writing complete 32-bits aligned words */
>   	if ((bytes % 4) || (offset % 4))
>   		return -EINVAL;
>   
> +	ret = stm32_bsec_ta_open_session(ctx, &session_id);
> +	if (ret)
> +		return ret;
> +
>   	memset(&arg, 0, sizeof(arg));
>   	memset(&param, 0, sizeof(param));
>   


Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>


Thanks
Patrick


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog()
  2026-12-03  8:26 ` [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog() Lee Jones
@ 2026-12-04  1:27   ` Baolin Wang
  0 siblings, 0 replies; 12+ messages in thread
From: Baolin Wang @ 2026-12-04  1:27 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-kernel, stable, Chunyan Zhang, Freeman Liu,
	Greg Kroah-Hartman, Orson Zhai, Srinivas Kandagatla



On 12/3/26 4:26 PM, Lee Jones wrote:
> 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>
> ---

Thanks. LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-12-04  1:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1796286324.git.lee@kernel.org>
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 ` [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog() Lee Jones
2026-12-04  1:27   ` Baolin Wang
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox