Skip to content

feat: add Linux native kernel mechanisms - #191

Merged
kevin-orellana merged 8 commits into
mainfrom
feature/linux-native-kernel
Oct 30, 2026
Merged

kevin-orellana merged 8 commits into
mainfrom
feature/linux-native-kernel

Conversation

@kevin-orellana

@kevin-orellana kevin-orellana commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Human readable section

Problem: Box needs Linux to report selected file operations and accept a response before they complete. Those kernel components need tests before the feature can run workloads.

Solution: Add the notification, file-handle transfer, and kernel-check components. Exercise them through a private test module without enabling Linux native policy for product use.

Example: A test sends a file handle between processes with an invalid handle count. The receiver rejects the transfer and closes the received handle.

Trade-off: Linux builds with the native feature now compile a small C helper. Kernel tests need additional Linux privileges and kernel support. Normal builds still refuse Linux native policy.

Description

This is PR 2 of 4: #186 → #191 → #193 → #188. PR #186 merged into main as 1ad7e987af6db807d66d896600c76a7d8d100b32. This PR now targets main.

Merge commit 5027e9673b2c358374b8688578d0ee0a378eff23 incorporates main and resolves the CI branch-filter conflict. The resulting 15-file diff against main is byte-for-byte identical to the diff Fernando reviewed at c510846e against 53b0f604. No kernel code or test assertion changed in this update.

GitHub dismissed Fernando's prior approval when the base moved. Fresh human approval is required. Three earlier automated readability comments remain open; this merge-only update does not change those lines.

  • Add seccomp notification handling, descriptor transfer, and a startup probe. Seccomp is the Linux interface that pauses selected system calls for a response from a process outside the kernel. A descriptor is a process's handle to an open file or another kernel object.
  • Add the BPF guard loader and kernel type parser. BPF allows small programs to run at kernel hooks. These components support file-identity checks for later delete and rename operations, and remove active loader capabilities after setup.
  • Add fault controls that only dedicated test builds activate. The private box_native_kernel_tests setting compiles the component tests. It does not activate the product adapter.
  • Add C compilation through cc and ar, test instructions, and continuous integration filters for the next two staging branches. Workflow permissions and the main push trigger do not change.

Strengthen the existing parser and capability-probe assertions with independently checked negative controls. Document unsafe buffer and descriptor ownership. Reuse the bounded subprocess helper with visibility limited to its test callers.

The example corresponds to refused_handoff_closes_received_descriptors. Two additional component tests check pathname termination and removal of loader capabilities.
The test that needs the operation layer follows in #193. The split preserves all original tests across the complete stack.

Related Issues

#127 tracks the Linux adapter. #186 is the prerequisite. #193 and #188 complete the stack.
Cloud qualification and performance testing remain separate work.

Type of Change

Other (please describe): independently testable kernel prerequisite for Linux native filesystem policy.

Testing

Current head: 5027e9673b2c358374b8688578d0ee0a378eff23.

The merge-only update passed formatting, all-target/all-feature compilation, feature-disabled build, and dedicated kernel-test compilation. Ordinary compilation reports the existing private-configuration warning; the dedicated kernel-test compilation passes without it. Independent review verified the exact approved patch and confirmed that all 78 imported paths match main. Current-head hosted results appear under Checks.

The following results describe the unchanged implementation and its earlier review fixes; they are not new execution results for this merge commit.

Check Result
Repaired component tests Eight tests passed. Removing type-record parsing or replacing the capability probe with a constant result now fails the intended assertion.
Prior component coverage All 15 kernel tests passed at 048afaee. This review reran eight permitted component tests; it does not claim a new complete privileged guard review.
Independent review Reviewed the test repairs, unsafe ownership comments, and helper visibility. The final merge checks preserved all existing assertions.
Subprocess timeout control The unchanged helper stopped and reaped a stalled child after 60 seconds. The new callers preserve closed standard input.
Strict lint and formatting Ordinary and native all-target lint passed at final stack head 58d0fc2, without new lint allowances. Formatting passed.
Feature-disabled build Passed at d0b3933. Its only subsequent change restricts a test helper's visibility.

Historical full-stack gates and limits

The workspace log reports 4,520 passing tests, zero failures, and 17 ignores at b5d4841, before these test and documentation repairs. The script printed its success footer. The remote disconnect lost its process exit status, so that status remains unavailable. Three host-dependent skip messages remain explicit in the review evidence.

The deterministic containment run recorded 119 passes, one failure, and nine macOS-only skips across all 129 cases. CN-L-02 failed while comparing canonical and noncanonical home paths in the harness. The identical failure reproduced against freshly built main revision e0af331, using the byte-identical harness sources. This is a baseline harness failure, not an introduced regression. The suite remains RED; it is not a qualification pass.

The manual SDK example was not run: its documented setup requires macOS, Homebrew Python, and a Bedrock API key. Fresh execution covered ARM64 Linux. Earlier macOS compilation evidence remains a separate, prior-revision result. Cloud native qualification and performance testing remain deferred.

