]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvmem: core: verify cell's raw_len
authorDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Fri, 11 Apr 2025 11:22:47 +0000 (12:22 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:41:52 +0000 (14:41 +0200)
[ Upstream commit 13bcd440f2ff38cd7e42a179c223d4b833158b33 ]

Check that the NVMEM cell's raw_len is a aligned to word_size. Otherwise
Otherwise drivers might face incomplete read while accessing the last
part of the NVMEM cell.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20250411112251.68002-10-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvmem/core.c

index 3ea94bc26e8003dafbf9400c46e113dd96e6679e..3d69c76f19236007808a7e2b6c0ae39e8af4bbc5 100644 (file)
@@ -467,6 +467,18 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
                return -EINVAL;
        }
 
+       if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) {
+               dev_err(&nvmem->dev,
+                       "cell %s raw len %zd unaligned to nvmem word size %d\n",
+                       cell->name ?: "<unknown>", cell->raw_len,
+                       nvmem->word_size);
+
+               if (info->raw_len)
+                       return -EINVAL;
+
+               cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size);
+       }
+
        return 0;
 }