conf: unstack all mounts atop /dev/console

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2017-05-09 22:21:07 +02:00
parent 74251e49bb
commit a7ba3c7ff8
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -1500,24 +1500,20 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
/* When we are asked to setup a console we remove any previous /* When we are asked to setup a console we remove any previous
* /dev/console bind-mounts. * /dev/console bind-mounts.
*/ */
ret = umount(path); if (file_exists(path)) {
ret = lxc_unstack_mountpoint(path, false);
if (ret < 0) { if (ret < 0) {
if (errno != EINVAL && errno != ENOENT) {
/* EINVAL: path is not a mountpoint
* ENOENT: path does not exist
* anything else means something weird is happening.
*/
ERROR("failed to unmount \"%s\": %s", path, strerror(errno)); ERROR("failed to unmount \"%s\": %s", path, strerror(errno));
return -errno; return -ret;
}
} else { } else {
DEBUG("unmounted console \"%s\"", path); DEBUG("cleared all (%d) mounts from \"%s\"", ret, path);
} }
ret = unlink(path); ret = unlink(path);
if (ret && errno != ENOENT) { if (ret < 0) {
SYSERROR("error unlinking %s", path); SYSERROR("error unlinking %s", path);
return -errno; return -errno;
} }
}
/* For unprivileged containers autodev or automounts will already have /* For unprivileged containers autodev or automounts will already have
* taken care of creating /dev/console. * taken care of creating /dev/console.
@ -1603,8 +1599,11 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
/* In case the user requested a bind-mount for /dev/console and /* In case the user requested a bind-mount for /dev/console and
* requests a ttydir we move the mount to the * requests a ttydir we move the mount to the
* /dev/<ttydir/console. If it is a character device created via * /dev/<ttydir/console.
* mknod() we simply rename it. * Note, we only move the uppermost mount and clear all other
* mounts underneath for safety.
* If it is a character device created via mknod() we simply
* rename it.
*/ */
ret = safe_mount(path, lxcpath, "none", MS_MOVE, NULL, rootfs->mount); ret = safe_mount(path, lxcpath, "none", MS_MOVE, NULL, rootfs->mount);
if (ret < 0) { if (ret < 0) {
@ -1622,19 +1621,24 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
} else { } else {
DEBUG("moved mount \"%s\" to \"%s\"", path, lxcpath); DEBUG("moved mount \"%s\" to \"%s\"", path, lxcpath);
} }
} else {
ret = umount(path); /* Clear all remaining bind-mounts. */
ret = lxc_unstack_mountpoint(path, false);
if (ret < 0) { if (ret < 0) {
if (errno != EINVAL && errno != ENOENT) {
/* EINVAL: path is not a mountpoint
* ENOENT: path does not exist
* anything else means something weird is happening.
*/
ERROR("failed to unmount \"%s\": %s", path, strerror(errno)); ERROR("failed to unmount \"%s\": %s", path, strerror(errno));
return -errno; return -ret;
} else {
DEBUG("cleared all (%d) mounts from \"%s\"", ret, path);
} }
} else { } else {
DEBUG("unmounted console \"%s\"", path); if (file_exists(path)) {
ret = lxc_unstack_mountpoint(path, false);
if (ret < 0) {
ERROR("failed to unmount \"%s\": %s", path, strerror(errno));
return -ret;
} else {
DEBUG("cleared all (%d) mounts from \"%s\"", ret, path);
}
} }
if (safe_mount(console->name, lxcpath, "none", MS_BIND, 0, rootfs->mount) < 0) { if (safe_mount(console->name, lxcpath, "none", MS_BIND, 0, rootfs->mount) < 0) {