Repository navigation
Conversation
## Problem On Linux the syscall filter answers every refusal with ERRNO(EPERM), and nothing records it (strands-agents#33). A workload that opens an AF_PACKET socket, maps W|X memory, or calls bpf, ptrace, or mount is refused without a trace. Only enforcement-point decisions reach the decision log. A security review of a session cannot tell whether the code tried to open a raw socket. ## Solution Compile one more program beside the permit/restrictions pair. It runs permit and then restrictions, with each permit ALLOW jumping into restrictions and each ERRNO(EPERM) rewritten to USER_NOTIF. Install it last with SECCOMP_FILTER_FLAG_NEW_LISTENER. A filter chain holds one listener (EBUSY otherwise), and ERRNO outranks USER_NOTIF, so two notified filters could not work. Both were measured on kernel 6.18. The workload cannot sendmsg once it is filtered, so PID 1 forwards the listener. It copies it out of the workload with pidfd_getfd after the workload drops its caps, and sends it to the box over the relay-control socket. PID 1 first checks that the copy will succeed. If it will not, or if the kernel refuses the observed install, today's two ERRNO filters are installed unchanged and a `refusals_unobserved` control record and a stderr line say so. A failure after a successful install fails the apply closed. No process in the box keeps the listener or the relay descriptor after exec. In the box, one thread per launch answers every notification with EPERM, through one builder that can produce nothing else, and never CONTINUE. It names the syscall and decodes the scalar arguments of the argument-scoped rules. It reads the process's exe and cmdline best effort. When the notification id goes stale, it drops them but still records the call. A refused call therefore still returns EPERM, or ENOSYS if the box is gone. Records pass a per-box limiter: the key is (exe, syscall, arguments), with a 10 s window and 256 keys; past the cap a new key is counted under its syscall alone, so later kinds of call keep their own record. Records and suppressed counts sum to every call, and pending counts flush when the box stops. The new signal is `kernel_refused` (event `strands.box.containment.refusal`, scope `strands-box.containment`, Warn2, log only, not a decision). It is gated by a new include word `kernel`, so a target naming no words receives it. A box whose telemetry names `kernel` is stored at record version 24; every other box keeps its version. macOS Seatbelt, view refusals, and netns refusals stay unobserved (limitations.md). ## Tests - syscall.rs: the_observed_program_notifies_exactly_where_the_pair_answers_eperm (a cBPF interpreter over every arm64 syscall number and the edge arguments of each argument-scoped rule), the_observed_program_is_well_formed, the_fallback_filters_are_unchanged (golden digests from main). - refusal.rs (containment): the_response_always_refuses_with_eperm, the decoder tests, and the_handoff_round_trips_both_outcomes_and_eof. - refusal_notify_linux.rs: a_refused_call_still_answers_eperm_and_reaches_the_listener, the_workload_holds_no_listener_and_no_relay_descriptor, a_closed_listener_answers_enosys, a_refused_observed_install_falls_back_to_the_refusing_filters, a_refused_listener_copy_falls_back_before_the_observed_install, a_listener_that_cannot_reach_the_box_refuses_the_apply (it fails if PID 1 answers FORWARDED on a send error). - telemetry: a_refusal_record_names_the_call_and_never_a_verdict, an_unlisted_refusal_carries_no_arguments_key, the_seventh_signal_has_its_own_spelling_slot_and_severity, a_refusal_reaches_a_file_target_under_the_containment_scope, a_target_without_kernel_receives_no_refusal. - box: the_kernel_word_parses_round_trips_and_is_listed_when_misspelled; the limiter and recorder tests in run/refusal.rs, including records_and_suppressed_counts_sum_to_every_call, past_the_cap_new_keys_are_counted_per_syscall, a_flood_of_distinct_arguments_does_not_hide_a_later_syscall, a_stale_notification_is_recorded_without_its_process, a_fallback_is_announced_with_its_launch_and_errno, the_cap_is_announced_once_and_its_count_flushed_at_stop, and dropping_a_watch_joins_within_two_seconds. - det cases CN-K-01 (socket AF_PACKET and an unlisted call each leave a record), CN-K-02 (100 000 refused calls end with at most 2 records summing to 100 000), and CN-K-03 (`include = ["deny"]` gets none). Forcing the fallback filters makes CN-K-01 and CN-K-02 fail. - Ran on Linux aarch64 (finch, rust:1-bookworm), privileged and masked. strands-box-containment passes in full, refusal_notify_linux 6/6, and telemetry 86/86. strands-box failures are the same ones that fail on main there: hardening, box_shell signalled binary, box_direct_filesystem rename, native_egress_mcp, runtime_mcp_start, runtime_mcp_policy_staging. The det harness passes CN-K 3/3 and TL 8/8. macOS: containment and box unit tests pass. box-bench startup, run alternately from saved binaries: base 330/323 ms, this branch 343/315 ms, inside the noise. - Found: CPython startup makes one refused mremap call (now syscall_216 in a record). Each refused call costs about 60 µs, against about 1 µs before. - Not run: x86_64 (syscall names there wait for strands-agents#21) and Kata. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…doff format Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…, fall back on refusal Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
….containment Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A box whose telemetry includes `kernel` is stored at record version 24, so a build that predates the word refuses the box by version. Every other box keeps the version main gives it (21, 22, or 23). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> ; Conflicts: ; crates/box/src/run/contain/supervise.rs ; crates/box/src/run/hosted.rs
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- A refusal whose notification id went stale (the caller was interrupted or exited while /proc was read) is still recorded. The syscall and arguments come from the kernel; only the process details are dropped. Before, a workload could interrupt its own refused call and leave no trace. Test: a_stale_notification_is_recorded_without_its_process. - refusal_notify_linux: a_listener_that_cannot_reach_the_box_refuses_the_apply pins that a send failure after the observed install refuses the apply (EACCES injected on sendmsg). It fails when PID 1 answers FORWARDED on that error. - The box-level refusals_unobserved records are pinned: a_fallback_is_announced_with_its_launch_and_errno and the_cap_is_announced_once_and_its_count_flushed_at_stop. - dropping_a_watch_joins_within_two_seconds drops on its own thread, so a hang fails the test instead of hanging it. two_watches_share_one_limiter is renamed to what it pins. - PID 1 formats an unknown errno without allocating after the fork (ErrnoName), in place of a leaked String. - Docs: refusals_unobserved reaches a target through `trace`, not `kernel`. limitations.md gains the workload-fillable 256-kind cap and the ~60 µs cost per refused call (glibc realloc's mremap). The five- and six-word counts are corrected, and so are the include error text and the trampoline's --relay-control-fd contract. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The workload picks the arguments that are part of a refusal's key. About 256 junk calls (setpgid with distinct pids, say) filled the box-wide cap, and every later kind of call then became one anonymous count. Past the cap, a new key is now counted under its syscall alone, windowed like any key. So a later bpf or ptrace still gets its own record. Syscall numbers from 1024 up share one bucket, so the coarse set stays bounded. The one rate_cap notice and the Σ(1 + suppressed) = calls invariant are unchanged. Tests: past_the_cap_new_keys_are_counted_per_syscall, records_and_suppressed_counts_sum_to_every_call_past_the_cap, a_numbered_syscall_past_the_known_range_shares_one_bucket, a_flood_of_distinct_arguments_does_not_hide_a_later_syscall, and the updated the_cap_is_announced_once_and_its_count_flushed_at_stop. All four fail with the old anonymous overflow restored. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The Linux deterministic leg had no CPython the harness accepts (it refuses /usr/bin), so CN-K-01..03 failed with DET_ERROR. It now installs uv's python-build-standalone 3.12, as the unit-test leg does on macOS. the_fallback_filters_are_unchanged holds arm64 digests, and the program differs per arch, so it runs on aarch64 only; x86_64's lists are still being settled (strands-agents#21). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
mufaddalq
force-pushed
the
fix/33-kernel-refusal-telemetry
branch
from
October 19, 2026 19:39
58fa0ae to
74dcd74
Compare
Author
|
Status: this branch conflicts with I am holding that until the direction on #33 is settled. The maintainers plan to mediate some syscalls through the policy engine, which changes what this PR should cover. I have written up the implications and two options there: #33 (comment) |
This branch has not been deployed
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.
Description
New feature, with interface changes approved in design. On Linux, a call the seccomp filter refuses now leaves a telemetry record. The boundary does not change: every call refused today is still refused. It gets
EPERMas before, orENOSYSif the box itself has gone away.Today a workload that opens an
AF_PACKETsocket, maps W|X memory, or callsbpf,ptrace, ormountis refused silently. Only enforcement-point decisions reach the decision log, so a review of a session cannot answer "did the code try to open a raw socket?".How it works:
SyscallPolicy::compilebuilds a third program beside the existing pair. It runspermitand thenrestrictions. EachALLOWinpermitbecomes a jump intorestrictions, and eachERRNO(EPERM)becomesUSER_NOTIF. It is installed last, withSECCOMP_FILTER_FLAG_NEW_LISTENER. Two notified filters cannot work, because a filter chain holds one listener (EBUSYotherwise) andERRNOoutranksUSER_NOTIF. Both facts were measured on kernel 6.18. A cBPF interpreter test runs the spliced program and the pair against every arm64 syscall number, and against the edge arguments of each argument-scoped rule. It checks that the spliced program notifies exactly where the pair answersEPERM.sendmsg. So the namespace's PID 1 copies the listener out of the workload withpidfd_getfd, after the workload drops its capabilities, and sends it to the box over the existing--relay-control-fdsocket. No process in the box holds the listener or the relay descriptor afterexec.ERRNOfilters, byte-identical tomain(pinned by golden digests on arm64). One stderr line and onerefusals_unobservedcontrol record say so. A failure after a successful install refuses the apply instead, because nothing can be stacked over the observed filter.EPERM. One thread per launch answers every notification through a single builder, which can produce nothing else and neverCONTINUE. It names the syscall and decodes the scalar arguments of the argument-scoped rules, for examplefamily=AF_PACKET type=SOCK_RAW. It reads/proc/<pid>/exeandcmdlinebest effort. When the notification id goes stale, it drops what/procreturned but still records the call.suppressedcounts always add up to the number of refused calls, and pending counts flush when the box stops.Interface changes:
kernel_refused: eventstrands.box.containment.refusal, scopestrands-box.containment, log only, not a decision. Its keys arestrands.box.containment.{mechanism,syscall,arguments,errno,suppressed},process.pid, and the redactedprocess.command/process.command_args.includewordkernel. A target that names no words receives it, so the default file target gets these records with no config change.refusals_unobserved. Its reason is the errno name, orrate_capwhen the key cap is reached. It reaches a target throughtrace, notkernel.kernelis stored at record version 24, so a build that predates the word refuses it. Every other box keeps the version main gives it (21, 22, or 23). No longer collides with feat(containment): share the container's /proc on masked hosts via [containment] private_proc #58, which uses 25.containment::refusalmodule (the listener, the refusal description, and the handoff reader), andCollector::refusal/RefusalRecordintelemetry.--relay-control-fdcontract: after the egress listeners comes one last message, the listener (O) or the fallback errno (U). The containment README describes it.decisions.mdgains the entry "A kernel refusal is observed, not decided". It records why the record is not a decision, the single spliced filter, why falling back is a deliberate exception to "every failed apply refuses the workload", the never-CONTINUErule, and the rate-limit numbers.Costs and residuals (
limitations.md):box-bench's noise (interleaved runs:main330 and 323 ms, this branch 343 and 315 ms). Found while testing: CPython's startup makes one refusedmremap, and glibc'sreallocof a large block triesmremapfirst. Programs that retry a refused call pay the 60 µs each time.ENOENT,EROFS) and by the network namespace (ENETUNREACH) are still unobserved.EINTRor restart, instead of returningEPERMat once.Out of scope (follow-ups):
kernel_refusedwithmechanism=seatbelt.syscall_<nr>.CI workflow change: the Linux leg of
containment-deterministic.ymlnow installs uv's python-build-standalone 3.12, asrust-test-lint.ymlalready does on macOS. The new CN-K cases drive refused syscalls from CPython, and the harness refuses/usr/bin/python3.For maintainers: as an outside contributor, my CI and Auto Strands Review runs wait for approval (
action_required/manual-approval). Could someone approve them? Thanks.Related Issues
Part of #33: Linux seccomp. The issue stays open for macOS Seatbelt.
Related: #21 / #40 (x86_64)
Type of Change
New feature
Testing
mainat069c39con 2026-10-19; fork CI on the rebased head: run. The run below is from before the rebase.ubuntu-latest(x86_64) andmacos-latest, both Containment / Deterministic legs (CN-K-01..03 run and pass onubuntu-24.04-arm), Lint, and Verdict. The first run (38091871145) failed twice, both fixed in58fa0ae:refusal_notify_linux.rs, 6 tests, on privileged and on unprivileged hosts with masked/proc): a refused call answersEPERMand reaches the listener; the workload holds neither the listener nor the relay descriptor; a closed listener answersENOSYS; a refused observed install and a refusedpidfd_getfdeach fall back to the refusing pair; a send failure after the install refuses the apply. Unit tests cover the splice, a well-formed program, byte-identical fallback filters, the response builder, and the decoders.argumentskey; the seventh signal's spelling, slot, and severity; a refusal reaches a file target under the containment scope; a target withoutkernelgets none.kernelword parses, round-trips, and is listed when an include word is misspelled. The limiter and recorder tests cover first-hit records, windowed counts, the sum invariant (also past the cap), per-syscall counting past the cap (300 junksetpgidkeys do not hide a laterbpf), stale notifications, the fallback andrate_caprecords, and a watcher that stops within 2 s.socket(AF_PACKET)and an unlisted call each leave a record.include = ["deny"]gets no refusal record.rust:1-bookworm):strands-box-containment: all tests pass.strands-box-telemetry: 86/86.strands-boxunit tests: 591 pass. The 2 failures are therun::hardeningtests, which fail the same way onmainin that environment.strands-boxintegration suites: the failures matchmain's in that environment.cargo fmt --allandcargo clippy --all-targets --all-features -- -D warningsonstrands-box-containment,strands-box, andstrands-box-telemetry. The one lint left,chunks_exactinview.rs, also fires onmain.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
🤖 Generated with Claude Code