diff options
author | Ye Bin <yebin10@huawei.com> | 2022-09-14 13:08:12 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-10-26 14:25:13 +0300 |
commit | 1d4d16daec2a6689b6d3fbfc7d2078643adc6619 (patch) | |
tree | 1d31da54ae3387ea46cffd0824c8c2b1a9ea8429 /fs | |
parent | 7a33dde572fceb45d02d188e0213c47059401c93 (diff) | |
download | linux-1d4d16daec2a6689b6d3fbfc7d2078643adc6619.tar.xz |
jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
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@kernel.org
Signed-off-by: Ye Bin <yebin10@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20220914100812.1414768-3-yebin10@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/jbd2/journal.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 7c443ee5b472..6689d235de8a 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -924,16 +924,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; |