mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2024-12-29 09:13:38 +00:00
pstore: ram_core: fix possible overflow in persistent_ram_init_ecc()
In persistent_ram_init_ecc(), on 64-bit arches DIV_ROUND_UP() will return
64-bit value since persistent_ram_zone::buffer_size has type size_t which
is derived from the 64-bit *unsigned long*, while the ecc_blocks variable
this value gets assigned to has (always 32-bit) *int* type. Even if that
value fits into *int* type, an overflow is still possible when calculating
the size_t typed ecc_total variable further below since there's no cast to
any 64-bit type before multiplication. Declaring the ecc_blocks variable
as *size_t* should fix this mess...
Found by Linux Verification Center (linuxtesting.org) with the SVACE static
analysis tool.
Fixes: 9cc05ad97c
("staging: android: persistent_ram: refactor ecc support")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/20231105202936.25694-1-s.shtylyov@omp.ru
Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
parent
d49270a046
commit
86222a8fc1
@ -190,7 +190,7 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz,
|
|||||||
{
|
{
|
||||||
int numerr;
|
int numerr;
|
||||||
struct persistent_ram_buffer *buffer = prz->buffer;
|
struct persistent_ram_buffer *buffer = prz->buffer;
|
||||||
int ecc_blocks;
|
size_t ecc_blocks;
|
||||||
size_t ecc_total;
|
size_t ecc_total;
|
||||||
|
|
||||||
if (!ecc_info || !ecc_info->ecc_size)
|
if (!ecc_info || !ecc_info->ecc_size)
|
||||||
|
Loading…
Reference in New Issue
Block a user