]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: avoid potential int overflow in sanity_check_area_boundary()
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Wed, 24 Jul 2024 17:51:58 +0000 (10:51 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:11:14 +0000 (15:11 +0200)
commit 50438dbc483ca6a133d2bce9d5d6747bcee38371 upstream.

While calculating the end addresses of main area and segment 0, u32
may be not enough to hold the result without the danger of int
overflow.

Just in case, play it safe and cast one of the operands to a
wider type (u64).

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: fd694733d523 ("f2fs: cover large section in sanity check of super")
Cc: stable@vger.kernel.org
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/super.c

index 17615eb833e0c8ce2d7691b9290dc52b4696c7a8..f8aaff9b1784ab1c9e344520ef3cedf73fba2fd0 100644 (file)
@@ -3181,9 +3181,9 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
        u32 segment_count = le32_to_cpu(raw_super->segment_count);
        u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
        u64 main_end_blkaddr = main_blkaddr +
-                               (segment_count_main << log_blocks_per_seg);
+                               ((u64)segment_count_main << log_blocks_per_seg);
        u64 seg_end_blkaddr = segment0_blkaddr +
-                               (segment_count << log_blocks_per_seg);
+                               ((u64)segment_count << log_blocks_per_seg);
 
        if (segment0_blkaddr != cp_blkaddr) {
                f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",