Skip to content

Commit 13bcd44

Browse files
lumaggregkh
authored andcommitted
nvmem: core: verify cell's raw_len
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 <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7a06ef7 commit 13bcd44

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/nvmem/core.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,18 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
605605
return -EINVAL;
606606
}
607607

608+
if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) {
609+
dev_err(&nvmem->dev,
610+
"cell %s raw len %zd unaligned to nvmem word size %d\n",
611+
cell->name ?: "<unknown>", cell->raw_len,
612+
nvmem->word_size);
613+
614+
if (info->raw_len)
615+
return -EINVAL;
616+
617+
cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size);
618+
}
619+
608620
return 0;
609621
}
610622

0 commit comments

Comments
 (0)