aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYe Bin <[email protected]>2022-09-14 18:08:12 +0800
committerTheodore Ts'o <[email protected]>2022-09-30 23:46:52 -0400
commit243d1a5d505d0b0460c9af0ad56ed4a56ef0bebd (patch)
tree03104b6889bdf97ca76bd508ab80c03f1838d4af
parente0d5fc7a6d80ac2406c7dfc6bb625201d0250a8a (diff)
jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
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: [email protected] Signed-off-by: Ye Bin <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
-rw-r--r--fs/jbd2/journal.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index d00193077bce..bc8270e0d7d0 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -923,16 +923,16 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
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;