From 78fa41fc671eae51fd3390a12a041d1c4a241c66 Mon Sep 17 00:00:00 2001 From: Hanna Reitz Date: Fri, 4 Mar 2022 16:37:28 +0100 Subject: [PATCH] block/amend: Keep strong reference to BDS Otherwise, the BDS might be freed while the job is running, which would cause a use-after-free. Signed-off-by: Hanna Reitz Message-Id: <20220304153729.711387-5-hreitz@redhat.com> Signed-off-by: Kevin Wolf --- block/amend.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/amend.c b/block/amend.c index 553890ded9..f696a006e3 100644 --- a/block/amend.c +++ b/block/amend.c @@ -69,6 +69,8 @@ static void blockdev_amend_free(Job *job) if (s->bs->drv->bdrv_amend_clean) { s->bs->drv->bdrv_amend_clean(s->bs); } + + bdrv_unref(s->bs); } static const JobDriver blockdev_amend_job_driver = { @@ -129,6 +131,7 @@ void qmp_x_blockdev_amend(const char *job_id, return; } + bdrv_ref(bs); s->bs = bs, s->opts = QAPI_CLONE(BlockdevAmendOptions, options), s->force = has_force ? force : false;