Skip to content

fix: fallback to Landlock-only when user namespaces unavailable and set PR_SET_NO_NEW_PRIVS early#9250

Merged
bolinfest merged 4 commits intomainfrom
codex/viyatb/fix-sandbox-landlock-failure-on-writable-root
Jan 15, 2026
Merged

fix: fallback to Landlock-only when user namespaces unavailable and set PR_SET_NO_NEW_PRIVS early#9250
bolinfest merged 4 commits intomainfrom
codex/viyatb/fix-sandbox-landlock-failure-on-writable-root

Conversation

@viyatb-oai
Copy link
Collaborator

@viyatb-oai viyatb-oai commented Jan 15, 2026

fixes #9236

Motivation

  • Prevent sandbox setup from failing when unprivileged user namespaces are denied so Landlock-only protections can still be applied.
  • Ensure PR_SET_NO_NEW_PRIVS is set before installing seccomp and Landlock restrictions to avoid kernel EPERM/LandlockRestrict ordering issues.

Description

  • Add is_permission_denied helper that detects EPERM / PermissionDenied from CodexErr to drive fallback logic.
  • In apply_read_only_mounts skip read-only bind-mount setup and return Ok(()) when unshare_user_and_mount_namespaces() fails with permission-denied so Landlock rules can still be installed.
  • Add set_no_new_privs() and call it from apply_sandbox_policy_to_current_thread before installing seccomp filters and Landlock rules when disk or network access is restricted.

@viyatb-oai viyatb-oai changed the title Fallback to Landlock-only when user namespaces unavailable; set PR_SET_NO_NEW_PRIVS early fix: fallback to Landlock-only when user namespaces unavailable and set PR_SET_NO_NEW_PRIVS early Jan 15, 2026
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b358805d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 30 to 34
if let Err(err) = unshare_user_and_mount_namespaces() {
if is_permission_denied(&err) {
// Unprivileged user namespaces can be disabled on some systems; fall back
// to Landlock-only protections when we cannot set up the mount namespace.
return Ok(());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve read-only subpath protections on userns EPERM

When unprivileged user namespaces are disabled (unshare returns EPERM), this early return skips the read‑only bind mounts but the caller still proceeds to install Landlock with writable roots. Because Landlock is an allowlist, read_only_subpaths (e.g., .git/.codex under a writable root) become writable in that environment, which violates the sandbox policy and allows mutation of protected metadata (including git hooks) instead of blocking it. If fallback is needed, consider failing sandbox setup or removing writable roots/read‑only expectations when mount isolation cannot be established.

Useful? React with 👍 / 👎.

@viyatb-oai viyatb-oai requested a review from bolinfest January 15, 2026 02:26
@bolinfest bolinfest merged commit 2259031 into main Jan 15, 2026
32 checks passed
@bolinfest bolinfest deleted the codex/viyatb/fix-sandbox-landlock-failure-on-writable-root branch January 15, 2026 06:24
@github-actions github-actions bot locked and limited conversation to collaborators Jan 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not able to read/write in directories where the config.toml has configured that directory as a writable root

2 participants