[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-7.2.6 05/51] async: avoid use-after-free on re-entrancy guard
From: |
Michael Tokarev |
Subject: |
[Stable-7.2.6 05/51] async: avoid use-after-free on re-entrancy guard |
Date: |
Mon, 11 Sep 2023 11:01:56 +0300 |
From: Alexander Bulekov <alxndr@bu.edu>
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>
Message-Id: <20230501141956.3444868-1-alxndr@bu.edu>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit 7915bd06f25e1803778081161bf6fa10c42dc7cd)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/util/async.c b/util/async.c
index ca149507e9..a1f07fc5a7 100644
--- a/util/async.c
+++ b/util/async.c
@@ -151,18 +151,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.2
- [Stable-7.2.6 00/51] v2 Patch Round-up for stable 7.2.6, freeze on 2023-09-19, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 01/51] gitlab-ci: check-dco.py: switch from master to stable-7.2 branch, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 03/51] memory: prevent dma-reentracy issues, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 02/51] python: drop pipenv, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 06/51] checkpatch: add qemu_bh_new/aio_bh_new checks, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 05/51] async: avoid use-after-free on re-entrancy guard,
Michael Tokarev <=
- [Stable-7.2.6 04/51] async: Add an optional reentrancy guard to the BH API, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 07/51] hw: replace most qemu_bh_new calls with qemu_bh_new_guarded, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 08/51] lsi53c895a: disable reentrancy detection for script RAM, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 09/51] lsi53c895a: disable reentrancy detection for MMIO region, too, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 11/51] raven: disable reentrancy detection for iomem, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 10/51] bcm2835_property: disable reentrancy detection for iomem, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 12/51] apic: disable reentrancy detection for apic-msi, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 13/51] loongarch: mark loongarch_ipi_iocsr re-entrnacy safe, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 14/51] pnv_lpc: disable reentrancy detection for lpc-hc, Michael Tokarev, 2023/09/11
- [Stable-7.2.6 43/51] hw/ide/ahci: PxCI should not get cleared when ERR_STAT is set, Michael Tokarev, 2023/09/11