Skip to content

fix(unikontainers): verify pid identity before signaling or joining its netns - #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 signaling or joining its netns#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

Fixes #899.

isRunning(), Signal(), Kill() and joinSandboxNetNs() were all trusting the raw pid stored in state without checking whether it still belonged to the VMM we actually launched. Since Linux reuses pids pretty fast once a process is reaped, if the VMM dies and something else on the host grabs that same pid before we get around to kill/delete, we'd end up signaling the wrong process and even joining its netns instead of the sandbox's.

Fix records the pid's /proc//stat starttime once at Create() time (that value changes whenever a pid gets reused, so it works as a cheap identity check), and checks it before acting on the pid anywhere we previously just assumed it was still ours. If it doesn't match anymore we just treat it like the process is already gone.

Added a few unit tests for the new starttime helper and the identity check itself, covering a live pid, a dead one, a mismatched starttime, negative pid, etc.

Ran go build and go test on pkg/unikontainers, everything passes except two tests (TestCopyFile, TestMoveFile) that were already failing on a clean upstream/main checkout too, they rely on read-only permission checks that don't trigger when running as root in a container, unrelated to this change.

@netlify

netlify Bot commented Aug 4, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit c6e53ee
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a71e603f94cb30007db679a

…ts netns

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 bc66493 to c6e53ee Compare August 4, 2026 13:15
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