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