Skip to contentSkip to conversation

f2fs: fix use-after-free issue

PATCH Superseded Chao Yu 2 participants 3 messages Jul 23, 2020 – Jul 24, 2020 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs: fix use-after-free issue

From: Li Guifu <[email protected]>

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 relcating f2fs_unregister_sysfs().

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

---
 fs/f2fs/super.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/f2fs/super.c +3 -2
index 80cb7cd358f8..bf8bd64c8380 100644
@@ -1175,6 +1175,9 @@ static void f2fs_put_super(struct super_block *sb)
 	int i;
 	bool dropped;
 
+	/* unregister procfs/sysfs entries to avoid race case */
+	f2fs_unregister_sysfs(sbi);
+
 	f2fs_quota_off_umount(sb);
 
 	/* prevent remaining shrinker jobs */
@@ -1240,8 +1243,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);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 5 lines · Chao Yu

From: Li Guifu <[email protected]>

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 relcating

typo issue: relcating -> relocating?

Quoted 43 lines

f2fs_unregister_sysfs().

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

---
fs/f2fs/super.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
fs/f2fs/super.c +3 -2
index 80cb7cd358f8..bf8bd64c8380 100644
@@ -1175,6 +1175,9 @@ static void f2fs_put_super(struct super_block *sb)
 	int i;
 	bool dropped;
 
+	/* unregister procfs/sysfs entries to avoid race case */
+	f2fs_unregister_sysfs(sbi);
+
 	f2fs_quota_off_umount(sb);
 
 	/* prevent remaining shrinker jobs */
@@ -1240,8 +1243,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);
Signature · 8 lines
2.26.2



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

please check typo issue for comment: relcating->relocating?
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author
#2 lore raw

Hi Feng,

Thanks for the reminder. :)

Jaegeuk, could you please fix this while merging.

Thanks,

Quoted 53 lines · Song Feng
Quoted 5 lines · Chao Yu

From: Li Guifu <[email protected]>

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 relcating

typo issue: relcating -> relocating?

Quoted 43 lines

f2fs_unregister_sysfs().

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

---
fs/f2fs/super.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
fs/f2fs/super.c +3 -2
index 80cb7cd358f8..bf8bd64c8380 100644
@@ -1175,6 +1175,9 @@ static void f2fs_put_super(struct super_block *sb)
 	int i;
 	bool dropped;
 
+	/* unregister procfs/sysfs entries to avoid race case */
+	f2fs_unregister_sysfs(sbi);
+
 	f2fs_quota_off_umount(sb);
 
 	/* prevent remaining shrinker jobs */
@@ -1240,8 +1243,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);
Signature · 8 lines
2.26.2



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

please check typo issue for comment: relcating->relocating?