Skip to content

Commit b7d0a97

Browse files
Ye BinJaegeuk Kim
authored andcommitted
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: f543805 ("f2fs: introduce private bioset") Signed-off-by: Ye Bin <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent d5c367e commit b7d0a97

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/f2fs/super.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4991,9 +4991,6 @@ static int __init init_f2fs_fs(void)
49914991
err = f2fs_init_shrinker();
49924992
if (err)
49934993
goto free_sysfs;
4994-
err = register_filesystem(&f2fs_fs_type);
4995-
if (err)
4996-
goto free_shrinker;
49974994
f2fs_create_root_stats();
49984995
err = f2fs_init_post_read_processing();
49994996
if (err)
@@ -5016,7 +5013,12 @@ static int __init init_f2fs_fs(void)
50165013
err = f2fs_create_casefold_cache();
50175014
if (err)
50185015
goto free_compress_cache;
5016+
err = register_filesystem(&f2fs_fs_type);
5017+
if (err)
5018+
goto free_casefold_cache;
50195019
return 0;
5020+
free_casefold_cache:
5021+
f2fs_destroy_casefold_cache();
50205022
free_compress_cache:
50215023
f2fs_destroy_compress_cache();
50225024
free_compress_mempool:
@@ -5031,8 +5033,6 @@ static int __init init_f2fs_fs(void)
50315033
f2fs_destroy_post_read_processing();
50325034
free_root_stats:
50335035
f2fs_destroy_root_stats();
5034-
unregister_filesystem(&f2fs_fs_type);
5035-
free_shrinker:
50365036
f2fs_exit_shrinker();
50375037
free_sysfs:
50385038
f2fs_exit_sysfs();
@@ -5056,6 +5056,7 @@ static int __init init_f2fs_fs(void)
50565056

50575057
static void __exit exit_f2fs_fs(void)
50585058
{
5059+
unregister_filesystem(&f2fs_fs_type);
50595060
f2fs_destroy_casefold_cache();
50605061
f2fs_destroy_compress_cache();
50615062
f2fs_destroy_compress_mempool();
@@ -5064,7 +5065,6 @@ static void __exit exit_f2fs_fs(void)
50645065
f2fs_destroy_iostat_processing();
50655066
f2fs_destroy_post_read_processing();
50665067
f2fs_destroy_root_stats();
5067-
unregister_filesystem(&f2fs_fs_type);
50685068
f2fs_exit_shrinker();
50695069
f2fs_exit_sysfs();
50705070
f2fs_destroy_garbage_collection_cache();

0 commit comments

Comments
 (0)