From: Peter Krempa Date: Wed, 16 Jun 2021 13:42:53 +0000 (+0200) Subject: qemuSnapshotPrepareDiskExternal: Enforce match between snapshot type and existing... X-Git-Tag: v7.5.0-rc1~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=919b1296032a58b27995ac2d13b035c9be86c17b;p=thirdparty%2Flibvirt.git qemuSnapshotPrepareDiskExternal: Enforce match between snapshot type and existing file type The code executed later when creating a snapshot makes all decisions based on the configured type rather than the actual type of the existing file, while the check whether the file exists is based solely on the on-disk type. Since a block device is allowed to exist even when not reusing existing files in contrast to regular files this creates a potential for a block device to squeak past the check but then be influenced by other code executed later. Specifically this is a problem when creating a snapshot with the following XML: If the snapshot creation fails, '/dev/sdb' will be removed because it's considered to be a regular file by the cleanup code. Add a check that will force that the configured type matches the on-disk state. Additional supporting reason is that qemu stopped to accept block devices with the 'file' backend, thus the above configuration will not work any more. This allows us to fail sooner. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1972145 Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index f06d0ada38..96c43f69e7 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -598,6 +598,15 @@ qemuSnapshotPrepareDiskExternal(virDomainObj *vm, } } } else { + /* at this point VIR_STORAGE_TYPE_DIR was already rejected */ + if ((snapdisk->src->type == VIR_STORAGE_TYPE_BLOCK && !S_ISBLK(st.st_mode)) || + (snapdisk->src->type == VIR_STORAGE_TYPE_FILE && !S_ISREG(st.st_mode))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("mismatch between configured type for snapshot disk '%s' and the type of existing file '%s'"), + snapdisk->name, snapdisk->src->path); + return -1; + } + if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("external snapshot file for disk %s already "