]> xenbits.xensource.com Git - libvirt.git/commitdiff
security_selinux: Don't ignore NVMe disks when setting image label
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 21 Sep 2022 13:56:13 +0000 (15:56 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Sep 2022 14:24:05 +0000 (16:24 +0200)
For NVMe disks we skip setting SELinux label on corresponding
VFIO group (/dev/vfio/X). This bug is only visible with
namespaces and goes as follows:

1) libvirt assigns NVMe disk to vfio-pci driver,
2) kernel creates /dev/vfio/X node with generic device_t SELinux
   label,
3) our namespace code creates the exact copy of the node in
   domain's private /dev,
4) SELinux policy kicks in an changes the label on the node to
   vfio_device_t (in the top most namespace),
5) libvirt tells QEMU to attach the NVMe disk, which is denied by
   SELinux policy.

While one can argue that kernel should have created the
/dev/vfio/X node with the correct SELinux label from the
beginning (step 2), libvirt can't rely on that and needs to set
label on its own.

Surprisingly, I already wrote the code that aims on this specific
case (v6.0.0-rc1~241), but because of a shortcut we take earlier
it is never ran. The reason is that
virStorageSourceIsLocalStorage() considers NVMe disks as
non-local because their source is not accessible via src->path
(or even if it is, it's not a local path).

Therefore, do not exit early for NVMe disks and let the function
continue.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2121441
Fixes: 284a12bae0e4cf93ea72797965d6c12e3a103f40
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/security/security_selinux.c

index 9f2872decc74407d36139f94cbc110fc747401dd..a296cb7613fa56337af9a9dbc6602ed79f83a9aa 100644 (file)
@@ -1818,7 +1818,11 @@ virSecuritySELinuxSetImageLabelInternal(virSecurityManager *mgr,
     const char *path = src->path;
     int ret;
 
-    if (!src->path || !virStorageSourceIsLocalStorage(src))
+    /* Special case NVMe. Per virStorageSourceIsLocalStorage() it's
+     * considered not local, but we still want the code below to set
+     * label on VFIO group. */
+    if (src->type != VIR_STORAGE_TYPE_NVME &&
+        (!src->path || !virStorageSourceIsLocalStorage(src)))
         return 0;
 
     secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);