Skip to content

Commit

Permalink
block/amend: Keep strong reference to BDS
Browse files Browse the repository at this point in the history
Otherwise, the BDS might be freed while the job is running, which would
cause a use-after-free.

Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220304153729.711387-5-hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Mar 4, 2022
1 parent b8ba600 commit 78fa41f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions block/amend.c
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 78fa41f

Please sign in to comment.