Repository navigation
prowld: close PID reuse race when signaling an adopted pdfork(2) daemon - #709
Merged
Merged
Conversation
Closing the last descriptor of a pdfork(2) process that has exited reaps it without its parent, so a supervisor that checks a child and then signals it cannot rely on the PID staying reserved. Set KI_PROCDESC in ki_kiflag while a descriptor is attached. A descriptor is attached only at pdfork(2) time and never returns once detached, so a process reported without one stays reaped only by its parent. Advertise the flag as the kinfo_procdesc kernel feature so userland can tell an old kernel from a process without a descriptor. PR: 677 AI-Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
The identity check in supervisor_signal() relies on an adopted daemon staying a zombie until prowld reaps it. A pdfork(2) daemon whose descriptor another process holds can be reaped by that close instead, and its PID reused before kill(2) runs. Treat a candidate with KI_PROCDESC as not adoptable. The launch keeps polling, so a launcher that drops its descriptor on exit is adopted as before; one held past the adoption window cancels the launch. Kernels without kinfo_procdesc keep the previous behavior, and prowld logs a notice once at startup. Add regression tests for a held and a closed descriptor, and for a double-forked daemon that changes user ID. PR: 677 AI-Assisted-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #677.
Problem
supervisor_signal()checks an adopted daemon's parent and start time, then callskill(2). That is safe only while the daemon stays a zombie until prowld reaps it. Apdfork(2)daemon breaks this. While its descriptor is attached, wildcardwait()skips it and prowld gets noSIGCHLD. Whichever process closes the last descriptor reaps the zombie itself (procdesc_close()callsproc_reap()), so the PID can be reused between the check and the signal.Fix
Kernel (
756b4c29bd)fill_kinfo_procsets a new flag,KI_PROCDESC(0x8inki_kiflag), whilep_procdescis attached. It reads the field underproctree_lock, which serializes it againstprocdesc_close()andprocdesc_reap().pdfork(2)time and never comes back once detached. So a process seen without one stays safe to signal for its whole life.kinfo_procdesckernel feature lets userland tell an old kernel apart from a process that has no descriptor.tests/sys/kern/sysctl_kern_proc:sysctl_kern_proc_procdesc.prowld (
65d0bb7545)adoptable()helper, used byfind_daemon()andchild_start_time(), rejectsKI_PROCDESCcandidates. That covers selection, handoff and every check before a signal.sbin/prowlctl/tests/prowlctl_test.sh:forking_pdfork_held: never adopted, launch cancelled, daemon killed.forking_pdfork_closed: adopted once the descriptor closes, then stopped.forking_uid: double fork pluschroot -u nobody, adopted and stopped.pdfork_helperfor those tests.prowl-unit.5andprowld-spec.mddocument the rule.Testing
make buildkernel KERNCONF=GENERIC NO_MODULES=yessucceeds.pdfork_helperandsysctl_kern_proc.ccompile with-Wall -Wextra -Werroragainst the newuser.h.checkstyle9.plpasses on the C diff.kern.features.kinfo_procdesc=1. Boot-time pidfile adoption ofinetdand a forking test daemon passes, andprowlctl restartre-adopts inetd.sysctl_kern_procpasses 3/3, includingsysctl_kern_proc_procdesc.sbin/prowlctlpasses 40, skips 1 (trust_test:nfsv4_acl, which skips on /tmp without NFSv4 ACLs). The passes includeforking_pdfork_held,forking_pdfork_closed,forking_uid,forking,forking_launch_identityandforking_pidfile.sbin/prowlctlpasses 38 and skips 3, the two pdfork tests among them.sysctl_kern_proc_procdescfails on itsfeature_present()check, which is expected for a kernel test run on a kernel without the change.AI_POLICY.md.AI-Assisted-by: Claude Opus 5.5
🤖 Generated with Claude Code