Re: [PATCH 1/3] nvmem: sprd: Fix memory overflow issue during memcpy operation in efuse driver

From: Srinivas Kandagatla
Date: Fri Dec 08 2023 - 06:41:19 EST


thanks for the patch.

On 08/12/2023 06:11, Yanxin Huang wrote:
The efuse driver didn't determine the size of bytes, resulting in memory
overflow during memcpy operation.

Fixes: 096030e7f449 ("nvmem: sprd: Add Spreadtrum SoCs eFuse support")

Please add CC Stable for all the fixes.

Signed-off-by: Yanxin Huang <yanxin.huang@xxxxxxxxxx>
---
drivers/nvmem/sprd-efuse.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/nvmem/sprd-efuse.c b/drivers/nvmem/sprd-efuse.c
index bb3105f3291f..24b63620d217 100644
--- a/drivers/nvmem/sprd-efuse.c
+++ b/drivers/nvmem/sprd-efuse.c
@@ -311,6 +311,7 @@ static int sprd_efuse_read(void *context, u32 offset, void *val, size_t bytes)
ret = sprd_efuse_raw_read(efuse, index, &data, blk_double);
if (!ret) {
data >>= blk_offset;
+ bytes = bytes > sizeof(data) ? sizeof(data) : bytes;

looks like sprd_efuse_read is only reading upto 4 bytes max, and silently ignoring reading requests data after 4 bytes.

Is this working because consumers so far only requested 4 bytes and less ?
does dumping nvmem sysfs actually show real content in your case?

--srini
memcpy(val, &data, bytes);


}