Fix two issue in jbd2_fc_wait_bufs
cover Fix two issue in jbd2_fc_wait_bufs
Ye Bin (2):
jbd2: fix potential buffer head reference count leak
jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
fs/jbd2/journal.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/2 jbd2: fix potential buffer head reference count leak
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.
--- fs/jbd2/journal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/jbd2/journal.c +7 -1
@@ -925,8 +925,14 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)wait_on_buffer (bh);put_bh (bh); journal->j_fc_wbuf[i] =NULL ; -if (unlikely (!buffer_uptodate (bh))) +/* +* Update j_fc_off so jbd2_fc_release_bufs can release remain +* buffer head. +*/ +if (unlikely (!buffer_uptodate (bh))) { + journal->j_fc_off = i;return -EIO ; + } }return 0 ;
Signature · 1 line
2.31.1
Re: [PATCH -next 1/2] jbd2: fix potential buffer head reference count leak
Quoted 7 lines · Ye Bin
As in '
jbd2_fc_wait_bufs' if buffer isn't uptodate, will return-EIOwithout 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.Signed-off-by Ye Bin <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 27 lines
--- fs/jbd2/journal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/jbd2/journal.c +7
-1@@ -925,8 +925,14 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)wait_on_buffer (bh);put_bh (bh); journal->j_fc_wbuf[i] =NULL ; -if (unlikely (!buffer_uptodate (bh))) +/* +* Update j_fc_off so jbd2_fc_release_bufs can release remain +* buffer head. +*/ +if (unlikely (!buffer_uptodate (bh))) { + journal->j_fc_off = i;return -EIO ; + } }return 0 ;Signature · 1 line
2.31.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 2/2 jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
In reply to Ye BinIn '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.
--- fs/jbd2/journal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/jbd2/journal.c +3 -3
@@ -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 ;
Signature · 1 line
2.31.1
Re: [PATCH -next 2/2] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
Quoted 5 lines · Ye Bin
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.Signed-off-by Ye Bin <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 31 lines
--- fs/jbd2/journal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/jbd2/journal.c +3
-3@@ -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 ;Signature · 1 line
2.31.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Ye Bin
Ye Bin (2):
jbd2: fix potential buffer head reference count leak
jbd2: fix potential use-after-free injbd2_fc_wait_bufs
fs/jbd2/journal.c| 10 ++++++++--1 file changed, 8 insertions(+), 2 deletions(-)[...]
Applied, thanks!
[1/2] jbd2: fix potential buffer head reference count leak
commit: 53dee029ec341f5c985b880de34f64de60072688
[2/2] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
commit: 6e16a2d9ff8f3ea4a53e10ae4607feb446cf5c90Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>