Skip to content

Commit c78f3f2

Browse files
lifubangfuweidkolyshkincyphar
committed
libct/nsenter: become root after joining userns
Containerd pre-creates userns and netns before calling runc, which results in the current code not working when SELinux is enabled, resulting in the following error: > runc create failed: unable to start container process: error during container init: error mounting "mqueue" to rootfs at "/dev/mqueue": setxattr /path/to/rootfs/dev/mqueue: operation not permitted The solution is to become root in the user namespace right after we join it. Fixes #4466. Co-authored-by: Wei Fu <[email protected]> Co-authored-by: Kir Kolyshkin <[email protected]> Co-authored-by: Aleksa Sarai <[email protected]> Signed-off-by: lifubang <[email protected]>
1 parent e37371e commit c78f3f2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@ void join_namespaces(char *nslist)
505505
if (setns(ns->fd, flag) < 0)
506506
bail("failed to setns into %s namespace", ns->type);
507507

508+
/*
509+
* If we change user namespaces, make sure we switch to root in the
510+
* namespace (this matches the logic for unshare(CLONE_NEWUSER)), lots
511+
* of things can break if we aren't the right user. See
512+
* <https://github.com/opencontainers/runc/issues/4466> for one example.
513+
*/
514+
if (flag == CLONE_NEWUSER) {
515+
if (setresuid(0, 0, 0) < 0)
516+
bail("failed to become root in user namespace");
517+
}
518+
508519
close(ns->fd);
509520
}
510521

0 commit comments

Comments
 (0)