mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
storage: qemu: Fix security labelling of new image chain elements
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
This commit is contained in:
parent
be90aa0026
commit
7e130e8b35
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 transferLabels)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (force)
|
||||
virStorageSourceSeclabelsClear(newelem);
|
||||
|
||||
if (!newelem->seclabels &&
|
||||
if (transferLabels &&
|
||||
!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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user