linux-yocto/drivers/nvmem
Jennifer Berringer 31507fc2ad nvmem: core: improve range check for nvmem_cell_write()
When __nvmem_cell_entry_write() is called for an nvmem cell that does
not need bit shifting, it requires that the len parameter exactly
matches the nvmem cell size. However, when the nvmem cell has a nonzero
bit_offset, it was skipping this check.

Accepting values of len larger than the cell size results in
nvmem_cell_prepare_write_buffer() trying to write past the end of a heap
buffer that it allocates. Add a check to avoid that problem and instead
return -EINVAL when len doesn't match the number of bits expected by the
nvmem cell when bit_offset is nonzero.

This check uses cell->nbits in order to allow providing the smaller size
to cells that are shifted into another byte by bit_offset. For example,
a cell with nbits=8 and nonzero bit_offset would have bytes=2 but should
accept a 1-byte write here, although no current callers depend on this.

Fixes: 69aba7948c ("nvmem: Add a simple NVMEM framework for consumers")
Cc: stable@vger.kernel.org
Signed-off-by: Jennifer Berringer <jberring@redhat.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20241230141901.263976-7-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-01-10 16:16:48 +01:00
..
layouts nvmem: layouts: add U-Boot env layout 2024-09-11 16:05:15 +02:00
apple-efuses.c nvmem: add missing MODULE_DESCRIPTION() macros 2024-07-05 09:55:04 +02:00
bcm-ocotp.c
brcm_nvram.c nvmem: Correct some typos in comments 2024-11-05 05:33:47 +01:00
core.c nvmem: core: improve range check for nvmem_cell_write() 2025-01-10 16:16:48 +01:00
imx-iim.c nvmem: imx-iim: Convert comma to semicolon 2024-11-05 05:33:47 +01:00
imx-ocotp-ele.c nvmem: imx-ocotp-ele: set word length to 1 2025-01-10 16:16:48 +01:00
imx-ocotp-scu.c
imx-ocotp.c
internals.h
jz4780-efuse.c
Kconfig nvmem: Add R-Car E-FUSE driver 2024-11-05 05:33:46 +01:00
lan9662-otpc.c
layerscape-sfp.c
layouts.c nvdimm: Use of_property_present() and of_property_read_bool() 2024-08-21 16:06:43 -05:00
lpc18xx_eeprom.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
lpc18xx_otp.c nvmem: Correct some typos in comments 2024-11-05 05:33:47 +01:00
Makefile nvmem: Add R-Car E-FUSE driver 2024-11-05 05:33:46 +01:00
meson-efuse.c Char/Misc and other driver changes for 6.11-rc1 2024-07-19 15:55:08 -07:00
meson-mx-efuse.c nvmem: meson-mx-efuse: Remove nvmem_device from efuse struct 2024-05-03 07:26:39 +02:00
microchip-otpc.c nvmem: Correct some typos in comments 2024-11-05 05:33:47 +01:00
mtk-efuse.c Get rid of 'remove_new' relic from platform driver struct 2024-12-01 15:12:43 -08:00
mxs-ocotp.c
nintendo-otp.c
qcom-spmi-sdam.c nvmem: qcom-spmi-sdam: Set size in struct nvmem_config 2025-01-10 16:16:48 +01:00
qfprom.c
qoriq-efuse.c
rave-sp-eeprom.c
rcar-efuse.c nvmem: Add R-Car E-FUSE driver 2024-11-05 05:33:46 +01:00
rmem.c nvmem: rmem: add CRC validation for Mobileye EyeQ5 NVMEM 2024-12-30 15:36:00 +01:00
rockchip-efuse.c nvmem: rockchip-efuse: set type to OTP 2024-07-05 09:55:04 +02:00
rockchip-otp.c nvmem: rockchip-otp: Set type to OTP 2024-07-05 09:55:04 +02:00
sc27xx-efuse.c nvmem: sc27xx: fix module autoloading 2024-05-03 07:26:38 +02:00
sec-qfprom.c
snvs_lpgpr.c
sprd-efuse.c nvmem: sprd: fix module autoloading 2024-05-03 07:26:38 +02:00
stm32-bsec-optee-ta.c
stm32-bsec-optee-ta.h
stm32-romem.c
sunplus-ocotp.c nvmem: sunplus-ocotp: Use devm_platform_ioremap_resource_byname() helper function 2024-09-03 12:13:23 +02:00
sunxi_sid.c
u-boot-env.c nvmem: layouts: add U-Boot env layout 2024-09-11 16:05:15 +02:00
uniphier-efuse.c
vf610-ocotp.c
zynqmp_nvmem.c nvmem: zynqmp_nvmem: Add support to access efuse 2024-03-07 20:21:53 +00:00