linux/fs/f2fs
Chao Yu ee1b421c46 f2fs: fix to do sanity check on sit_bitmap_size
commit 5db0d252c6 upstream.

w/ below testcase, resize will generate a corrupted image which
contains inconsistent metadata, so when mounting such image, it
will trigger kernel panic:

touch img
truncate -s $((512*1024*1024*1024)) img
mkfs.f2fs -f img $((256*1024*1024))
resize.f2fs -s -i img -t $((1024*1024*1024))
mount img /mnt/f2fs

------------[ cut here ]------------
kernel BUG at fs/f2fs/segment.h:863!
Oops: invalid opcode: 0000 [#1] SMP PTI
CPU: 11 UID: 0 PID: 3922 Comm: mount Not tainted 6.15.0-rc1+ #191 PREEMPT(voluntary)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:f2fs_ra_meta_pages+0x47c/0x490

Call Trace:
 f2fs_build_segment_manager+0x11c3/0x2600
 f2fs_fill_super+0xe97/0x2840
 mount_bdev+0xf4/0x140
 legacy_get_tree+0x2b/0x50
 vfs_get_tree+0x29/0xd0
 path_mount+0x487/0xaf0
 __x64_sys_mount+0x116/0x150
 do_syscall_64+0x82/0x190
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
RIP: 0033:0x7fdbfde1bcfe

The reaseon is:

sit_i->bitmap_size is 192, so size of sit bitmap is 192*8=1536, at maximum
there are 1536 sit blocks, however MAIN_SEGS is 261893, so that sit_blk_cnt
is 4762, build_sit_entries() -> current_sit_addr() tries to access
out-of-boundary in sit_bitmap at offset from [1536, 4762), once sit_bitmap
and sit_bitmap_mirror is not the same, it will trigger f2fs_bug_on().

Let's add sanity check in f2fs_sanity_check_ckpt() to avoid panic.

Cc: stable@vger.kernel.org
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-06-27 11:11:21 +01:00
..
acl.c f2fs: Use in_group_or_capable() helper 2024-06-25 11:15:48 +02:00
acl.h fs: port ->set_acl() to pass mnt_idmap 2023-01-19 09:24:27 +01:00
checkpoint.c Revert "f2fs: rebuild nat_bits during umount" 2025-04-20 10:15:20 +02:00
compress.c f2fs: get rid of page->index 2024-09-06 23:04:48 +00:00
data.c f2fs: fix to detect gcing page in f2fs_is_cp_guaranteed() 2025-06-19 15:31:45 +02:00
debug.c f2fs: clean up val{>>,<<}F2FS_BLKSIZE_BITS 2024-08-21 00:56:27 +00:00
dir.c f2fs: Introduce linear search for dentries 2025-02-08 09:58:11 +01:00
extent_cache.c f2fs: add a sysfs node to limit max read extent count per-inode 2024-12-14 20:04:06 +01:00
f2fs.h f2fs: fix to do sanity check on sbi->total_valid_block_count 2025-06-19 15:31:42 +02:00
file.c f2fs: fix to avoid forcing direct write to use buffered IO on inline_data inode 2024-12-05 14:02:23 +01:00
gc.c f2fs: zone: fix to avoid inconsistence in between SIT and SSA 2025-06-19 15:31:41 +02:00
gc.h f2fs: add valid block ratio not to do excessive GC for one time GC 2024-09-11 03:33:08 +00:00
hash.c f2fs: don't use casefolded comparison for "." and ".." 2022-05-17 11:19:23 -07:00
inline.c f2fs: Introduce linear search for dentries 2025-02-08 09:58:11 +01:00
inode.c f2fs: fix to do sanity check on ino and xnid 2025-06-27 11:11:21 +01:00
iostat.c f2fs: add async reset zone command support 2023-06-12 13:04:09 -07:00
iostat.h f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx() 2023-02-07 10:39:28 -08:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: prevent kernel warning due to negative i_nlink from corrupted image 2025-06-27 11:11:21 +01:00
node.c Revert "f2fs: rebuild nat_bits during umount" 2025-04-20 10:15:20 +02:00
node.h f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-02-27 09:41:12 -08:00
recovery.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
segment.c f2fs: fix to drop all discards after creating snapshot on lvm device 2024-12-09 10:41:05 +01:00
segment.h f2fs: prevent the current section from being selected as a victim during GC 2025-06-19 15:31:42 +02:00
shrinker.c f2fs: add block_age-based extent cache 2022-12-12 14:53:56 -08:00
super.c f2fs: fix to do sanity check on sit_bitmap_size 2025-06-27 11:11:21 +01:00
sysfs.c f2fs: introduce f2fs_base_attr for global sysfs entries 2025-05-29 11:03:00 +02:00
verity.c f2fs-6.12-rc1 2024-09-24 15:12:38 -07:00
xattr.c f2fs: reduce expensive checkpoint trigger frequency 2024-08-15 15:26:39 +00:00
xattr.h f2fs: move f2fs_xattr_handlers and f2fs_xattr_handler_map to .rodata 2023-10-09 16:24:18 +02:00