Patch "f2fs: fix to avoid use-after-free for cached IPU bio" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    f2fs: fix to avoid use-after-free for cached IPU bio

to the 5.10-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-to-avoid-use-after-free-for-cached-ipu-bio.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 0d97b1c80eb3b90751903cd42a38009d3e0812fb
Author: Chao Yu <chao@xxxxxxxxxx>
Date:   Mon Apr 10 10:14:02 2023 +0800

    f2fs: fix to avoid use-after-free for cached IPU bio
    
    [ Upstream commit 5cdb422c839134273866208dad5360835ddb9794 ]
    
    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: 0b20fcec8651 ("f2fs: cache global IPU bio")
    Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
    Signed-off-by: Jaegeuk Kim <jaegeuk@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index db26e87b8f0dd..e9481c940895c 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -849,6 +849,8 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
 	bool found = false;
 	struct bio *target = bio ? *bio : NULL;
 
+	f2fs_bug_on(sbi, !target && !page);
+
 	for (temp = HOT; temp < NR_TEMP_TYPE && !found; temp++) {
 		struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
 		struct list_head *head = &io->bio_list;
@@ -2917,7 +2919,8 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,
 
 	if (unlikely(f2fs_cp_error(sbi))) {
 		f2fs_submit_merged_write(sbi, DATA);
-		f2fs_submit_merged_ipu_write(sbi, bio, NULL);
+		if (bio && *bio)
+			f2fs_submit_merged_ipu_write(sbi, bio, NULL);
 		submitted = NULL;
 	}
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux