Skip to content

Commit 4c59d57

Browse files
authored
Merge pull request #5 from projectatomic/fix_selinux_mqueue
Delay unshare of CLONE_NEWIPC for SELinux
2 parents 2f7393a + 67120ef commit 4c59d57

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,12 @@ void nsexec(void)
639639
* some old kernel versions where clone(CLONE_PARENT | CLONE_NEWPID)
640640
* was broken, so we'll just do it the long way anyway.
641641
*/
642-
if (unshare(config.cloneflags) < 0)
642+
uint32_t apply_cloneflags = config.cloneflags;
643+
if ((config.cloneflags & CLONE_NEWUSER) && (config.cloneflags & CLONE_NEWIPC)) {
644+
apply_cloneflags &= ~CLONE_NEWIPC;
645+
}
646+
647+
if (unshare(apply_cloneflags) < 0)
643648
bail("failed to unshare namespaces");
644649

645650
/*
@@ -735,6 +740,11 @@ void nsexec(void)
735740
if (setgroups(0, NULL) < 0)
736741
bail("setgroups failed");
737742

743+
if ((config.cloneflags & CLONE_NEWUSER) && (config.cloneflags & CLONE_NEWIPC)) {
744+
if (unshare(CLONE_NEWIPC) < 0)
745+
bail("unshare ipc failed");
746+
}
747+
738748
if (consolefd != -1) {
739749
if (ioctl(consolefd, TIOCSCTTY, 0) < 0)
740750
bail("ioctl TIOCSCTTY failed");

0 commit comments

Comments
 (0)