Commit 569f0993 authored by Ye Bin's avatar Ye Bin Committed by Chen Zhongjin
Browse files

f2fs: fix null-ptr-deref in f2fs_submit_page_bio()

mainline inclusion
from mainline-v6.13-rc1
commit b7d0a97b28083084ebdd8e5c6bccd12e6ec18faa
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBEAFK
CVE: CVE-2024-53221

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b7d0a97b28083084ebdd8e5c6bccd12e6ec18faa



--------------------------------

There's issue as follows when concurrently installing the f2fs.ko
module and mounting the f2fs file system:
KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027]
RIP: 0010:__bio_alloc+0x2fb/0x6c0 [f2fs]
Call Trace:
 <TASK>
 f2fs_submit_page_bio+0x126/0x8b0 [f2fs]
 __get_meta_page+0x1d4/0x920 [f2fs]
 get_checkpoint_version.constprop.0+0x2b/0x3c0 [f2fs]
 validate_checkpoint+0xac/0x290 [f2fs]
 f2fs_get_valid_checkpoint+0x207/0x950 [f2fs]
 f2fs_fill_super+0x1007/0x39b0 [f2fs]
 mount_bdev+0x183/0x250
 legacy_get_tree+0xf4/0x1e0
 vfs_get_tree+0x88/0x340
 do_new_mount+0x283/0x5e0
 path_mount+0x2b2/0x15b0
 __x64_sys_mount+0x1fe/0x270
 do_syscall_64+0x5f/0x170
 entry_SYSCALL_64_after_hwframe+0x76/0x7e

Above issue happens as the biset of the f2fs file system is not
initialized before register "f2fs_fs_type".
To address above issue just register "f2fs_fs_type" at the last in
init_f2fs_fs(). Ensure that all f2fs file system resources are
initialized.

Fixes: f543805f ("f2fs: introduce private bioset")
Signed-off-by: default avatarYe Bin <yebin10@huawei.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
Conflicts:
	fs/f2fs/super.c
[Conflict caused by commit 4d9a2bb1 has not been merged]
Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
parent 90884a33
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -4116,9 +4116,6 @@ static int __init init_f2fs_fs(void)
	err = register_shrinker(&f2fs_shrinker_info);
	if (err)
		goto free_sysfs;
	err = register_filesystem(&f2fs_fs_type);
	if (err)
		goto free_shrinker;
	f2fs_create_root_stats();
	err = f2fs_init_post_read_processing();
	if (err)
@@ -4135,7 +4132,12 @@ static int __init init_f2fs_fs(void)
	err = f2fs_init_compress_cache();
	if (err)
		goto free_compress_mempool;
	err = register_filesystem(&f2fs_fs_type);
	if (err)
		goto free_compress_cache;
	return 0;
free_compress_cache:
	f2fs_destroy_compress_cache();
free_compress_mempool:
	f2fs_destroy_compress_mempool();
free_bioset:
@@ -4146,8 +4148,6 @@ static int __init init_f2fs_fs(void)
	f2fs_destroy_post_read_processing();
free_root_stats:
	f2fs_destroy_root_stats();
	unregister_filesystem(&f2fs_fs_type);
free_shrinker:
	unregister_shrinker(&f2fs_shrinker_info);
free_sysfs:
	f2fs_exit_sysfs();
@@ -4171,13 +4171,13 @@ static int __init init_f2fs_fs(void)

static void __exit exit_f2fs_fs(void)
{
	unregister_filesystem(&f2fs_fs_type);
	f2fs_destroy_compress_cache();
	f2fs_destroy_compress_mempool();
	f2fs_destroy_bioset();
	f2fs_destroy_bio_entry_cache();
	f2fs_destroy_post_read_processing();
	f2fs_destroy_root_stats();
	unregister_filesystem(&f2fs_fs_type);
	unregister_shrinker(&f2fs_shrinker_info);
	f2fs_exit_sysfs();
	f2fs_destroy_garbage_collection_cache();