vmexec: enter the container's IPC namespace on exec - #851
Merged
Conversation
`ExecCommand.execInNamespaces` entered a hardcoded `CLONE_NEWCGROUP | CLONE_NEWPID | CLONE_NEWUTS | CLONE_NEWNS`, while the init process gets its namespaces from the OCI spec via `RunCommand.setupNamespaces` — which includes `CLONE_NEWIPC` whenever the spec lists an `ipc` namespace. `LinuxContainer` (and `LinuxPod`) always declare one, so the init process runs in a private IPC namespace and every exec'd process stays in the guest's root one. The effect is that an exec cannot see SysV IPC segments or POSIX message queues created by the workload — and anything the exec creates leaks into the guest's root namespace, where it outlives the container. IPC-namespaced sysctls (`kernel.shm*`, `kernel.msg*`, `kernel.sem`, `fs.mqueue.*`) also read back as the guest default, because they resolve against the reading process's IPC namespace. That last one is what fails critest's "should support safe sysctls" and "should support unsafe sysctls", which set such a sysctl and read it back over ExecSync. Add `CLONE_NEWIPC` to the mask. `setns(2)` into a namespace the caller is already in is a no-op, so the mask is now a superset of everything `setupNamespaces` can unshare rather than a set that has to be kept in sync by hand. `CLONE_NEWUSER` stays out deliberately: nothing puts a container in a user namespace today, and entering one carries constraints that deserve their own change. The integration test asserts the general invariant rather than the specific sysctl: inside an exec, `/proc/self/ns/*` must equal `/proc/1/ns/*` for `ipc`, `uts`, `mnt`, `pid`, `cgroup`, and `net`. `kernel.shm_rmid_forced` is checked alongside it as the consumer-visible symptom. Signed-off-by: michael_crosby <michael_crosby@apple.com>
adityaramani
approved these changes
Aug 27, 2026
This was referenced Aug 28, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExecCommand.execInNamespacesentered a hardcodedCLONE_NEWCGROUP | CLONE_NEWPID | CLONE_NEWUTS | CLONE_NEWNS, while the init process gets its namespaces from the OCI spec viaRunCommand.setupNamespaces— which includesCLONE_NEWIPCwhenever the spec lists anipcnamespace.LinuxContainer(andLinuxPod) always declare one, so the init process runs in a private IPC namespace and every exec'd process stays in the guest's root one.The effect is that an exec cannot see SysV IPC segments or POSIX message queues created by the workload — and anything the exec creates leaks into the guest's root namespace, where it outlives the container. IPC-namespaced sysctls (
kernel.shm*,kernel.msg*,kernel.sem,fs.mqueue.*) also read back as the guest default, because they resolve against the reading process's IPC namespace. That last one is what fails critest's "should support safe sysctls" and "should support unsafe sysctls", which set such a sysctl and read it back over ExecSync.Add
CLONE_NEWIPCto the mask.setns(2)into a namespace the caller is already in is a no-op, so the mask is now a superset of everythingsetupNamespacescan unshare rather than a set that has to be kept in sync by hand.CLONE_NEWUSERstays out deliberately: nothing puts a container in a user namespace today, and entering one carries constraints that deserve their own change.The integration test asserts the general invariant rather than the specific sysctl: inside an exec,
/proc/self/ns/*must equal/proc/1/ns/*foripc,uts,mnt,pid,cgroup, andnet.kernel.shm_rmid_forcedis checked alongside it as the consumer-visible symptom.