|
|
c401cc |
From 9450ad80b814fe0ca823696bff468046340d43c8 Mon Sep 17 00:00:00 2001
|
|
|
c401cc |
Message-Id: <9450ad80b814fe0ca823696bff468046340d43c8@dist-git>
|
|
|
c401cc |
From: "Daniel P. Berrange" <berrange@redhat.com>
|
|
|
c401cc |
Date: Tue, 18 Feb 2014 15:45:43 -0700
|
|
|
c401cc |
Subject: [PATCH] CVE-2013-6456: Avoid unsafe use of /proc/$PID/root in LXC
|
|
|
c401cc |
chardev hostdev hotplug
|
|
|
c401cc |
|
|
|
c401cc |
Rewrite lxcDomainAttachDeviceHostdevMiscLive function
|
|
|
c401cc |
to use the virProcessRunInMountNamespace helper. This avoids
|
|
|
c401cc |
risk of a malicious guest replacing /dev with a absolute
|
|
|
c401cc |
symlink, tricking the driver into changing the host OS
|
|
|
c401cc |
filesystem.
|
|
|
c401cc |
|
|
|
c401cc |
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
|
|
|
c401cc |
(cherry picked from commit 1cadeafcaa422844a27ef622e2a7041d0235bcb3)
|
|
|
c401cc |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c401cc |
---
|
|
|
c401cc |
src/lxc/lxc_driver.c | 66 ++++++++++++++--------------------------------------
|
|
|
c401cc |
1 file changed, 18 insertions(+), 48 deletions(-)
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
|
|
|
c401cc |
index 3920ad9..91e491c 100644
|
|
|
c401cc |
--- a/src/lxc/lxc_driver.c
|
|
|
c401cc |
+++ b/src/lxc/lxc_driver.c
|
|
|
c401cc |
@@ -3567,11 +3567,7 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
|
|
|
c401cc |
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
|
|
c401cc |
virDomainHostdevDefPtr def = dev->data.hostdev;
|
|
|
c401cc |
int ret = -1;
|
|
|
c401cc |
- char *dst = NULL;
|
|
|
c401cc |
- char *vroot = NULL;
|
|
|
c401cc |
struct stat sb;
|
|
|
c401cc |
- bool created = false;
|
|
|
c401cc |
- mode_t mode = 0;
|
|
|
c401cc |
|
|
|
c401cc |
if (!def->source.caps.u.misc.chardev) {
|
|
|
c401cc |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
c401cc |
@@ -3599,51 +3595,29 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
- if (virAsprintf(&vroot, "/proc/%llu/root",
|
|
|
c401cc |
- (unsigned long long)priv->initpid) < 0)
|
|
|
c401cc |
- goto cleanup;
|
|
|
c401cc |
-
|
|
|
c401cc |
- if (virAsprintf(&dst, "%s/%s",
|
|
|
c401cc |
- vroot,
|
|
|
c401cc |
- def->source.caps.u.misc.chardev) < 0)
|
|
|
c401cc |
+ if (virCgroupAllowDevice(priv->cgroup,
|
|
|
c401cc |
+ 'c',
|
|
|
c401cc |
+ major(sb.st_rdev),
|
|
|
c401cc |
+ minor(sb.st_rdev),
|
|
|
c401cc |
+ VIR_CGROUP_DEVICE_RWM) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
- if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) {
|
|
|
c401cc |
- virReportSystemError(errno,
|
|
|
c401cc |
- _("Unable to create directory for device %s"),
|
|
|
c401cc |
- dst);
|
|
|
c401cc |
- goto cleanup;
|
|
|
c401cc |
- }
|
|
|
c401cc |
-
|
|
|
c401cc |
- mode = 0700 | S_IFCHR;
|
|
|
c401cc |
-
|
|
|
c401cc |
- VIR_DEBUG("Creating dev %s (%d,%d)",
|
|
|
c401cc |
- def->source.caps.u.misc.chardev,
|
|
|
c401cc |
- major(sb.st_rdev), minor(sb.st_rdev));
|
|
|
c401cc |
- if (mknod(dst, mode, sb.st_rdev) < 0) {
|
|
|
c401cc |
- virReportSystemError(errno,
|
|
|
c401cc |
- _("Unable to create device %s"),
|
|
|
c401cc |
- dst);
|
|
|
c401cc |
- goto cleanup;
|
|
|
c401cc |
- }
|
|
|
c401cc |
- created = true;
|
|
|
c401cc |
-
|
|
|
c401cc |
- if (lxcContainerChown(vm->def, dst) < 0)
|
|
|
c401cc |
- goto cleanup;
|
|
|
c401cc |
-
|
|
|
c401cc |
- if (virSecurityManagerSetHostdevLabel(driver->securityManager,
|
|
|
c401cc |
- vm->def, def, vroot) < 0)
|
|
|
c401cc |
- goto cleanup;
|
|
|
c401cc |
-
|
|
|
c401cc |
- if (virCgroupAllowDevicePath(priv->cgroup, def->source.caps.u.misc.chardev,
|
|
|
c401cc |
- VIR_CGROUP_DEVICE_RW |
|
|
|
c401cc |
- VIR_CGROUP_DEVICE_MKNOD) != 0) {
|
|
|
c401cc |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
c401cc |
- _("cannot allow device %s for domain %s"),
|
|
|
c401cc |
- def->source.caps.u.misc.chardev, vm->def->name);
|
|
|
c401cc |
+ if (lxcDomainAttachDeviceMknod(driver,
|
|
|
c401cc |
+ 0700 | S_IFBLK,
|
|
|
c401cc |
+ sb.st_rdev,
|
|
|
c401cc |
+ vm,
|
|
|
c401cc |
+ dev,
|
|
|
c401cc |
+ def->source.caps.u.misc.chardev) < 0) {
|
|
|
c401cc |
+ if (virCgroupDenyDevice(priv->cgroup,
|
|
|
c401cc |
+ 'c',
|
|
|
c401cc |
+ major(sb.st_rdev),
|
|
|
c401cc |
+ minor(sb.st_rdev),
|
|
|
c401cc |
+ VIR_CGROUP_DEVICE_RWM) < 0)
|
|
|
c401cc |
+ VIR_WARN("cannot deny device %s for domain %s",
|
|
|
c401cc |
+ def->source.caps.u.storage.block, vm->def->name);
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
@@ -3653,10 +3627,6 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
|
|
|
c401cc |
|
|
|
c401cc |
cleanup:
|
|
|
c401cc |
virDomainAuditHostdev(vm, def, "attach", ret == 0);
|
|
|
c401cc |
- if (dst && created && ret < 0)
|
|
|
c401cc |
- unlink(dst);
|
|
|
c401cc |
- VIR_FREE(dst);
|
|
|
c401cc |
- VIR_FREE(vroot);
|
|
|
c401cc |
return ret;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
--
|
|
|
c401cc |
1.9.0
|
|
|
c401cc |
|