]> Git Repo - linux.git/commitdiff
f2fs: fix UAF in f2fs_available_free_memory
authorDongliang Mu <[email protected]>
Thu, 4 Nov 2021 08:22:01 +0000 (16:22 +0800)
committerJaegeuk Kim <[email protected]>
Tue, 9 Nov 2021 16:23:17 +0000 (08:23 -0800)
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 d6d2b491a82e1 introduces the call of
f2fs_available_free_memory into issue_discard_thread.

Cc: [email protected]
Fixes: d6d2b491a82e ("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]>
fs/f2fs/super.c

index 75f706b91ebf1bf95e645386afd4e1b1c05a84a6..60cb2ede4fdd728280aaf345429b36678a2ce10b 100644 (file)
@@ -4385,6 +4385,8 @@ free_node_inode:
 free_stats:
        f2fs_destroy_stats(sbi);
 free_nm:
+       /* stop discard thread before destroying node manager */
+       f2fs_stop_discard_thread(sbi);
        f2fs_destroy_node_manager(sbi);
 free_sm:
        f2fs_destroy_segment_manager(sbi);
This page took 0.059009 seconds and 4 git commands to generate.