ACK: [SRU][B][PATCH 2/2] f2fs: fix to do sanity check on segment/section count

Thadeu Lima de Souza Cascardo cascardo at canonical.com
Thu Sep 30 19:06:39 UTC 2021


On Thu, Sep 30, 2021 at 11:28:47AM -0700, Luke Nowakowski-Krijger wrote:
> As syzbot reported:
> 
> BUG: KASAN: slab-out-of-bounds in init_min_max_mtime fs/f2fs/segment.c:4710 [inline]
> BUG: KASAN: slab-out-of-bounds in f2fs_build_segment_manager+0x9302/0xa6d0 fs/f2fs/segment.c:4792
> Read of size 8 at addr ffff8880a1b934a8 by task syz-executor682/6878
> 
> CPU: 1 PID: 6878 Comm: syz-executor682 Not tainted 5.9.0-rc6-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
> Call Trace:
>  __dump_stack lib/dump_stack.c:77 [inline]
>  dump_stack+0x198/0x1fd lib/dump_stack.c:118
>  print_address_description.constprop.0.cold+0xae/0x497 mm/kasan/report.c:383
>  __kasan_report mm/kasan/report.c:513 [inline]
>  kasan_report.cold+0x1f/0x37 mm/kasan/report.c:530
>  init_min_max_mtime fs/f2fs/segment.c:4710 [inline]
>  f2fs_build_segment_manager+0x9302/0xa6d0 fs/f2fs/segment.c:4792
>  f2fs_fill_super+0x381a/0x6e80 fs/f2fs/super.c:3633
>  mount_bdev+0x32e/0x3f0 fs/super.c:1417
>  legacy_get_tree+0x105/0x220 fs/fs_context.c:592
>  vfs_get_tree+0x89/0x2f0 fs/super.c:1547
>  do_new_mount fs/namespace.c:2875 [inline]
>  path_mount+0x1387/0x20a0 fs/namespace.c:3192
>  do_mount fs/namespace.c:3205 [inline]
>  __do_sys_mount fs/namespace.c:3413 [inline]
>  __se_sys_mount fs/namespace.c:3390 [inline]
>  __x64_sys_mount+0x27f/0x300 fs/namespace.c:3390
>  do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
>  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> The root cause is: if segs_per_sec is larger than one, and segment count
> in last section is less than segs_per_sec, we will suffer out-of-boundary
> memory access on sit_i->sentries[] in init_min_max_mtime().
> 
> Fix this by adding sanity check among segment count, section count and
> segs_per_sec value in sanity_check_raw_super().
> 
> Reported-by: syzbot+481a3ffab50fed41dcc0 at syzkaller.appspotmail.com
> Signed-off-by: Chao Yu <yuchao0 at huawei.com>
> Signed-off-by: Jaegeuk Kim <jaegeuk at kernel.org>
> (backported from commit 3a22e9ac71585bcb7667e44641f1bbb25295f0ce)
> [lukenow: changed f2fs_info to f2fs_msg because the f2fs_info
> infastructure would require too many changes]
> CVE-2019-19449
> Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger at canonical.com>

Acked-by: Thadeu Lima de Souza Cascardo <cascardo at canonical.com>

> ---
>  fs/f2fs/super.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 9eba35db374c..28237918ad1b 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -2053,6 +2053,13 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
>  		return -EFSCORRUPTED;
>  	}
>  
> +	if (segment_count_main != total_sections * segs_per_sec) {
> +		f2fs_msg(sb, KERN_INFO,
> +			"Invalid segment/section count (%u != %u * %u)",
> +			segment_count_main, total_sections, segs_per_sec);
> +		return -EFSCORRUPTED;
> +	}
> +
>  	if ((segment_count / segs_per_sec) < total_sections) {
>  		f2fs_msg(sb, KERN_INFO,
>  			"Small segment_count (%u < %u * %u)",
> -- 
> 2.30.2
> 
> 
> -- 
> kernel-team mailing list
> kernel-team at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team



More information about the kernel-team mailing list