linux-stable/fs/f2fs
Dongliang Mu 5e1b901dd4 f2fs: fix UAF in f2fs_available_free_memory
commit 5429c9dbc9 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 d6d2b491a8 introduces the call of
f2fs_available_free_memory into issue_discard_thread.

Cc: stable@vger.kernel.org
Fixes: d6d2b491a8 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-18 19:17:15 +01:00
..
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
checkpoint.c f2fs: rebuild nat_bits during umount 2021-08-23 10:25:52 -07:00
compress.c f2fs: include non-compressed blocks in compr_written_block 2021-11-18 19:17:15 +01:00
data.c f2fs-for-5.15-rc1 2021-09-04 10:48:47 -07:00
debug.c f2fs: convert S_IRUGO to 0444 2021-08-17 11:59:05 -07:00
dir.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
extent_cache.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
f2fs.h f2fs-for-5.15-rc1 2021-09-04 10:48:47 -07:00
file.c f2fs-for-5.15-rc1 2021-09-04 10:48:47 -07:00
gc.c f2fs: fix to account missing .skipped_gc_rwsem 2021-08-30 10:12:47 -07:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: Handle casefolding with Encryption 2020-12-02 22:00:21 -08:00
inline.c f2fs: restructure f2fs page.private layout 2021-05-14 11:22:08 -07:00
inode.c f2fs: should use GFP_NOFS for directory inodes 2021-11-18 19:17:15 +01:00
iostat.c f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
iostat.h f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
Kconfig f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: should use GFP_NOFS for directory inodes 2021-11-18 19:17:15 +01:00
node.c f2fs: rebuild nat_bits during umount 2021-08-23 10:25:52 -07:00
node.h f2fs: swap: support migrating swapfile in aligned write mode 2021-06-23 01:09:35 -07:00
recovery.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
segment.c f2fs: Don't create discard thread when device doesn't support realtime discard 2021-08-30 10:12:46 -07:00
segment.h f2fs: correct comment in segment.h 2021-08-13 11:57:08 -07:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: fix UAF in f2fs_available_free_memory 2021-11-18 19:17:15 +01:00
sysfs.c f2fs-for-5.15-rc1 2021-09-04 10:48:47 -07:00
verity.c f2fs-for-5.13-rc1 2021-05-04 18:03:38 -07:00
xattr.c f2fs: support fault injection for f2fs_kmem_cache_alloc() 2021-08-17 11:59:05 -07:00
xattr.h f2fs: code cleanup by removing ifdef macro surrounding 2020-05-26 18:56:10 -07:00