linux-stable/fs/f2fs
Chao Yu 9a7f63283a f2fs: fix to avoid use-after-free for cached IPU bio
[ Upstream commit 5cdb422c83 ]

xfstest generic/019 reports a bug:

kernel BUG at mm/filemap.c:1619!
RIP: 0010:folio_end_writeback+0x8a/0x90
Call Trace:
 end_page_writeback+0x1c/0x60
 f2fs_write_end_io+0x199/0x420
 bio_endio+0x104/0x180
 submit_bio_noacct+0xa5/0x510
 submit_bio+0x48/0x80
 f2fs_submit_write_bio+0x35/0x300
 f2fs_submit_merged_ipu_write+0x2a0/0x2b0
 f2fs_write_single_data_page+0x838/0x8b0
 f2fs_write_cache_pages+0x379/0xa30
 f2fs_write_data_pages+0x30c/0x340
 do_writepages+0xd8/0x1b0
 __writeback_single_inode+0x44/0x370
 writeback_sb_inodes+0x233/0x4d0
 __writeback_inodes_wb+0x56/0xf0
 wb_writeback+0x1dd/0x2d0
 wb_workfn+0x367/0x4a0
 process_one_work+0x21d/0x430
 worker_thread+0x4e/0x3c0
 kthread+0x103/0x130
 ret_from_fork+0x2c/0x50

The root cause is: after cp_error is set, f2fs_submit_merged_ipu_write()
in f2fs_write_single_data_page() tries to flush IPU bio in cache, however
f2fs_submit_merged_ipu_write() missed to check validity of @bio parameter,
result in submitting random cached bio which belong to other IO context,
then it will cause use-after-free issue, fix it by adding additional
validity check.

Fixes: 0b20fcec86 ("f2fs: cache global IPU bio")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-11 23:00:27 +09:00
..
acl.c
acl.h
checkpoint.c f2fs: do not bother checkpoint by f2fs_get_node_info 2023-03-17 08:48:50 +01:00
compress.c f2fs: compress: fix to call f2fs_wait_on_page_writeback() in f2fs_write_raw_pages() 2023-05-11 23:00:27 +09:00
data.c f2fs: fix to avoid use-after-free for cached IPU bio 2023-05-11 23:00:27 +09:00
debug.c f2fs: use spin_lock to avoid hang 2022-04-08 14:23:58 +02:00
dir.c f2fs: don't use casefolded comparison for "." and ".." 2022-06-09 10:23:17 +02:00
extent_cache.c f2fs: let's avoid panic if extent_tree is not created 2023-01-24 07:22:42 +01:00
f2fs.h f2fs: enforce single zone capacity 2023-05-11 23:00:26 +09:00
file.c f2fs: handle dqget error in f2fs_transfer_project_quota() 2023-05-11 23:00:26 +09:00
gc.c f2fs: do not bother checkpoint by f2fs_get_node_info 2023-03-17 08:48:50 +01:00
gc.h
hash.c f2fs: don't use casefolded comparison for "." and ".." 2022-06-09 10:23:17 +02:00
inline.c f2fs: do not bother checkpoint by f2fs_get_node_info 2023-03-17 08:48:50 +01:00
inode.c f2fs: retry to update the inode page given data corruption 2023-03-17 08:48:50 +01:00
iostat.c f2fs: fix to avoid potential memory corruption in __update_iostat_latency() 2023-03-11 13:57:26 +01:00
iostat.h
Kconfig
Makefile
namei.c f2fs: attach inline_data after setting compression 2022-06-29 09:03:27 +02:00
node.c f2fs: do not bother checkpoint by f2fs_get_node_info 2023-03-17 08:48:50 +01:00
node.h
recovery.c f2fs: do not bother checkpoint by f2fs_get_node_info 2023-03-17 08:48:50 +01:00
segment.c f2fs: apply zone capacity to all zone type 2023-05-11 23:00:27 +09:00
segment.h f2fs: apply zone capacity to all zone type 2023-05-11 23:00:27 +09:00
shrinker.c
super.c f2fs: enforce single zone capacity 2023-05-11 23:00:26 +09:00
sysfs.c f2fs: fix to enable ATGC correctly via gc_idle sysfs interface 2022-04-08 14:23:10 +02:00
verity.c fs: f2fs: initialize fsdata in pagecache_write() 2023-03-11 13:57:23 +01:00
xattr.c f2fs: support fault injection for dquot_initialize() 2022-06-09 10:23:13 +02:00
xattr.h