Skip to content

Commit e3cd191

Browse files
committed
nsenter: un-split clone(cloneflags) for RHEL
Without this patch applied, RHEL's SELinux policies cause container creation to not really work. Unfortunately this might be an issue for rootless containers (#774) but we'll cross that bridge when we come to it. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 2cd9c31 commit e3cd191

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,25 @@ void nsexec(void)
621621
if (config.namespaces)
622622
join_namespaces(config.namespaces);
623623

624+
/*
625+
* Unshare all of the namespaces. Now, it should be noted that this
626+
* ordering might break in the future (especially with rootless
627+
* containers). But for now, it's not possible to split this into
628+
* CLONE_NEWUSER + [the rest] because of some RHEL SELinux issues.
629+
*
630+
* We also can't be sure if the current kernel supports
631+
* clone(CLONE_PARENT | CLONE_NEWPID), so we'll just do it the long
632+
* way anyway.
633+
*/
634+
if (unshare(config.cloneflags) < 0)
635+
bail("failed to unshare namespaces");
636+
624637
/*
625638
* Deal with user namespaces first. They are quite special, as they
626639
* affect our ability to unshare other namespaces and are used as
627640
* context for privilege checks.
628641
*/
629642
if (config.cloneflags & CLONE_NEWUSER) {
630-
/* Create a new user namespace. */
631-
if (unshare(CLONE_NEWUSER) < 0)
632-
bail("failed to unshare user namespace");
633-
634643
/*
635644
* We don't have the privileges to do any mapping here (see the
636645
* clone_parent rant). So signal our parent to hook us up.
@@ -646,18 +655,8 @@ void nsexec(void)
646655
bail("failed to sync with parent: read(SYNC_USERMAP_ACK)");
647656
if (s != SYNC_USERMAP_ACK)
648657
bail("failed to sync with parent: SYNC_USERMAP_ACK: got %u", s);
649-
650-
config.cloneflags &= ~CLONE_NEWUSER;
651658
}
652659

653-
/*
654-
* Now we can unshare the rest of the namespaces. We can't be sure if the
655-
* current kernel supports clone(CLONE_PARENT | CLONE_NEWPID), so we'll
656-
* just do it the long way anyway.
657-
*/
658-
if (unshare(config.cloneflags) < 0)
659-
bail("failed to unshare namespaces");
660-
661660
/* TODO: What about non-namespace clone flags that we're dropping here? */
662661
child = clone_parent(&env, JUMP_INIT);
663662
if (child < 0)

0 commit comments

Comments
 (0)