Files
kernel_xiaomi_sm8250/fs
Dongliang Mu edf1bf0833 UPSTREAM: 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 d6d2b491a82e1 introduces the call of
f2fs_available_free_memory into issue_discard_thread.

Cc: stable@vger.kernel.org
Fixes: d6d2b491a82e ("f2fs: allow to change discard policy based on cached discard cmds")
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit 5429c9dbc9025f9a166f64e22e3a69c94fd5b29b)
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Change-Id: If121b453455b11b2aded8ba8a3899faad431dbd3
2025-02-13 00:23:20 +02:00
..
2024-11-08 16:19:19 +01:00
2021-09-22 11:48:02 +02:00
2024-11-08 16:19:17 +01:00
2024-09-04 13:13:01 +02:00
2020-08-21 15:15:18 +05:30
2022-06-14 16:59:24 +02:00
2020-08-21 15:15:18 +05:30
2020-08-21 15:15:18 +05:30
2022-02-28 19:00:41 +05:30
2023-12-08 09:28:23 +00:00
2020-08-21 15:15:18 +05:30