mirror of https://gitee.com/openkylin/libvirt.git
Don't mount /dev for application containers
An application container shouldn't get a private /dev. Fix
the regression from 6d37888e6a
* src/lxc/lxc_container.c: Don't mount /dev for app containers
This commit is contained in:
parent
63e4af45f2
commit
b6bd2d3466
|
@ -402,9 +402,10 @@ err:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int lxcContainerMountBasicFS(const char *srcprefix)
|
static int lxcContainerMountBasicFS(const char *srcprefix, bool pivotRoot)
|
||||||
{
|
{
|
||||||
const struct {
|
const struct {
|
||||||
|
bool onlyPivotRoot;
|
||||||
bool needPrefix;
|
bool needPrefix;
|
||||||
const char *src;
|
const char *src;
|
||||||
const char *dst;
|
const char *dst;
|
||||||
|
@ -415,23 +416,31 @@ static int lxcContainerMountBasicFS(const char *srcprefix)
|
||||||
/* When we want to make a bind mount readonly, for unknown reasons,
|
/* When we want to make a bind mount readonly, for unknown reasons,
|
||||||
* it is currently neccessary to bind it once, and then remount the
|
* it is currently neccessary to bind it once, and then remount the
|
||||||
* bind with the readonly flag. If this is not done, then the original
|
* bind with the readonly flag. If this is not done, then the original
|
||||||
* mount point in the main OS becomes readonly too which si not what
|
* mount point in the main OS becomes readonly too which is not what
|
||||||
* we want. Hence some things have two entries here.
|
* we want. Hence some things have two entries here.
|
||||||
*/
|
*/
|
||||||
{ false, "devfs", "/dev", "tmpfs", "mode=755", MS_NOSUID },
|
{ true, false, "devfs", "/dev", "tmpfs", "mode=755", MS_NOSUID },
|
||||||
{ false, "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
|
{ false, false, "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
|
||||||
{ false, "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND },
|
{ false, false, "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND },
|
||||||
{ false, "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
|
{ false, false, "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
|
||||||
{ true, "/sys", "/sys", NULL, NULL, MS_BIND },
|
{ false, true, "/sys", "/sys", NULL, NULL, MS_BIND },
|
||||||
{ true, "/sys", "/sys", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
|
{ false, true, "/sys", "/sys", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
|
||||||
{ true, "/selinux", "/selinux", NULL, NULL, MS_BIND },
|
{ false, true, "/selinux", "/selinux", NULL, NULL, MS_BIND },
|
||||||
{ true, "/selinux", "/selinux", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
|
{ false, true, "/selinux", "/selinux", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
|
||||||
};
|
};
|
||||||
int i, rc = -1;
|
int i, rc = -1;
|
||||||
|
|
||||||
|
VIR_DEBUG("Mounting basic filesystems %s pivotRoot=%d", NULLSTR(srcprefix), pivotRoot);
|
||||||
|
|
||||||
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
|
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
|
||||||
char *src = NULL;
|
char *src = NULL;
|
||||||
const char *srcpath = NULL;
|
const char *srcpath = NULL;
|
||||||
|
|
||||||
|
VIR_DEBUG("Consider %s onlyPivotRoot=%d",
|
||||||
|
mnts[i].src, mnts[i].onlyPivotRoot);
|
||||||
|
if (mnts[i].onlyPivotRoot && !pivotRoot)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (virFileMakePath(mnts[i].dst) < 0) {
|
if (virFileMakePath(mnts[i].dst) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mkdir %s"),
|
_("Failed to mkdir %s"),
|
||||||
|
@ -454,6 +463,8 @@ static int lxcContainerMountBasicFS(const char *srcprefix)
|
||||||
(access(srcpath, R_OK) < 0))
|
(access(srcpath, R_OK) < 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
VIR_DEBUG("Mount %s on %s type=%s flags=%x, opts=%s",
|
||||||
|
srcpath, mnts[i].dst, mnts[i].type, mnts[i].mflags, mnts[i].opts);
|
||||||
if (mount(srcpath, mnts[i].dst, mnts[i].type, mnts[i].mflags, mnts[i].opts) < 0) {
|
if (mount(srcpath, mnts[i].dst, mnts[i].type, mnts[i].mflags, mnts[i].opts) < 0) {
|
||||||
VIR_FREE(src);
|
VIR_FREE(src);
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
|
@ -716,7 +727,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Mounts the core /proc, /sys, etc filesystems */
|
/* Mounts the core /proc, /sys, etc filesystems */
|
||||||
if (lxcContainerMountBasicFS("/.oldroot") < 0)
|
if (lxcContainerMountBasicFS("/.oldroot", true) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Mounts /dev and /dev/pts */
|
/* Mounts /dev and /dev/pts */
|
||||||
|
@ -760,8 +771,7 @@ static int lxcContainerSetupExtraMounts(virDomainDefPtr vmDef)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Mounts the core /proc, /sys, etc filesystems */
|
/* Mounts the core /proc, /sys, etc filesystems */
|
||||||
VIR_DEBUG("Mounting basic FS");
|
if (lxcContainerMountBasicFS(NULL, false) < 0)
|
||||||
if (lxcContainerMountBasicFS(NULL) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
VIR_DEBUG("Mounting completed");
|
VIR_DEBUG("Mounting completed");
|
||||||
|
|
Loading…
Reference in New Issue