Skip to content

bug: workload pre_exec hooks compile the seccomp filter and log after fork #5180

Open

Description

@EmilienM

User Story

I run OpenShell sandboxes with the Podman and Kubernetes drivers, and I read through the isolation core (openshell-sandbox, openshell-binary-identity, openshell-isolation-interface) at 00528d24a. This item comes from reading the code. I have not hit it in production. It is one line of the umbrella issue #5179.

Problem Statement

The workload pre_exec hooks run in the forked child of a multithreaded process. They call enforce_capability_free, which calls seccomp::apply (crates/openshell-sandbox/src/sandbox/linux/seccomp.rs:75). That builds both the main and the compatibility filter inside the child: BTreeMap allocations, seccompiler compilation, and a debug! callsite at seccomp.rs:198. On a best-effort Landlock failure, landlock::enforce (sandbox/linux/landlock.rs:419) also emits an OCSF event from the child.

The // SAFETY: comments say otherwise: pty.rs:70 and pty.rs:104 claim "all allocations and policy compilation happened before spawn", and process.rs:629 says the hook only calls setpgid and setns.

ChildHardeningProgram already prebuilds the child self-protection filter in the parent. The main and compatibility filters are not prebuilt.

Impact / Why This Matters

If another thread holds the allocator, a tracing or subscriber mutex, or the OCSF writer lock at the moment of fork, the child can block before exec. Debug logging also writes "Restricting socket domains via seccomp" to the child's stdout, which is already the workload's pipe or PTY. The comments mislead reviewers of the fork path.

Acceptance Criteria

  • Both seccomp filters are compiled into BpfPrograms in the parent (for example inside PreparedSandbox) and the child only installs them.
  • No allocation, tracing call, or OCSF emission runs between fork and exec in process.rs, pty.rs, and landlock::enforce (report the best-effort Landlock failure from the parent or after exec).
  • The three // SAFETY: comments describe what the hooks actually do.
  • A test or check covers the post-fork path, for example a unit test asserting the hook performs only prebuilt operations.

Reproduction Steps

Found by reading the code; not reproduced live. Run a sandbox with debug logging enabled and watch the workload's stdout for Restricting socket domains via seccomp, which comes from the forked child. The hang itself needs a lock held across fork and is not expected to be reproducible on demand.

Environment

  • OpenShell: main at 00528d24a
  • OS: Fedora 44, Linux 7.2.14
  • Deployment: Podman driver (local gateway); code read for the Kubernetes driver too

Activity

  1. added
    state:triage-needed
    on Nov 3, 2026
  2. added
    state:accepted
    on Nov 3, 2026
  3. mrunalp commented on Nov 3, 2026

    @mrunalp
    Contributor

    Accepted for implementation in #5216.

    Source inspection at 32dcc4a67: Seccomp apply builds both filters at installation time and includes tracing, while the child-side Landlock enforcement path can emit OCSF. Preparing filters before fork and reporting degradation from the parent addresses the reported post-fork allocation/logging hazards.

    This assessment is based on the source and the linked report/PR; I have not independently run deployment reproductions or the PR test suite. CI and code review still need to validate the fix.

  4. removed
    state:triage-needed
    on Nov 3, 2026
  5. added 5 commits that reference this issue on Nov 4, 2026
    f9e08dd
    0d0372a
    fea6cbb
    f1fe202
    f3c078f
  6. added
    area:runtime
    topic:reliability
    topic:security
    on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:runtimestate:acceptedtopic:reliabilitytopic:security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions