Repository navigation
fix(sandbox): document unsafe blocks and enforce SAFETY comments with clippy - #5232
Merged
FrostGod merged 1 commit intoNov 9, 2026
Conversation
EmilienM
marked this pull request as ready for review
November 4, 2026 03:36
Contributor
|
/ok to test 16d0012 |
github-actions
Bot
requested review from
TaylorMutch,
drew,
purp and
shiju-nv
November 4, 2026 19:31
shiju-nv
reviewed
Nov 5, 2026
EmilienM
force-pushed
the
fix/5188-sandbox-safety-comments/EmilienM
branch
from
November 5, 2026 14:39
16d0012 to
0d0372a
Compare
shiju-nv
previously approved these changes
Nov 5, 2026
… clippy Every non-test unsafe block in openshell-sandbox now carries a // SAFETY: comment stating its invariant, and clippy::undocumented_unsafe_blocks is enabled at warn level in the crate roots (lib, the sandbox bin, and the seccomp-perf bin), so the CI clippy lanes with -D warnings fail the build on new undocumented blocks. Test-only blocks are exempt through cfg_attr(test, allow) to keep this change free of test-comment churn; the lint fires 89 times on main and zero times after this change. reset_child_signal_dispositions gains a # Safety section documenting its caller contract (forked pre-exec child only), and the vsock control stream reinterpreted as a UnixStream is documented in place: the family-agnostic operations it relies on, the AF_UNIX members that must never be called on it, and the dial-side twin of the same reinterpretation. Small mechanical edits were required so each comment sits on the line directly above its unsafe block (the lint is line-anchored): nine expressions hoisted into let bindings or nested ifs (five syscall probes in main.rs, two F_SETFL guards in network_broker.rs, two in boundary_server.rs), plus two reorderings (a timeout binding in network_broker.rs, the SAFETY comment placement in seccomp_notify.rs). Every movement preserves the original short-circuits and the errno adjacency the probe helpers rely on, and four new tests pin those properties: two run the self-protection probes against seccomp filters (one lets the FIOSETOWN ioctl through to the kernel, so a probe that reads another syscall's errno fails), and two cover the F_SETFL error arms in connect_exact (an O_PATH descriptor for the transition failure, a deny filter for the restore failure). multiple_unsafe_ops_per_block is deliberately not enabled: it is restriction-group and needs block splits at production sites owned by Closes ai-openshell#5188 Signed-off-by: Emilien Macchi <emacchi@redhat.com>
EmilienM
force-pushed
the
fix/5188-sandbox-safety-comments/EmilienM
branch
from
November 6, 2026 18:22
0d0372a to
32c1957
Compare
FrostGod
approved these changes
Nov 6, 2026
FrostGod
enabled auto-merge
November 6, 2026 18:24
Contributor
|
/ok to test 32c1957 |
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.
Summary
Every non-test
unsafeblock inopenshell-sandboxnow carries a// SAFETY:comment stating its invariant, andclippy::undocumented_unsafe_blocksis enabled at warn level in the crate roots, so the CI clippy lanes fail the build on new undocumented blocks. The lint fires 89 times onmainand zero times after this change.reset_child_signal_dispositionsgains a# Safetysection. The vsock control stream reinterpreted as aUnixStreamis documented in place: which operations it relies on being family-agnostic, whichAF_UNIXmembers must never be called on it, and where the dial side does the same reinterpretation.Related Issue
Closes #5188
Note: the issue is still awaiting
state:accepted, so the PR Issue Acceptance job stays red until a maintainer accepts it.Changes
// SAFETY:comments on non-test unsafe blocks acrossboundary_server.rs(7),main.rs(6),network_broker.rs(3),process.rs(2),sandbox/linux/seccomp.rs(1),linux/seccomp_notify.rs(1)# Safetysection onreset_child_signal_dispositions(forked pre-exec child only)#![warn(clippy::undocumented_unsafe_blocks)]inlib.rs,main.rs, andbin/seccomp-perf.rs, each withcfg_attr(test, allow)for the test-only blocks (after rebasing on fix(sandbox): zero-initialize sigset_t before assume_init #5194's signal-mask tests,main.rsneeds the exemption too: their SAFETY comments sit above theassert_*!line, where the line-anchored lint can't see them)F_SETFLerror arms inconnect_exactThis is not a comment-only change: the movements are mechanical but real, and the tests exist because the existing suites are end-state based and cannot catch a wrong hoist.
Left as follow-ups on purpose:
multiple_unsafe_ops_per_blockstays off: it is restriction-group and needs block splits at 7 production sites, one owned by bug: workload pre_exec hooks compile the seccomp filter and log after fork #5180cfg_attr(test, allow); documenting them would let the allow dropclippy::missing_safety_docnever fires on private bin fns, so the# Safetyhalf of the acceptance criteria has no enforcement after this PRRelease Notes
Testing
cargo clippy -p openshell-sandbox --all-targets(with and without--features perf-harness) with-D warnings, the workspace clippy lanes, andcargo fmt --checkcargo test -p openshell-sandboxgreen, plus the full workspace suite, server tests, and nextest groups locallyThe musl cross-check could not run locally (no musl C cross-compiler on this host); the only change near
cfg(musl)code is a comment move.