Skip to content

Commit 5429c9d

Browse files
mudongliangJaegeuk Kim
authored andcommitted
f2fs: fix UAF in f2fs_available_free_memory
if2fs_fill_super -> f2fs_build_segment_manager -> create_discard_cmd_control -> f2fs_start_discard_thread It invokes kthread_run to create a thread and run issue_discard_thread. However, if f2fs_build_node_manager fails, the control flow goes to free_nm and calls f2fs_destroy_node_manager. This function will free sbi->nm_info. However, if issue_discard_thread accesses sbi->nm_info after the deallocation, but before the f2fs_stop_discard_thread, it will cause UAF(Use-after-free). -> f2fs_destroy_segment_manager -> destroy_discard_cmd_control -> f2fs_stop_discard_thread Fix this by stopping discard thread before f2fs_destroy_node_manager. Note that, the commit d6d2b49 introduces the call of f2fs_available_free_memory into issue_discard_thread. Cc: [email protected] Fixes: d6d2b49 ("f2fs: allow to change discard policy based on cached discard cmds") Signed-off-by: Dongliang Mu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent e3b49ea commit 5429c9d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/f2fs/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
43854385
free_stats:
43864386
f2fs_destroy_stats(sbi);
43874387
free_nm:
4388+
/* stop discard thread before destroying node manager */
4389+
f2fs_stop_discard_thread(sbi);
43884390
f2fs_destroy_node_manager(sbi);
43894391
free_sm:
43904392
f2fs_destroy_segment_manager(sbi);

0 commit comments

Comments
 (0)