Skip to content

Commit 6f6f84a

Browse files
z00467499chucklever
authored andcommitted
nfsd: Fix null-ptr-deref in nfsd_fill_super()
KASAN report null-ptr-deref as follows: BUG: KASAN: null-ptr-deref in nfsd_fill_super+0xc6/0xe0 [nfsd] Write of size 8 at addr 000000000000005d by task a.out/852 CPU: 7 PID: 852 Comm: a.out Not tainted 5.18.0-rc7-dirty #66 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x34/0x44 kasan_report+0xab/0x120 ? nfsd_mkdir+0x71/0x1c0 [nfsd] ? nfsd_fill_super+0xc6/0xe0 [nfsd] nfsd_fill_super+0xc6/0xe0 [nfsd] ? nfsd_mkdir+0x1c0/0x1c0 [nfsd] get_tree_keyed+0x8e/0x100 vfs_get_tree+0x41/0xf0 __do_sys_fsconfig+0x590/0x670 ? fscontext_read+0x180/0x180 ? anon_inode_getfd+0x4f/0x70 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xae This can be reproduce by concurrent operations: 1. fsopen(nfsd)/fsconfig 2. insmod/rmmod nfsd Since the nfsd file system is registered before than nfsd_net allocated, the caller may get the file_system_type and use the nfsd_net before it allocated, then null-ptr-deref occurred. So init_nfsd() should call register_filesystem() last. Fixes: bd5ae92 ("nfsd: register pernet ops last, unregister first") Signed-off-by: Zhang Xiaoxu <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 62fdb65 commit 6f6f84a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/nfsd/nfsctl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,25 +1535,25 @@ static int __init init_nfsd(void)
15351535
retval = create_proc_exports_entry();
15361536
if (retval)
15371537
goto out_free_lockd;
1538-
retval = register_filesystem(&nfsd_fs_type);
1539-
if (retval)
1540-
goto out_free_exports;
15411538
retval = register_pernet_subsys(&nfsd_net_ops);
15421539
if (retval < 0)
1543-
goto out_free_filesystem;
1540+
goto out_free_exports;
15441541
retval = register_cld_notifier();
15451542
if (retval)
15461543
goto out_free_subsys;
15471544
retval = nfsd4_create_laundry_wq();
1545+
if (retval)
1546+
goto out_free_cld;
1547+
retval = register_filesystem(&nfsd_fs_type);
15481548
if (retval)
15491549
goto out_free_all;
15501550
return 0;
15511551
out_free_all:
1552+
nfsd4_destroy_laundry_wq();
1553+
out_free_cld:
15521554
unregister_cld_notifier();
15531555
out_free_subsys:
15541556
unregister_pernet_subsys(&nfsd_net_ops);
1555-
out_free_filesystem:
1556-
unregister_filesystem(&nfsd_fs_type);
15571557
out_free_exports:
15581558
remove_proc_entry("fs/nfs/exports", NULL);
15591559
remove_proc_entry("fs/nfs", NULL);
@@ -1571,6 +1571,7 @@ static int __init init_nfsd(void)
15711571

15721572
static void __exit exit_nfsd(void)
15731573
{
1574+
unregister_filesystem(&nfsd_fs_type);
15741575
nfsd4_destroy_laundry_wq();
15751576
unregister_cld_notifier();
15761577
unregister_pernet_subsys(&nfsd_net_ops);
@@ -1581,7 +1582,6 @@ static void __exit exit_nfsd(void)
15811582
nfsd_lockd_shutdown();
15821583
nfsd4_free_slabs();
15831584
nfsd4_exit_pnfs();
1584-
unregister_filesystem(&nfsd_fs_type);
15851585
}
15861586

15871587
MODULE_AUTHOR("Olaf Kirch <[email protected]>");

0 commit comments

Comments
 (0)