Skip to content

Commit e7385c8

Browse files
Ye Bingregkh
authored andcommitted
jbd2: fix potential buffer head reference count leak
commit e0d5fc7 upstream. As in 'jbd2_fc_wait_bufs' if buffer isn't uptodate, will return -EIO without update 'journal->j_fc_off'. But 'jbd2_fc_release_bufs' will release buffer head from ‘j_fc_off - 1’ if 'bh' is NULL will terminal release which will lead to buffer head buffer head reference count leak. To solve above issue, update 'journal->j_fc_off' before return -EIO. 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-2-yebin10@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d87fe29 commit e7385c8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/jbd2/journal.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,14 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
926926
wait_on_buffer(bh);
927927
put_bh(bh);
928928
journal->j_fc_wbuf[i] = NULL;
929-
if (unlikely(!buffer_uptodate(bh)))
929+
/*
930+
* Update j_fc_off so jbd2_fc_release_bufs can release remain
931+
* buffer head.
932+
*/
933+
if (unlikely(!buffer_uptodate(bh))) {
934+
journal->j_fc_off = i;
930935
return -EIO;
936+
}
931937
}
932938

933939
return 0;

0 commit comments

Comments
 (0)