* [PATCH] async: avoid use-after-free on re-entrancy guard
@ 2023-05-01 14:19 Alexander Bulekov
2023-05-02 7:48 ` Thomas Huth
2023-05-02 11:40 ` Stefan Hajnoczi
0 siblings, 2 replies; 3+ messages in thread
From: Alexander Bulekov @ 2023-05-01 14:19 UTC (permalink / raw)
To: qemu-devel
Cc: Alexander Bulekov, Thomas Huth, Darren Kenny, Stefan Hajnoczi,
Fam Zheng, open list:Block I/O path
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;
}
}
--
2.39.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] async: avoid use-after-free on re-entrancy guard
2023-05-01 14:19 [PATCH] async: avoid use-after-free on re-entrancy guard Alexander Bulekov
@ 2023-05-02 7:48 ` Thomas Huth
2023-05-02 11:40 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Huth @ 2023-05-02 7:48 UTC (permalink / raw)
To: Alexander Bulekov, qemu-devel
Cc: Darren Kenny, Stefan Hajnoczi, Fam Zheng,
open list:Block I/O path
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] async: avoid use-after-free on re-entrancy guard
2023-05-01 14:19 [PATCH] async: avoid use-after-free on re-entrancy guard Alexander Bulekov
2023-05-02 7:48 ` Thomas Huth
@ 2023-05-02 11:40 ` Stefan Hajnoczi
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2023-05-02 11:40 UTC (permalink / raw)
To: Alexander Bulekov
Cc: qemu-devel, Thomas Huth, Darren Kenny, Fam Zheng,
open list:Block I/O path
[-- Attachment #1: Type: text/plain, Size: 570 bytes --]
On Mon, May 01, 2023 at 10:19:56AM -0400, 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(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-02 11:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-01 14:19 [PATCH] async: avoid use-after-free on re-entrancy guard Alexander Bulekov
2023-05-02 7:48 ` Thomas Huth
2023-05-02 11:40 ` Stefan Hajnoczi
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).