Skip to content

Commit

Permalink
f2fs: fix use-after-free issue
Browse files Browse the repository at this point in the history
[ Upstream commit 99c787c ]

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>
  • Loading branch information
Li Guifu authored and gregkh committed Sep 3, 2020
1 parent 4cba879 commit 45e3039
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/f2fs/super.c
Expand Up @@ -1075,6 +1075,9 @@ static void f2fs_put_super(struct super_block *sb)
int i;
bool dropped;

/* unregister procfs/sysfs entries in advance to avoid race case */
f2fs_unregister_sysfs(sbi);

f2fs_quota_off_umount(sb);

/* prevent remaining shrinker jobs */
Expand Down Expand Up @@ -1138,8 +1141,6 @@ static void f2fs_put_super(struct super_block *sb)

kvfree(sbi->ckpt);

f2fs_unregister_sysfs(sbi);

sb->s_fs_info = NULL;
if (sbi->s_chksum_driver)
crypto_free_shash(sbi->s_chksum_driver);
Expand Down

0 comments on commit 45e3039

Please sign in to comment.