Blame SOURCES/libvirt-qemuDomainCreateDeviceRecursive-Don-t-try-to-create-devices-under-preserved-mount-points.patch

6d3351
From 09f7d1ef473ec3e1f21c62abff77d55d79817704 Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <09f7d1ef473ec3e1f21c62abff77d55d79817704@dist-git>
6d3351
From: Michal Privoznik <mprivozn@redhat.com>
6d3351
Date: Thu, 11 May 2017 15:38:39 +0200
6d3351
Subject: [PATCH] qemuDomainCreateDeviceRecursive: Don't try to create devices
6d3351
 under preserved mount points
6d3351
6d3351
https://bugzilla.redhat.com/show_bug.cgi?id=1449510
6d3351
6d3351
While the code allows devices to already be there (by some
6d3351
miracle), we shouldn't try to create devices that don't belong to
6d3351
us. For instance, we shouldn't try to create /dev/shm/file
6d3351
because /dev/shm is a mount point that is preserved. Therefore if
6d3351
a file is created there from an outside (e.g. by mgmt application
6d3351
or some other daemon running on the system like vhostmd), it
6d3351
exists in the qemu namespace too as the mount point is the same.
6d3351
It's only /dev and /dev only that is different. The same
6d3351
reasoning applies to all other preserved mount points.
6d3351
6d3351
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6d3351
Reviewed-by: Cedric Bosdonnat <cbosdonnat@suse.com>
6d3351
(cherry picked from commit e30dbf35a1a9e86934272aeef803f91b36d8cbce)
6d3351
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 src/qemu/qemu_domain.c | 39 ++++++++++++++++++++++++++++++---------
6d3351
 1 file changed, 30 insertions(+), 9 deletions(-)
6d3351
6d3351
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
6d3351
index bbf865e12..9217747d5 100644
6d3351
--- a/src/qemu/qemu_domain.c
6d3351
+++ b/src/qemu/qemu_domain.c
6d3351
@@ -7415,6 +7415,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
6d3351
 
6d3351
 struct qemuDomainCreateDeviceData {
6d3351
     const char *path;     /* Path to temp new /dev location */
6d3351
+    char * const *devMountsPath;
6d3351
+    size_t ndevMountsPath;
6d3351
 };
6d3351
 
6d3351
 
6d3351
@@ -7468,17 +7470,34 @@ qemuDomainCreateDeviceRecursive(const char *device,
6d3351
      * For now, lets hope callers play nice.
6d3351
      */
6d3351
     if (STRPREFIX(device, DEVPREFIX)) {
6d3351
-        if (virAsprintf(&devicePath, "%s/%s",
6d3351
-                        data->path, device + strlen(DEVPREFIX)) < 0)
6d3351
-            goto cleanup;
6d3351
+        size_t i;
6d3351
 
6d3351
-        if (virFileMakeParentPath(devicePath) < 0) {
6d3351
-            virReportSystemError(errno,
6d3351
-                                 _("Unable to create %s"),
6d3351
-                                 devicePath);
6d3351
-            goto cleanup;
6d3351
+        for (i = 0; i < data->ndevMountsPath; i++) {
6d3351
+            if (STREQ(data->devMountsPath[i], "/dev"))
6d3351
+                continue;
6d3351
+            if (STRPREFIX(device, data->devMountsPath[i]))
6d3351
+                break;
6d3351
+        }
6d3351
+
6d3351
+        if (i == data->ndevMountsPath) {
6d3351
+            /* Okay, @device is in /dev but not in any mount point under /dev.
6d3351
+             * Create it. */
6d3351
+            if (virAsprintf(&devicePath, "%s/%s",
6d3351
+                            data->path, device + strlen(DEVPREFIX)) < 0)
6d3351
+                goto cleanup;
6d3351
+
6d3351
+            if (virFileMakeParentPath(devicePath) < 0) {
6d3351
+                virReportSystemError(errno,
6d3351
+                                     _("Unable to create %s"),
6d3351
+                                     devicePath);
6d3351
+                goto cleanup;
6d3351
+            }
6d3351
+            VIR_DEBUG("Creating dev %s", device);
6d3351
+            create = true;
6d3351
+        } else {
6d3351
+            VIR_DEBUG("Skipping dev %s because of %s mount point",
6d3351
+                      device, data->devMountsPath[i]);
6d3351
         }
6d3351
-        create = true;
6d3351
     }
6d3351
 
6d3351
     if (isLink) {
6d3351
@@ -8027,6 +8046,8 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
6d3351
     }
6d3351
 
6d3351
     data.path = devPath;
6d3351
+    data.devMountsPath = devMountsPath;
6d3351
+    data.ndevMountsPath = ndevMountsPath;
6d3351
 
6d3351
     if (virProcessSetupPrivateMountNS() < 0)
6d3351
         goto cleanup;
6d3351
-- 
6d3351
2.13.0
6d3351