From: Thomas Huth <thuth@redhat.com>
To: Alexander Bulekov <alxndr@bu.edu>, qemu-devel@nongnu.org
Cc: Darren Kenny <darren.kenny@oracle.com>,
Stefan Hajnoczi <stefanha@redhat.com>, Fam Zheng <fam@euphon.net>,
"open list:Block I/O path" <qemu-block@nongnu.org>
Subject: Re: [PATCH] async: avoid use-after-free on re-entrancy guard
Date: Tue, 2 May 2023 09:48:29 +0200 [thread overview]
Message-ID: <52984020-f336-08ad-426c-ebf9da9d0597@redhat.com> (raw)
In-Reply-To: <20230501141956.3444868-1-alxndr@bu.edu>
On 01/05/2023 16.19, Alexander Bulekov wrote:
> A BH callback can free the BH, causing a use-after-free in aio_bh_call.
> Fix that by keeping a local copy of the re-entrancy guard pointer.
>
> Buglink: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58513
> Fixes: 9c86c97f12 ("async: Add an optional reentrancy guard to the BH API")
> Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
> ---
> util/async.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/util/async.c b/util/async.c
> index 9df7674b4e..055070ffbd 100644
> --- a/util/async.c
> +++ b/util/async.c
> @@ -156,18 +156,20 @@ void aio_bh_call(QEMUBH *bh)
> {
> bool last_engaged_in_io = false;
>
> - if (bh->reentrancy_guard) {
> - last_engaged_in_io = bh->reentrancy_guard->engaged_in_io;
> - if (bh->reentrancy_guard->engaged_in_io) {
> + /* Make a copy of the guard-pointer as cb may free the bh */
> + MemReentrancyGuard *reentrancy_guard = bh->reentrancy_guard;
> + if (reentrancy_guard) {
> + last_engaged_in_io = reentrancy_guard->engaged_in_io;
> + if (reentrancy_guard->engaged_in_io) {
> trace_reentrant_aio(bh->ctx, bh->name);
> }
> - bh->reentrancy_guard->engaged_in_io = true;
> + reentrancy_guard->engaged_in_io = true;
> }
>
> bh->cb(bh->opaque);
>
> - if (bh->reentrancy_guard) {
> - bh->reentrancy_guard->engaged_in_io = last_engaged_in_io;
> + if (reentrancy_guard) {
> + reentrancy_guard->engaged_in_io = last_engaged_in_io;
> }
> }
Reviewed-by: Thomas Huth <thuth@redhat.com>
I'll assemble a pull request with this later today, to avoid that people run
into this regression.
Thomas
next prev parent reply other threads:[~2023-05-02 7:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-01 14:19 [PATCH] async: avoid use-after-free on re-entrancy guard Alexander Bulekov
2023-05-02 7:48 ` Thomas Huth [this message]
2023-05-02 11:40 ` Stefan Hajnoczi
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=52984020-f336-08ad-426c-ebf9da9d0597@redhat.com \
--to=thuth@redhat.com \
--cc=alxndr@bu.edu \
--cc=darren.kenny@oracle.com \
--cc=fam@euphon.net \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).