Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(freebsd): map reaper_kill no-failure sentinel to None - #1764

Open
xz-dev wants to merge 1 commit into
bytecodealliance:mainfrom
xz-dev:fix-reaper-kill-no-failure-sentinel
Open

xz-dev wants to merge 1 commit into
bytecodealliance:mainfrom
xz-dev:fix-reaper-kill-no-failure-sentinel

Conversation

@xz-dev

@xz-dev xz-dev commented Dec 4, 2026 •

Copy link
Copy Markdown

Fixes #1763.

Problem

FreeBSD's procctl(PROC_REAP_KILL, …) sets rk_fpid to -1 when no process failed to be signalled (man page: "If no such process exists, the rk_fpid field is set to -1"). reaper_kill passed that value straight to Pid::from_raw, which debug-asserts raw >= 0 — so a fully successful signal operation panicked in debug builds, and produced Some(Pid(-1)) instead of None in release builds.

Observed downstream in procward CI on a FreeBSD 14.3 x86_64 guest (rustix 1.1.6), in a success path with exactly one signalled child and no failures:

Fix

Map nonpositive sentinel values to None before the Pid conversion. Positive failed pids and syscall errors keep their existing handling. > 0 (rather than != -1) stays correct for any nonpositive sentinel and matches the man page contract that only an actual failed pid is positive.

Same class of conversion bug as #1710.

Test

tests/process/procctl.rs::test_reaper_kill_no_failed_pid reproduces the exact failure: acquire reaper status, spawn one child, reaper_kill with Signal::TERM, assert killed == 1 and first_failed == None. Unpatched, this panics in Pid::from_raw in debug builds and fails the assertion in release builds.

Because a flagless reaper_kill signals the reaper's whole domain, the test re-executes the test binary so the domain contains only its own child — running it in-process would TERM sibling tests' children. The outer invocation asserts on the inner output because libtest exits successfully even when a filter matches zero tests.

The test runs in the existing FreeBSD 14.4/15.0 vmactions CI jobs.

Verification

  • cargo check --workspace --release --target=x86_64-unknown-freebsd --features=all-apis --all-targets passes (same command as CI).
  • cargo fmt --check clean.

FreeBSD sets rk_fpid to -1 when PROC_REAP_KILL has no failed target.
Pid::from_raw debug-asserts nonnegative input, so a successful
reaper_kill panicked in debug builds and produced a bogus negative Pid
in release builds. Map nonpositive sentinels to None; positive failed
pids and syscall errors are unaffected.

The regression test runs in a re-executed test binary so that the
reaper domain contains only its own child, and asserts both the killed
count and first_failed == None.

Fixes bytecodealliance#1763.
@xz-dev
xz-dev force-pushed the fix-reaper-kill-no-failure-sentinel branch from 62482fc to f3e2d2a Compare December 4, 2026 05:40
@xz-dev

xz-dev commented Dec 4, 2026

Copy link
Copy Markdown
Author

Local verification on a real FreeBSD 14.3-RELEASE x86_64 guest (quickemu/QEMU, root):

Red — test against unpatched src/process/procctl.rs (fix reverted, test kept):

thread 'procctl::test_reaper_kill_no_failed_pid' panicked at src/pid.rs:44:9:
assertion failed: raw >= 0
test result: FAILED. 0 passed; 1 failed

The exact failure signature from the downstream report — the kernel signals the child successfully, writes -1 to rk_fpid, and the debug assertion in Pid::from_raw fires before reaper_kill can return.

Green — same test against this PR:

test procctl::test_reaper_kill_no_failed_pid ... ok
test result: ok. 7 passed; 0 failed  (whole procctl module)

The FreeBSD 14.4/15.0 vmactions rows are green as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FreeBSD reaper_kill maps the no-failure sentinel -1 through Pid::from_raw

1 participant