This is a note to let you know that I've just added the patch titled jbd2: fix potential use-after-free in jbd2_fc_wait_bufs to the 5.15-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: jbd2-fix-potential-use-after-free-in-jbd2_fc_wait_bufs.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 243d1a5d505d0b0460c9af0ad56ed4a56ef0bebd Mon Sep 17 00:00:00 2001 From: Ye Bin <yebin10@xxxxxxxxxx> Date: Wed, 14 Sep 2022 18:08:12 +0800 Subject: jbd2: fix potential use-after-free in jbd2_fc_wait_bufs From: Ye Bin <yebin10@xxxxxxxxxx> commit 243d1a5d505d0b0460c9af0ad56ed4a56ef0bebd upstream. In 'jbd2_fc_wait_bufs' use 'bh' after put buffer head reference count which may lead to use-after-free. So judge buffer if uptodate before put buffer head reference count. Cc: stable@xxxxxxxxxx Signed-off-by: Ye Bin <yebin10@xxxxxxxxxx> Reviewed-by: Jan Kara <jack@xxxxxxx> Link: https://lore.kernel.org/r/20220914100812.1414768-3-yebin10@xxxxxxxxxx Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/jbd2/journal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -924,16 +924,16 @@ int jbd2_fc_wait_bufs(journal_t *journal for (i = j_fc_off - 1; i >= j_fc_off - num_blks; i--) { bh = journal->j_fc_wbuf[i]; wait_on_buffer(bh); - put_bh(bh); - journal->j_fc_wbuf[i] = NULL; /* * Update j_fc_off so jbd2_fc_release_bufs can release remain * buffer head. */ if (unlikely(!buffer_uptodate(bh))) { - journal->j_fc_off = i; + journal->j_fc_off = i + 1; return -EIO; } + put_bh(bh); + journal->j_fc_wbuf[i] = NULL; } return 0; Patches currently in stable-queue which might be from yebin10@xxxxxxxxxx are queue-5.15/jbd2-fix-potential-buffer-head-reference-count-leak.patch queue-5.15/jbd2-fix-potential-use-after-free-in-jbd2_fc_wait_bufs.patch queue-5.15/btrfs-fix-race-between-quota-enable-and-quota-rescan-ioctl.patch queue-5.15/jbd2-add-miss-release-buffer-head-in-fc_do_one_pass.patch