From: Kevin Wolf <kwolf@redhat.com>
To: gerben@altlinux.org
Cc: qemu-devel@nongnu.org, hreitz@redhat.com, sdl.qemu@linuxtesting.org
Subject: Re: [PATCH] block/snapshot: fix *errp handling in bdrv_snapshot_goto
Date: Mon, 10 Mar 2025 12:01:05 +0100 [thread overview]
Message-ID: <Z87GcceOGOM4wAkI@redhat.com> (raw)
In-Reply-To: <20250304080213.36099-1-gerben@altlinux.org>
Am 04.03.2025 um 09:01 hat gerben@altlinux.org geschrieben:
> From: Denis Rastyogin <gerben@altlinux.org>
>
> This error was discovered by fuzzing qemu-img.
>
> If bdrv_snapshot_goto() returns an error, it is not handled immediately,
> allowing *errp to be reassigned when qcow_open() fails, which triggers
> assert(*errp == NULL) in util/error.c: void error_setv().
>
> This patch ensures that errors from bdrv_snapshot_goto() are handled
> immediately after the call, preventing *errp from being modified twice
> and avoiding unnecessary assertion failures.
>
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/2851
> Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
> ---
> block/snapshot.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/block/snapshot.c b/block/snapshot.c
> index 9c44780e96..d1b5a8d33d 100644
> --- a/block/snapshot.c
> +++ b/block/snapshot.c
> @@ -296,14 +296,20 @@ int bdrv_snapshot_goto(BlockDriverState *bs,
> bdrv_graph_wrunlock();
>
> ret = bdrv_snapshot_goto(fallback_bs, snapshot_id, errp);
> + if (ret < 0) {
> + bdrv_unref(fallback_bs);
> + bs->drv = NULL;
> + /* A bdrv_snapshot_goto() error takes precedence */
> + error_propagate(errp, local_err);
> + return ret;
> + }
Now you return without having reopened the image!
> open_ret = drv->bdrv_open(bs, options, bs->open_flags, &local_err);
> qobject_unref(options);
> if (open_ret < 0) {
> bdrv_unref(fallback_bs);
> bs->drv = NULL;
> - /* A bdrv_snapshot_goto() error takes precedence */
> error_propagate(errp, local_err);
> - return ret < 0 ? ret : open_ret;
> + return open_ret;
> }
I don't see a problem in the old code. local_err is still NULL at this
point, so it's safe to pass it to drv->bdrv_open(). A previous error
from bdrv_snapshot_goto() is stored in errp, which is separate.
The line in qcow.c (test.qed is misleading as a filename!) that causes
the assertion failure is this:
error_setg(&s->migration_blocker, "The qcow format used by node '%s' "
"does not support live migration",
bdrv_get_device_or_node_name(bs));
This is an internal field that is not related to either error in
bdrv_snapshot_goto(). This is another instance of the same bug that
bs->opaque needs to be zeroed before calling drv->bdrv_open(). I sent a
patch for that.
Kevin
prev parent reply other threads:[~2025-03-10 11:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 8:01 [PATCH] block/snapshot: fix *errp handling in bdrv_snapshot_goto gerben
2025-03-10 11:01 ` Kevin Wolf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z87GcceOGOM4wAkI@redhat.com \
--to=kwolf@redhat.com \
--cc=gerben@altlinux.org \
--cc=hreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sdl.qemu@linuxtesting.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).