提交 21241428 编写于 作者: D Daniel P. Berrange

CVE-2013-6456: Avoid unsafe use of /proc/$PID/root in LXC block hostdev hotplug

Rewrite lxcDomainAttachDeviceHostdevStorageLive function
to use the virProcessRunInMountNamespace helper. This avoids
risk of a malicious guest replacing /dev with a absolute
symlink, tricking the driver into changing the host OS
filesystem.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 1754c7f0)

Conflicts:
	src/lxc/lxc_driver.c: OOM + cgroups error reporting
上级 c17dd7ed
...@@ -3706,11 +3706,7 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver, ...@@ -3706,11 +3706,7 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
virLXCDomainObjPrivatePtr priv = vm->privateData; virLXCDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevDefPtr def = dev->data.hostdev; virDomainHostdevDefPtr def = dev->data.hostdev;
int ret = -1; int ret = -1;
char *dst = NULL;
char *vroot = NULL;
struct stat sb; struct stat sb;
bool created = false;
mode_t mode = 0;
if (!def->source.caps.u.storage.block) { if (!def->source.caps.u.storage.block) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
...@@ -3738,54 +3734,35 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver, ...@@ -3738,54 +3734,35 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
goto cleanup; goto cleanup;
} }
if (virAsprintf(&vroot, "/proc/%llu/root",
(unsigned long long)priv->initpid) < 0) {
virReportOOMError();
goto cleanup;
}
if (virAsprintf(&dst, "%s/%s",
vroot,
def->source.caps.u.storage.block) < 0) {
virReportOOMError();
goto cleanup;
}
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) { if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
if (lxcContainerSetupHostdevCapsMakePath(dst) < 0) { if (virCgroupAllowDevice(priv->cgroup,
virReportSystemError(errno, 'b',
_("Unable to create directory for device %s"), major(sb.st_rdev),
dst); minor(sb.st_rdev),
goto cleanup; VIR_CGROUP_DEVICE_RWM) < 0) {
} virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to allow device %s"),
mode = 0700 | S_IFBLK; def->source.caps.u.storage.block);
VIR_DEBUG("Creating dev %s (%d,%d)",
def->source.caps.u.storage.block,
major(sb.st_rdev), minor(sb.st_rdev));
if (mknod(dst, mode, sb.st_rdev) < 0) {
virReportSystemError(errno,
_("Unable to create device %s"),
dst);
goto cleanup; goto cleanup;
} }
created = true;
if (virSecurityManagerSetHostdevLabel(driver->securityManager, if (lxcDomainAttachDeviceMknod(driver,
vm->def, def, vroot) < 0) 0700 | S_IFBLK,
goto cleanup; sb.st_rdev,
vm,
if (virCgroupAllowDevicePath(priv->cgroup, def->source.caps.u.storage.block, dev,
VIR_CGROUP_DEVICE_RW | def->source.caps.u.storage.block) < 0) {
VIR_CGROUP_DEVICE_MKNOD) != 0) { if (virCgroupDenyDevice(priv->cgroup,
virReportError(VIR_ERR_INTERNAL_ERROR, 'b',
_("cannot allow device %s for domain %s"), major(sb.st_rdev),
def->source.caps.u.storage.block, vm->def->name); minor(sb.st_rdev),
VIR_CGROUP_DEVICE_RWM) < 0)
VIR_WARN("cannot deny device %s for domain %s",
def->source.caps.u.storage.block, vm->def->name);
goto cleanup; goto cleanup;
} }
...@@ -3795,10 +3772,6 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver, ...@@ -3795,10 +3772,6 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
cleanup: cleanup:
virDomainAuditHostdev(vm, def, "attach", ret == 0); virDomainAuditHostdev(vm, def, "attach", ret == 0);
if (dst && created && ret < 0)
unlink(dst);
VIR_FREE(dst);
VIR_FREE(vroot);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册