Skip to content

[Bug]: With use_namespaces, /proc doesn't match the action's PID namespace #3003

Closed

Description

@mkanat

Problem

With use_namespaces, when an action looks up its own child in /proc/<pid> using the PID it got from fork or subprocess, it reads whichever host process has that number, or nothing.

In my case, a profiler records which Python it's running under by reading /proc/<its own PID>/exe. That path belongs to an unrelated host process, so the read fails with PermissionError and the profiler exits before it starts its target.

Present in v1.7.7, v1.8.0 and main.

Cause

The action runs in a new PID namespace, but /proc is still the host's, which lists processes by their host PIDs.

Workaround

An entrypoint script that runs the action under unshare --user --map-current-user --pid --fork --kill-child --mount-proc, which gives it a matching /proc.

Repro

config.json5 (replace /path/to/data):

{
  stores: [
    {
      name: "CAS",
      fast_slow: {
        fast: {
          filesystem: {
            content_path: "/path/to/data/cas",
            temp_path: "/path/to/data/cas-tmp",
          },
        },
        slow: { noop: {} },
      },
    },
    { name: "AC", memory: {} },
  ],
  schedulers: [{ name: "SCHEDULER", simple: {} }],
  workers: [
    {
      local: {
        worker_api_endpoint: { uri: "grpc://127.0.0.1:50061" },
        cas_fast_slow_store: "CAS",
        upload_action_result: { ac_store: "AC" },
        work_directory: "/path/to/data/work",
        platform_properties: {},
        use_namespaces: true,
      },
    },
  ],
  servers: [
    {
      listener: { http: { socket_address: "127.0.0.1:50051" } },
      services: {
        cas: [{ cas_store: "CAS" }],
        ac: [{ ac_store: "AC" }],
        bytestream: [{ cas_store: "CAS" }],
        execution: [{ cas_store: "CAS", scheduler: "SCHEDULER" }],
        capabilities: [{ remote_execution: { scheduler: "SCHEDULER" } }],
      },
    },
    {
      listener: { http: { socket_address: "127.0.0.1:50061" } },
      services: { worker_api: { scheduler: "SCHEDULER" } },
    },
  ],
}

A Bazel workspace with an empty MODULE.bazel and this BUILD.bazel, which starts sleep 10 and reads its command line from /proc:

genrule(
    name = "proc",
    outs = ["proc.out"],
    cmd = "python3 -c 'import os, sys, time; child = os.fork() or os.execvp(\"sleep\", [\"sleep\", \"10\"]); time.sleep(1); cmdline = open(f\"/proc/{child}/cmdline\", \"rb\").read(); os.kill(child, 9); print(child, cmdline, file=sys.stderr); sys.exit(cmdline != b\"sleep\\0\" b\"10\\0\")' && touch $@",
)
nativelink config.json5 &
bazel build --remote_executor=grpc://127.0.0.1:50051 //:proc

With NativeLink v1.8.0 and Bazel 9.3.0 on Linux 7.2, the action fails. The child is PID 3, and /proc/3 is a host kernel thread:

3 b''

With use_namespaces: false, the same action succeeds and prints <pid> b'sleep\x0010\x00'.

Suggested Solution

The worker could mount a new proc over /proc for the action after joining the PID namespace. The action can't do it itself: it runs as a non-root user in the user namespace and has no capabilities after exec.

Activity

  1. MarcusSorealheis commented on Oct 22, 2026

    @MarcusSorealheis
    Member

    I'm looking to reproduce this issue now. Thanks for the report @mkanat

  2. added a commit that references this issue on Oct 23, 2026
    db200db
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions