When creating a disk image snapshot the libvirt code would blindly copy
the parents label to the newly created image. This runs into problems
when you start a VM from an image hosted on NFS (or other storage system
that doesn't support selinux labels) and the snapshot destination is on
a storage system that does support selinux labels. Libvirt's code in
that case generates a different security label for the image hosted on
NFS. This label is valid only for NFS images and doesn't allow access in
case of a locally stored image.
To fix this issue libvirt needs to refrain from copying security
information in cases where the default domain seclabel is a better
choice.
This patch repurposes the now unused @force argument of
virStorageSourceInitChainElement to denote whether a copy of the
security labelling stuff should be attempted or not. This allows to
fine-control the copy operation for cases where we need to keep the
label of the old disk vs. the cases where we need to keep the label
unset to use the default domain imagelabel.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1151718
---
Note:
I've opted not to change to use the default label when doing a block-copy via
the old API as there is no way to specify a new label all other options now
allow to provide a different label via the XML that was provided by the user.
src/qemu/qemu_driver.c | 14 ++++++++------
src/qemu/qemu_process.c | 2 +-
src/util/virstoragefile.c | 16 +++++++---------
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 74d1bdc..0343713 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15861,7 +15861,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
unsigned long long bandwidth,
unsigned int granularity,
unsigned long long buf_size,
- unsigned int flags)
+ unsigned int flags,
+ bool keepParentLabel)
{
virQEMUDriverPtr driver = conn->privateData;
qemuDomainObjPrivatePtr priv;
@@ -15992,7 +15993,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
if (mirror->format > 0)
format = virStorageFileFormatTypeToString(mirror->format);
- if (virStorageSourceInitChainElement(mirror, disk->src, false) < 0)
+ if (virStorageSourceInitChainElement(mirror, disk->src,
+ keepParentLabel) < 0)
goto endjob;
if (qemuDomainPrepareDiskChainElement(driver, vm, mirror,
@@ -16104,7 +16106,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const
char *base,
flags &= (VIR_DOMAIN_BLOCK_REBASE_SHALLOW |
VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT);
ret = qemuDomainBlockCopyCommon(vm, dom->conn, path, dest,
- bandwidth, 0, 0, flags);
+ bandwidth, 0, 0, flags, true);
vm = NULL;
dest = NULL;
@@ -16177,8 +16179,8 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *disk, const char
*destxml,
VIR_DOMAIN_XML_INACTIVE)))
goto cleanup;
- ret = qemuDomainBlockCopyCommon(vm, dom->conn, disk, dest,
- bandwidth, granularity, buf_size, flags);
+ ret = qemuDomainBlockCopyCommon(vm, dom->conn, disk, dest, bandwidth,
+ granularity, buf_size, flags, false);
vm = NULL;
cleanup:
@@ -16353,7 +16355,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
goto endjob;
if (virStorageSourceInitChainElement(mirror,
disk->src,
- false) < 0)
+ true) < 0)
goto endjob;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b782984..1f22bd0 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1064,7 +1064,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
copy = virStorageSourceCopy(disk->mirror, false);
if (virStorageSourceInitChainElement(copy,
persistDisk->src,
- false) < 0) {
+ true) < 0) {
VIR_WARN("Unable to update persistent definition "
"on vm %s after block job",
vm->def->name);
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index aa97f75..5287c51 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1900,28 +1900,26 @@ virStorageSourceCopy(const virStorageSource *src,
* virStorageSourceInitChainElement:
* @newelem: New backing chain element disk source
* @old: Existing top level disk source
- * @force: Force-copy the information
+ * @transferLabels: Transfer security lables.
*
* Transfers relevant information from the existing disk source to the new
* backing chain element if they weren't supplied so that labelling info
* and possibly other stuff is correct.
*
- * If @force is true, user-supplied information for the new backing store
- * element is overwritten from @old instead of keeping it.
+ * If @transferLabels is true, security labels from the existing disk are copied
+ * to the new disk. Otherwise the default domain imagelabel label will be used.
*
* Returns 0 on success, -1 on error.
*/
int
virStorageSourceInitChainElement(virStorageSourcePtr newelem,
virStorageSourcePtr old,
- bool force)
+ bool transferLables)
{
int ret = -1;
- if (force)
- virStorageSourceSeclabelsClear(newelem);
-
- if (!newelem->seclabels &&
+ if (transferLables &&
+ !newelem->seclabels &&
virStorageSourceSeclabelsCopy(newelem, old) < 0)
goto cleanup;
@@ -2367,7 +2365,7 @@ virStorageSourceNewFromBacking(virStorageSourcePtr parent)
}
/* copy parent's labelling and other top level stuff */
- if (virStorageSourceInitChainElement(ret, parent, false) < 0)
+ if (virStorageSourceInitChainElement(ret, parent, true) < 0)
goto error;
}
--
2.1.0