-bugfix: fix qmp command migrate-set-parameters -some bugfixs about ARM hot-plugged CPUs -hw/core/machine:Fix the missing consideration of cluster-id -test/tcg:Fix target-specific Makefile variable path for user-mode -tests:add (riscv virt) machine mapping to testenv -Make a litte improvement in curl and hw/riscv -qemu support for loongarch -hw/pvrdma: Protect against buggy or malious guest driver -hw/audio/intel-hda:fix stream reset -dsoundaudio:fix crackling audio recordings -add notify-vm-exit support for i386 -blok-backend: prevent dangling BDS pointers across aio_poll() -net:Fix uninitialized data usage -net/eth:Don't consider ESP to be an IPv6 option header -hw/net/vmxnet3:Log guest-triggerable errors using LOG_GUEST_ERROR Signed-off-by: FeiXu <xufei30@huawei.com>
125 lines
4.1 KiB
Diff
125 lines
4.1 KiB
Diff
From 6363172843fd756c61d6a3725ad5b3a385eddc87 Mon Sep 17 00:00:00 2001
|
|
From: tangbinzy <tangbin_yewu@cmss.chinamobile.com>
|
|
Date: Tue, 21 Mar 2023 03:02:58 +0000
|
|
Subject: [PATCH] block-backend: prevent dangling BDS pointers across
|
|
aio_poll() mainline inclusion commit 1e3552dbd28359d35967b7c28dc86cde1bc29205
|
|
category: bugfix
|
|
|
|
---------------------------------------------------------------
|
|
|
|
The BlockBackend root child can change when aio_poll() is invoked. This
|
|
happens when a temporary filter node is removed upon blockjob
|
|
completion, for example.
|
|
|
|
Functions in block/block-backend.c must be aware of this when using a
|
|
blk_bs() pointer across aio_poll() because the BlockDriverState refcnt
|
|
may reach 0, resulting in a stale pointer.
|
|
|
|
One example is scsi_device_purge_requests(), which calls blk_drain() to
|
|
wait for in-flight requests to cancel. If the backup blockjob is active,
|
|
then the BlockBackend root child is a temporary filter BDS owned by the
|
|
blockjob. The blockjob can complete during bdrv_drained_begin() and the
|
|
last reference to the BDS is released when the temporary filter node is
|
|
removed. This results in a use-after-free when blk_drain() calls
|
|
bdrv_drained_end(bs) on the dangling pointer.
|
|
|
|
Explicitly hold a reference to bs across block APIs that invoke
|
|
aio_poll().
|
|
|
|
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2021778
|
|
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2036178
|
|
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
Message-Id: <20220111153613.25453-2-stefanha@redhat.com>
|
|
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
|
Signed-off-by: tangbinzy <tangbin_yewu@cmss.chinamobile.com>
|
|
---
|
|
block/block-backend.c | 19 +++++++++++++++++--
|
|
1 file changed, 17 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/block/block-backend.c b/block/block-backend.c
|
|
index 49d236b2a4..3a757fb746 100644
|
|
--- a/block/block-backend.c
|
|
+++ b/block/block-backend.c
|
|
@@ -840,16 +840,22 @@ BlockBackend *blk_by_public(BlockBackendPublic *public)
|
|
void blk_remove_bs(BlockBackend *blk)
|
|
{
|
|
ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
|
|
- BlockDriverState *bs;
|
|
BdrvChild *root;
|
|
|
|
notifier_list_notify(&blk->remove_bs_notifiers, blk);
|
|
if (tgm->throttle_state) {
|
|
- bs = blk_bs(blk);
|
|
+ BlockDriverState *bs = blk_bs(blk);
|
|
+
|
|
+ /*
|
|
+ * Take a ref in case blk_bs() changes across bdrv_drained_begin(), for
|
|
+ * example, if a temporary filter node is removed by a blockjob.
|
|
+ */
|
|
+ bdrv_ref(bs);
|
|
bdrv_drained_begin(bs);
|
|
throttle_group_detach_aio_context(tgm);
|
|
throttle_group_attach_aio_context(tgm, qemu_get_aio_context());
|
|
bdrv_drained_end(bs);
|
|
+ bdrv_unref(bs);
|
|
}
|
|
|
|
blk_update_root_state(blk);
|
|
@@ -1731,6 +1737,7 @@ void blk_drain(BlockBackend *blk)
|
|
BlockDriverState *bs = blk_bs(blk);
|
|
|
|
if (bs) {
|
|
+ bdrv_ref(bs);
|
|
bdrv_drained_begin(bs);
|
|
}
|
|
|
|
@@ -1740,6 +1747,7 @@ void blk_drain(BlockBackend *blk)
|
|
|
|
if (bs) {
|
|
bdrv_drained_end(bs);
|
|
+ bdrv_unref(bs);
|
|
}
|
|
}
|
|
|
|
@@ -2112,10 +2120,13 @@ static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context,
|
|
int ret;
|
|
|
|
if (bs) {
|
|
+ bdrv_ref(bs);
|
|
+
|
|
if (update_root_node) {
|
|
ret = bdrv_child_try_set_aio_context(bs, new_context, blk->root,
|
|
errp);
|
|
if (ret < 0) {
|
|
+ bdrv_unref(bs);
|
|
return ret;
|
|
}
|
|
}
|
|
@@ -2125,6 +2136,8 @@ static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context,
|
|
throttle_group_attach_aio_context(tgm, new_context);
|
|
bdrv_drained_end(bs);
|
|
}
|
|
+
|
|
+ bdrv_unref(bs);
|
|
}
|
|
|
|
blk->ctx = new_context;
|
|
@@ -2394,11 +2407,13 @@ void blk_io_limits_disable(BlockBackend *blk)
|
|
ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
|
|
assert(tgm->throttle_state);
|
|
if (bs) {
|
|
+ bdrv_ref(bs);
|
|
bdrv_drained_begin(bs);
|
|
}
|
|
throttle_group_unregister_tgm(tgm);
|
|
if (bs) {
|
|
bdrv_drained_end(bs);
|
|
+ bdrv_unref(bs);
|
|
}
|
|
}
|
|
|
|
--
|
|
2.27.0
|
|
|