Skip to content

fix(unikontainers): verify pid identity before signal/netns join - #900

Draft
Anand-240 wants to merge 1 commit into
urunc-dev:mainfrom
Anand-240:fix/pid-reuse-identity-check
Draft

fix(unikontainers): verify pid identity before signal/netns join#900
Anand-240 wants to merge 1 commit into
urunc-dev:mainfrom
Anand-240:fix/pid-reuse-identity-check

Conversation

@Anand-240

@Anand-240 Anand-240 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

isRunning(), Signal(), Kill(), and joinSandboxNetNs() all trusted the
raw pid stored in state without checking whether it still belonged to
the VMM process urunc originally launched. Linux reuses pid numbers
quickly once a process is reaped, so if the VMM dies and an unrelated
host process is assigned the same pid before kill/delete runs, urunc
could signal the wrong process or join its network namespace instead
of the sandbox's.

This records the pid's /proc//stat starttime once at Create()
time (the kernel changes this value whenever a pid is reused), and
validates it before acting on the pid anywhere it was previously
assumed to still belong to this container. A mismatch is now treated
the same as the process already being gone.

Related issues

How was this tested?

  • go build ./pkg/unikontainers/... and go test ./pkg/unikontainers/... pass
  • Added unit tests for the new starttime helper and the identity check
    itself, covering a live pid, a dead pid, a mismatched starttime, and
    a negative pid
  • TestCopyFile and TestMoveFile fail identically on a clean
    upstream/main checkout when run as root in a container, since their
    read-only permission checks don't trigger for root. Unrelated to
    this change.

LLM usage

Claude (Anthropic, model: claude-sonnet-5) assisted with tracing the
call sites and drafting the fix and this description. Reviewed and
tested by me before opening this PR, per the project's LLM policy.

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint). Not run locally, no
    golangci-lint setup available in this environment; deferring to CI.
  • The e2e tests of at least one tool pass locally. Not run
    locally; deferring to CI.
  • If LLMs were used: I have read the llm policy.

@netlify

netlify Bot commented Aug 4, 2026

Copy link
Copy Markdown

Deploy Preview for urunc ready!

Name Link
🔨 Latest commit a5a33e4
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a79f6fb4547870008e0c84a
😎 Deploy Preview https://deploy-preview-900--urunc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Anand-240
Anand-240 force-pushed the fix/pid-reuse-identity-check branch from bc66493 to c6e53ee Compare August 4, 2026 13:15
isRunning(), Signal(), Kill(), and joinSandboxNetNs() all trusted a raw
stored pid without checking whether it still identified the VMM
process that was originally launched. Linux recycles pid numbers as
soon as a process is reaped, so after the VMM exits and its pid gets
reused by an unrelated process, urunc could end up sending SIGKILL to
that unrelated process and joining its network namespace instead of
the sandbox's, or could refuse to ever delete an already-dead
container because isRunning() saw a live but unrelated process.

Record the /proc/<pid>/stat starttime for the VMM pid at Create()
time, since the kernel guarantees this value changes whenever a pid
number is reused, and validate it before treating the pid as
belonging to this container in isRunning(), Signal(), Kill(), and
joinSandboxNetNs(). A mismatch is now treated the same as the process
no longer existing.

Fixes: urunc-dev#899
Signed-off-by: Anand-240 <anandprakashsrivastava68@gmail.com>
@Anand-240
Anand-240 force-pushed the fix/pid-reuse-identity-check branch from c6e53ee to a5a33e4 Compare August 10, 2026 16:06
@Anand-240 Anand-240 changed the title fix(unikontainers): verify pid identity before signaling or joining its netns fix(unikontainers): verify pid identity before signal/netns join Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant