Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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: f543805fcd60 ("f2fs: introduce private bioset")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Ye Bin and committed by
Jaegeuk Kim
b7d0a97b d5c367ef

+6 -6
+6 -6
fs/f2fs/super.c
··· 4991 4991 err = f2fs_init_shrinker(); 4992 4992 if (err) 4993 4993 goto free_sysfs; 4994 - err = register_filesystem(&f2fs_fs_type); 4995 - if (err) 4996 - goto free_shrinker; 4997 4994 f2fs_create_root_stats(); 4998 4995 err = f2fs_init_post_read_processing(); 4999 4996 if (err) ··· 5013 5016 err = f2fs_create_casefold_cache(); 5014 5017 if (err) 5015 5018 goto free_compress_cache; 5019 + err = register_filesystem(&f2fs_fs_type); 5020 + if (err) 5021 + goto free_casefold_cache; 5016 5022 return 0; 5023 + free_casefold_cache: 5024 + f2fs_destroy_casefold_cache(); 5017 5025 free_compress_cache: 5018 5026 f2fs_destroy_compress_cache(); 5019 5027 free_compress_mempool: ··· 5033 5031 f2fs_destroy_post_read_processing(); 5034 5032 free_root_stats: 5035 5033 f2fs_destroy_root_stats(); 5036 - unregister_filesystem(&f2fs_fs_type); 5037 - free_shrinker: 5038 5034 f2fs_exit_shrinker(); 5039 5035 free_sysfs: 5040 5036 f2fs_exit_sysfs(); ··· 5056 5056 5057 5057 static void __exit exit_f2fs_fs(void) 5058 5058 { 5059 + unregister_filesystem(&f2fs_fs_type); 5059 5060 f2fs_destroy_casefold_cache(); 5060 5061 f2fs_destroy_compress_cache(); 5061 5062 f2fs_destroy_compress_mempool(); ··· 5065 5064 f2fs_destroy_iostat_processing(); 5066 5065 f2fs_destroy_post_read_processing(); 5067 5066 f2fs_destroy_root_stats(); 5068 - unregister_filesystem(&f2fs_fs_type); 5069 5067 f2fs_exit_shrinker(); 5070 5068 f2fs_exit_sysfs(); 5071 5069 f2fs_destroy_garbage_collection_cache();