Skip to content
Commit 2e4a7253 authored by Sergey Shtylyov's avatar Sergey Shtylyov Committed by Yang Yingliang
Browse files

pstore: ram_core: fix possible overflow in persistent_ram_init_ecc()

mainline inclusion
from mainline-v6.7-rc2
commit 86222a8fc16ec517de8da2604d904c9df3a08e5d
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9Q9FV
CVE: CVE-2023-52685

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=86222a8fc16ec517de8da2604d904c9df3a08e5d



--------------------------------

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: 9cc05ad9 ("staging: android: persistent_ram: refactor ecc support")
Signed-off-by: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/20231105202936.25694-1-s.shtylyov@omp.ru


Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parent f2cc57c8
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment