This is a note to let you know that I've just added the patch titled f2fs: fix UAF in f2fs_available_free_memory to the 5.14-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: f2fs-fix-uaf-in-f2fs_available_free_memory.patch and it can be found in the queue-5.14 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 5429c9dbc9025f9a166f64e22e3a69c94fd5b29b Mon Sep 17 00:00:00 2001 From: Dongliang Mu <mudongliangabcd@xxxxxxxxx> Date: Thu, 4 Nov 2021 16:22:01 +0800 Subject: f2fs: fix UAF in f2fs_available_free_memory From: Dongliang Mu <mudongliangabcd@xxxxxxxxx> commit 5429c9dbc9025f9a166f64e22e3a69c94fd5b29b upstream. 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@xxxxxxxxxxxxxxx Fixes: d6d2b491a82e ("f2fs: allow to change discard policy based on cached discard cmds") Signed-off-by: Dongliang Mu <mudongliangabcd@xxxxxxxxx> Reviewed-by: Chao Yu <chao@xxxxxxxxxx> Signed-off-by: Jaegeuk Kim <jaegeuk@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/f2fs/super.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4271,6 +4271,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); Patches currently in stable-queue which might be from mudongliangabcd@xxxxxxxxx are queue-5.14/f2fs-fix-uaf-in-f2fs_available_free_memory.patch queue-5.14/memory-fsl_ifc-fix-leak-of-irq-and-nand_irq-in-fsl_i.patch queue-5.14/jfs-fix-memleak-in-jfs_mount.patch