Fresh independent reviewers applied the repository's feature-critic checklist and reviewed the fixes before commits. This PR repairs two weak test assertions and adds unsafe-code explanations. The later PRs repair capture deadlines and warning documentation. A helper visibility lint introduced during those repairs was also fixed.

Authorization and identity-policy investigation was excluded. Full security sign-off, formal human approval, hosted checks, and merge approval remain outstanding. See current Checks and Reviews before merging.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

keorel and others added 5 commits October 27, 2026 19:04
## Problem

The Linux native adapter needs a containment handoff argument. Mixing its interface migration with the adapter obscures review of existing launch behavior.

## Solution

Add the approved fourth optional argument to Containment::apply and migrate every backend and caller. Callers pass None. A supplied handoff returns UnsupportedCapability before backend selection. Update the public documentation. Include the dependent review branch in the existing CI pull-request filter.

## Tests

Box and containment all-feature suites passed 1,513 tests with six existing ignores. The library callback executable passed, including its callback-created configuration case. an_unavailable_native_handoff_refuses_before_backend_selection checks the refusal and selection order. Build, formatting, diff checks, and strict owned-crate Clippy passed. Independent review found no remaining issues. No baseline test or assertion was removed. Full workspace and native macOS checks were not rerun on this standalone branch. Hosted checks and cloud qualification remain separate.
## Problem

The complete Linux native adapter is too large for one focused review.
Its low-level mechanisms need independent executable coverage before product activation.

## Solution

Stage notification handling, descriptor transfer, kernel identity guards, and capability cleanup behind the private kernel test build.
Keep product entry points at their preparation behavior. Preserve existing component assertions and defer the broker-dependent probe test to the operation layer.
Add staging bases to the existing continuous integration trigger and document component execution.

## Tests

All 15 kernel component tests passed on ARM64 Linux with loader capabilities.
Configuration tests passed with the product adapter unavailable.
The copied-path test checks truncation at NUL and refusal of unterminated input.
The disabled-guard test checks removal of active loader capabilities while retaining other capability bits.
Formatting and strict owned all-target Clippy passed. Independent split and test-harness review verified this tree.
Hosted checks and formal approval remain pending. This change does not establish cloud qualification.
@github-actions

Copy link
Copy Markdown

Assessment: Comment

Solid, well-isolated kernel-prerequisite PR: the mechanisms are crate-internal (pub(crate)/pub(super)), gated behind box_native_kernel_tests, and keep product behaviour unchanged (ordinary Linux builds still refuse native policy). Descriptor ownership in the handoff path is careful — refused handoffs close received FDs on drop, which is pinned by a test. No public/frozen surface changes, and bounded_output is correctly narrowed to pub(super).

My comments are mostly maintainability, plus one focus/testing concern.

Review Categories
  • Focus / testing: fault.rs lands injection points for six stages that have no call site in this PR, and its active #[cfg(box_native_test_faults)] body is not exercised by any test here — consider deferring the unused stages to feat: add Linux filesystem policy operations #193.
  • Maintainability: The hand-assembled BPF program and the seccomp ioctl layer use dense numeric opcodes/helper IDs/magics; named constants would let a reviewer check them against kernel definitions.
  • Readability: One BTF offset-validation condition mixes &&/||/shift/% without parentheses in a security-sensitive parser.
  • Size: ~1600 lines, but this is an intentional PR 2-of-4 split by layer and the new code is cohesive; no further split requested.

Nice work isolating the privileged mechanisms behind an opt-in cfg so product builds stay unaffected.

ferdingler
ferdingler previously approved these changes Oct 28, 2026
Base automatically changed from feature/linux-native-launch-prep to main October 28, 2026 16:23
@kevin-orellana
kevin-orellana dismissed ferdingler’s stale review October 28, 2026 16:23

The base branch was changed.

@kevin-orellana
kevin-orellana enabled auto-merge (squash) October 28, 2026 16:30
@github-actions

Copy link
Copy Markdown

Re-reviewed at 5027e96 (previously reviewed 048afae).

The update is a merge of main plus two welcome improvements to the kernel diff:

  • SAFETY: comments on every unsafe block — I spot-checked the trickier ones (process_vm_readv, fstat/fcntl in validate_registration, the post-fork child paths) and the justifications are accurate.
  • New tests — the probe.rs seccomp-refuse negative path (nicely isolated by re-execing in a subprocess, since the filter is irreversible) and the btf.rs synthetic-blob test for member/hook/truncation.

No new issues in the added code. My four earlier comments are suggestions and remain open — no need to re-post them. One small tie-in: the new btf.rs test uses a struct with kind_flag unset, so the bitfield branch of the offset check (guard/btf.rs:113, the one I flagged for parenthesization) is still unexercised. If you add parentheses there, a case with flags = true and a non-zero bitfield size in the high byte would pin both the precedence intent and that branch in one go.

@kevin-orellana
kevin-orellana merged commit db88268 into main Oct 30, 2026
23 of 24 checks passed
@kevin-orellana
kevin-orellana deleted the feature/linux-native-kernel branch October 30, 2026 06:42
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.

3 participants