From: Jan Kara <jack@suse.cz>
To: Ye Bin <yebin10@huawei.com>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
jack@suse.cz
Subject: Re: [PATCH -next 2/2] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs
Date: Wed, 14 Sep 2022 16:36:44 +0200 [thread overview]
Message-ID: <20220914143644.chjvnr3eiv6uxaaj@quack3> (raw)
In-Reply-To: <20220914100812.1414768-3-yebin10@huawei.com>
On Wed 14-09-22 18:08:12, Ye Bin wrote:
> 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 <yebin10@huawei.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 1c833d8cb0fe..4d49f629d06b 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;
> --
> 2.31.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2022-09-14 14:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-14 10:08 [PATCH -next 0/2] Fix two issue in jbd2_fc_wait_bufs Ye Bin
2022-09-14 10:08 ` [PATCH -next 1/2] jbd2: fix potential buffer head reference count leak Ye Bin
2022-09-14 14:36 ` Jan Kara
2022-09-14 10:08 ` [PATCH -next 2/2] jbd2: fix potential use-after-free in jbd2_fc_wait_bufs Ye Bin
2022-09-14 14:36 ` Jan Kara [this message]
2022-09-30 3:19 ` [PATCH -next 0/2] Fix two issue " Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220914143644.chjvnr3eiv6uxaaj@quack3 \
--to=jack@suse.cz \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=yebin10@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox