From: Nikita Zhandarovich Date: Wed, 24 Jul 2024 17:05:44 +0000 (-0700) Subject: f2fs: prevent possible int overflow in dir_block_index() X-Git-Tag: v5.10.227~280 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=85c2f7bd573d4cff37ec8002e2b40eda9c7d7909;p=thirdparty%2Fkernel%2Fstable.git f2fs: prevent possible int overflow in dir_block_index() commit 47f268f33dff4a5e31541a990dc09f116f80e61c upstream. The result of multiplication between values derived from functions dir_buckets() and bucket_blocks() *could* technically reach 2^30 * 2^2 = 2^32. While unlikely to happen, it is prudent to ensure that it will not lead to integer overflow. Thus, use mul_u32_u32() as it's more appropriate to mitigate the issue. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Fixes: 3843154598a0 ("f2fs: introduce large directory support") Cc: stable@vger.kernel.org Signed-off-by: Nikita Zhandarovich Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 6694298b1660f..c6348e346851f 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -183,7 +183,8 @@ static unsigned long dir_block_index(unsigned int level, unsigned long bidx = 0; for (i = 0; i < level; i++) - bidx += dir_buckets(i, dir_level) * bucket_blocks(i); + bidx += mul_u32_u32(dir_buckets(i, dir_level), + bucket_blocks(i)); bidx += idx * bucket_blocks(level); return bidx; }