]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_namespace: Don't unlink paths from cgroupDeviceACL
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 14 Mar 2022 14:05:11 +0000 (15:05 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 15 Mar 2022 16:03:03 +0000 (17:03 +0100)
When building namespace for a domain there are couple of devices
that are created independent of domain config (see
qemuDomainPopulateDevices()). The idea behind is that these
devices are crucial for QEMU or one of its libraries, or user is
passing through a device and wants us to create it in the
namespace too.  That's the reason that these devices are allowed
in the devices CGroup controller as well.

However, during unplug it may happen that a device is configured
to use one of such devices and since we remove /dev nodes on
hotplug we would remove such device too. For example,
/dev/urandom belongs onto the list of implicit devices and users
can hotplug and hotunplug an RNG device with /dev/urandom as
backend.

The fix is fortunately simple - just consult the list of implicit
devices before removing the device from the namespace.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_namespace.c

index 3b41d726304ebc96268de1c0427b46fe67b5ed66..9528112338e9fe130f9b06c27875dc2e2d2c83bc 100644 (file)
@@ -1364,6 +1364,7 @@ qemuNamespaceUnlinkPaths(virDomainObj *vm,
         if (STRPREFIX(path, QEMU_DEVPREFIX)) {
             GStrv mount;
             bool inSubmount = false;
+            const char *const *devices = (const char *const *)cfg->cgroupDeviceACL;
 
             for (mount = devMountsPath; *mount; mount++) {
                 if (STREQ(*mount, "/dev"))
@@ -1375,8 +1376,16 @@ qemuNamespaceUnlinkPaths(virDomainObj *vm,
                 }
             }
 
-            if (!inSubmount)
-                unlinkPaths = g_slist_prepend(unlinkPaths, g_strdup(path));
+            if (inSubmount)
+                continue;
+
+            if (!devices)
+                devices = defaultDeviceACL;
+
+            if (g_strv_contains(devices, path))
+                continue;
+
+            unlinkPaths = g_slist_prepend(unlinkPaths, g_strdup(path));
         }
     }