Skip to content

Commit

Permalink
conf: ensure that procfs and sysfs are unmounted
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Mar 9, 2021
1 parent ed41e76 commit 95258e3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lxc/conf.c
Expand Up @@ -613,13 +613,31 @@ static int lxc_mount_auto_mounts(struct lxc_handler *handler, int flags)
bool has_cap_net_admin;

if (flags & LXC_AUTO_PROC_MASK) {
ret = strnprintf(rootfs->buf, sizeof(rootfs->buf), "%s/proc",
rootfs->path ? rootfs->mount : "");
if (ret < 0)
return ret_errno(EIO);

ret = umount2(rootfs->buf, MNT_DETACH);
if (ret)
SYSDEBUG("Tried to ensure procfs is unmounted");

ret = mkdirat(rootfs->dfd_mnt, "proc" , S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (ret < 0 && errno != EEXIST)
return log_error_errno(-errno, errno,
"Failed to create proc mountpoint under %d", rootfs->dfd_mnt);
}

if (flags & LXC_AUTO_SYS_MASK) {
ret = strnprintf(rootfs->buf, sizeof(rootfs->buf), "%s/sys",
rootfs->path ? rootfs->mount : "");
if (ret < 0)
return ret_errno(EIO);

ret = umount2(rootfs->buf, MNT_DETACH);
if (ret)
SYSDEBUG("Tried to ensure sysfs is unmounted");

ret = mkdirat(rootfs->dfd_mnt, "sys" , S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
if (ret < 0 && errno != EEXIST)
return log_error_errno(-errno, errno,
Expand Down

0 comments on commit 95258e3

Please sign in to comment.