]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
f2fs: fix use-after-free issue
authorLi Guifu <bluce.liguifu@huawei.com>
Fri, 24 Jul 2020 01:38:11 +0000 (09:38 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Sep 2020 09:22:26 +0000 (11:22 +0200)
[ Upstream commit 99c787cfd2bd04926f1f553b30bd7dcea2caaba1 ]

During umount, f2fs_put_super() unregisters procfs entries after
f2fs_destroy_segment_manager(), it may cause use-after-free
issue when umount races with procfs accessing, fix it by relocating
f2fs_unregister_sysfs().

[Chao Yu: change commit title/message a bit]

Signed-off-by: Li Guifu <bluce.liguifu@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/super.c

index 89319c3524061541bd04061e5fa7d7e8c24c1f85..990339c538b0a55da0a58122d4c941bfbe92d15c 100644 (file)
@@ -782,6 +782,9 @@ static void f2fs_put_super(struct super_block *sb)
        struct f2fs_sb_info *sbi = F2FS_SB(sb);
        int i;
 
+       /* unregister procfs/sysfs entries in advance to avoid race case */
+       f2fs_unregister_sysfs(sbi);
+
        f2fs_quota_off_umount(sb);
 
        /* prevent remaining shrinker jobs */
@@ -834,8 +837,6 @@ static void f2fs_put_super(struct super_block *sb)
 
        kfree(sbi->ckpt);
 
-       f2fs_unregister_sysfs(sbi);
-
        sb->s_fs_info = NULL;
        if (sbi->s_chksum_driver)
                crypto_free_shash(sbi->s_chksum_driver);