[PATCH v3 0/2] nvmem: validate access ranges and fix SPRD reads

From: Pradhan, Sanman

Date: Mon Nov 30 2026 - 11:25:42 EST


From: Sanman Pradhan <psanman@xxxxxxxxxxx>

Patch 1 adds a device-size bounds check to the nvmem core, so an
out-of-range request is rejected before it reaches a provider. v1
open-coded this check in the sprd driver; since v2 it is in the core
instead.

Patch 2 fixes sprd_efuse_read(), which reads one four-byte block but
copies the caller's full length from that stack variable, and never
advances past the first block. Its provider-side range check is removed
in favour of patch 1, so patch 2 should be applied after patch 1:
without the core check an out-of-range in-kernel request would let the
new block loop read past the eFuse region.

Both patches are compile-tested only. No Spreadtrum eFuse hardware was
available for runtime testing. The bounds check intentionally permits a
zero-length access at offset == size and rejects all ranges extending
past the device size.

Changes in v3:
- Rebase onto nvmem-next (for-next), as requested by Srinivas.
- Patch 1: nvmem-next reworked the access paths, and cell reads and
writes no longer go through nvmem_reg_read()/nvmem_reg_write(). Move
the check into nvmem_access_locked(), which every device and cell
access now passes through, so the coverage is the same as in v2.
- Patch 2: no change.

Changes in v2:
- Add the range check in the nvmem core instead of the sprd provider
(new patch 1), as suggested by Srinivas.
- Patch 2: drop the provider-side range check, qualify the sysfs note
with CONFIG_NVMEM_SYSFS, and use min() instead of min_t().

Link to v2: https://lore.kernel.org/all/20260921165055.421933-1-sanman.pradhan@xxxxxxx/
Link to v1: https://lore.kernel.org/all/20260904003815.462352-1-sanman.pradhan@xxxxxxx/

Sanman Pradhan (2):
nvmem: core: reject reads and writes beyond the device size
nvmem: sprd: fix out-of-bounds read in sprd_efuse_read()

drivers/nvmem/core.c | 3 +++
drivers/nvmem/sprd-efuse.c | 17 ++++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)


base-commit: 9c938f8aa8244009ced6a8618bac8583ad49b38a
--
2.34.1