Skip to content

Commit d11d2de

Browse files
Ye Bingregkh
Ye Bin
authored andcommitted
jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
commit 243d1a5 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: [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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e7385c8 commit d11d2de

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/jbd2/journal.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -924,16 +924,16 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
924924
for (i = j_fc_off - 1; i >= j_fc_off - num_blks; i--) {
925925
bh = journal->j_fc_wbuf[i];
926926
wait_on_buffer(bh);
927-
put_bh(bh);
928-
journal->j_fc_wbuf[i] = NULL;
929927
/*
930928
* Update j_fc_off so jbd2_fc_release_bufs can release remain
931929
* buffer head.
932930
*/
933931
if (unlikely(!buffer_uptodate(bh))) {
934-
journal->j_fc_off = i;
932+
journal->j_fc_off = i + 1;
935933
return -EIO;
936934
}
935+
put_bh(bh);
936+
journal->j_fc_wbuf[i] = NULL;
937937
}
938938

939939
return 0;

0 commit comments

Comments
 (0)