summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSergey Shtylyov <s.shtylyov@omp.ru>2023-11-05 23:29:36 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-01-25 14:33:32 -0800
commit3b333cded94fbe5ce30d699b316c4715151268ae (patch)
treee972e2d0de3077a0ca1aab0f444d2c7c457b8c15 /fs
parent71ba0d44a741640a962d4a6092afc84e976379bc (diff)
downloadlinux-stable-3b333cded94fbe5ce30d699b316c4715151268ae.tar.gz
linux-stable-3b333cded94fbe5ce30d699b316c4715151268ae.tar.bz2
linux-stable-3b333cded94fbe5ce30d699b316c4715151268ae.zip
pstore: ram_core: fix possible overflow in persistent_ram_init_ecc()
[ Upstream commit 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: 9cc05ad97c57 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/pstore/ram_core.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index efb765b8466f..a6e5022469ab 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -189,7 +189,7 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz,
{
int numerr;
struct persistent_ram_buffer *buffer = prz->buffer;
- int ecc_blocks;
+ size_t ecc_blocks;
size_t ecc_total;
if (!ecc_info || !ecc_info->ecc_size)