提交 e30dbf35 编写于 作者: M Michal Privoznik

qemuDomainCreateDeviceRecursive: Don't try to create devices under preserved mount points

While the code allows devices to already be there (by some
miracle), we shouldn't try to create devices that don't belong to
us. For instance, we shouldn't try to create /dev/shm/file
because /dev/shm is a mount point that is preserved. Therefore if
a file is created there from an outside (e.g. by mgmt application
or some other daemon running on the system like vhostmd), it
exists in the qemu namespace too as the mount point is the same.
It's only /dev and /dev only that is different. The same
reasoning applies to all other preserved mount points.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NCedric Bosdonnat <cbosdonnat@suse.com>
上级 26c14be8
...@@ -7418,6 +7418,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg, ...@@ -7418,6 +7418,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
struct qemuDomainCreateDeviceData { struct qemuDomainCreateDeviceData {
const char *path; /* Path to temp new /dev location */ const char *path; /* Path to temp new /dev location */
char * const *devMountsPath;
size_t ndevMountsPath;
}; };
...@@ -7471,17 +7473,34 @@ qemuDomainCreateDeviceRecursive(const char *device, ...@@ -7471,17 +7473,34 @@ qemuDomainCreateDeviceRecursive(const char *device,
* For now, lets hope callers play nice. * For now, lets hope callers play nice.
*/ */
if (STRPREFIX(device, DEVPREFIX)) { if (STRPREFIX(device, DEVPREFIX)) {
if (virAsprintf(&devicePath, "%s/%s", size_t i;
data->path, device + strlen(DEVPREFIX)) < 0)
goto cleanup;
if (virFileMakeParentPath(devicePath) < 0) { for (i = 0; i < data->ndevMountsPath; i++) {
virReportSystemError(errno, if (STREQ(data->devMountsPath[i], "/dev"))
_("Unable to create %s"), continue;
devicePath); if (STRPREFIX(device, data->devMountsPath[i]))
goto cleanup; break;
}
if (i == data->ndevMountsPath) {
/* Okay, @device is in /dev but not in any mount point under /dev.
* Create it. */
if (virAsprintf(&devicePath, "%s/%s",
data->path, device + strlen(DEVPREFIX)) < 0)
goto cleanup;
if (virFileMakeParentPath(devicePath) < 0) {
virReportSystemError(errno,
_("Unable to create %s"),
devicePath);
goto cleanup;
}
VIR_DEBUG("Creating dev %s", device);
create = true;
} else {
VIR_DEBUG("Skipping dev %s because of %s mount point",
device, data->devMountsPath[i]);
} }
create = true;
} }
if (isLink) { if (isLink) {
...@@ -8030,6 +8049,8 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, ...@@ -8030,6 +8049,8 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
} }
data.path = devPath; data.path = devPath;
data.devMountsPath = devMountsPath;
data.ndevMountsPath = ndevMountsPath;
if (virProcessSetupPrivateMountNS() < 0) if (virProcessSetupPrivateMountNS() < 0)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册