fix(sandbox): fail closed when namespace isolation cannot be applied - #76
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(sandbox): fail closed when namespace isolation cannot be applied#76cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Unprivileged unshare of mount/net/pid namespaces returns EPERM and the return value was ignored, so sandbox.enabled still ran commands on the host network. Enter a user namespace first, then unshare; exit if isolation still cannot be established. Co-authored-by: esadrianno <esadrianno@gmail.com>
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.
Bug and impact
With
sandbox.enabled = true(the documentedconfig.example.tomldefault), ShellClaw claimed Linux mount/network/PID namespace isolation for the shell tool. On a typical non-root install,unshare(CLONE_NEWNS | CLONE_NEWNET | CLONE_NEWPID)returnsEPERMand the return value was ignored. The child thenexecl("/bin/sh", ...)on the host network.Trigger: copy the example config, run as a normal user, and have the agent execute a command with no path tokens (allowlist phase-2 skips URLs), for example
curl http://169.254.169.254/or a connect to a host loopback service. The command succeeds even though the operator enabled the sandbox.This is distinct from open PRs #66/#68/#74 (path/symlink/Landlock filesystem escapes).
Root cause
setup_child_processinsrc/sandbox/sandbox.ccalledunshare(...)without checking the result and never entered a user namespace, which unprivileged processes need before they can unshare net/mount/pid.Fix
unshare(CLONE_NEWUSER), writesetgroups/uid_map/gid_map, then unshare net/mount/pid._exit(123)andsandbox_execreturns-1(fail-closed) instead of running on the host netns.Validation
CI=true make test_sandbox(-Werror)test_network_namespace_blocks_host_loopback(host loopback listener must not be reachable from insidesandbox_exec)