Repository navigation
[CTX-1361] fix(runtime): harden activation record read/write and the ignored acceptance guard - #2295
Merged
Merged
Conversation
…ignored acceptance guard Follow-up to #2276 review findings F1, F2 and B1. F1 (write side): the record was written with `std::fs::write` to the predictable `activation.tmp-<pid>-<serial>` path, so a same-user process could pre-plant that name as a symlink and redirect the write. The temp record is now created with `create_new` (mode 0600; `O_CREAT|O_EXCL` refuses a link), flushed with `sync_all`, renamed over `activation`, and the directory is flushed. `AlreadyExists` retries under a fresh name (bounded, 8 attempts) without ever removing an entry this writer did not create; any other failure removes the temp file best-effort and returns the new typed `ActivationWriteError` (the broker drops it - activation is diagnostics, never a request gate). F2 (read side): the size bound came from `symlink_metadata` while `std::fs::read` re-resolved the path, so a swapped-in symlink or a grown file defeated both the no-follow and the size guarantee. The record is now opened once without following a link (`O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC` via rustix/nix; `FILE_FLAG_OPEN_REPARSE_POINT` on Windows; fail-closed elsewhere), the length and regular-file checks come from that handle, and the read is bounded by `take(MAX + 1)` with a length-mismatch rejection. B1: the ignored `bitty-net` acceptance test returned `Ok` when `BITTY_NET_COMPONENTS_DIR` was unset, so `--run-ignored ignored-only` reported a vacuous PASS. It now fails with a clear message when the fixture is missing or does not contain the installed component. Tests: planted temp symlink is not followed and the write retries; exhausted temp names surface `TempNameExhausted`; a record grown after the metadata snapshot is rejected; a symlinked oversize record reads as `installed`; the acceptance test fails without its fixture. Mutation evidence: `create_new` -> `create|truncate` makes both write tests fail (the planted link is followed and the victim overwritten); dropping the length-mismatch check makes the grown-record test fail; `File::open` instead of the no-follow open makes the symlinked-record test fail; the old `return` guard makes the ignored test PASS without the fixture. Refs #2276, #2254
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Xuepoo
added a commit
that referenced
this pull request
Oct 20, 2026
The first pass was audited at `470c20ab`; four commits merged while it was open and one of them changes a claim the entry makes. - #2296 adds the production component request surface (`bitty.component.request` / `bitty.component.poll`) and closes #2254, so the Known issues bullet no longer says no request producer exists. Its real limits replace it: no IPC verb, no streaming or retained handle, lossy UTF-8 response bodies, and a mirrored grant surviving a runtime-only suspend. - #2295 hardens the activation record against a planted symlink on both the write and read side, with a typed `ActivationWriteError`. - #2291 moves all six extracted extension pins to their upstream heads and adds the pin drift gate. - #2298 deflakes the cross-VM `command_invoke` test against the 50 ms production RC-1 wall budget. The provenance line now records the audited head `6c4ae437`. The RC-1 fuel accounting fix is still not claimed: PR #2292 remains open. Docs-only: no code, scripts, workflows, or pins touched.
Xuepoo
added a commit
that referenced
this pull request
Oct 20, 2026
The first pass was audited at `470c20ab`; four commits merged while it was open and one of them changes a claim the entry makes. - #2296 adds the production component request surface (`bitty.component.request` / `bitty.component.poll`) and closes #2254, so the Known issues bullet no longer says no request producer exists. Its real limits replace it: no IPC verb, no streaming or retained handle, lossy UTF-8 response bodies, and a mirrored grant surviving a runtime-only suspend. - #2295 hardens the activation record against a planted symlink on both the write and read side, with a typed `ActivationWriteError`. - #2291 moves all six extracted extension pins to their upstream heads and adds the pin drift gate. - #2298 deflakes the cross-VM `command_invoke` test against the 50 ms production RC-1 wall budget. The provenance line now records the audited head `6c4ae437`. The RC-1 fuel accounting fix is still not claimed: PR #2292 remains open. Docs-only: no code, scripts, workflows, or pins touched.
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 the blocking findings from the independent review of #2276 (CTX-1361 /
#2254). One commit, no behavior change for a well-behaved filesystem.
Priority: P1 | Area: runtime | Labels: fix,area:runtime,P1 | Milestone: 0.0.24 | RFC: OQ-xxx | Task: CTX-1361
F1/CR1 — write side followed a planted symlink
write_activationwrote the record withstd::fs::writeto the predictableactivation.tmp-<pid>-<serial>path, so a same-user process with write accessto the component directory could pre-create that name as a symlink and redirect
the write. Now:
OpenOptions::new().write(true).create_new(true)(mode 0600 on Unix):
O_CREAT|O_EXCLrefuses an existing entry, including aplanted link, and nothing is truncated;
AlreadyExistsretries under a fresh name (bounded: 8 attempts), and a failedcreation never removes an entry the writer did not create;
sync_all, renamed overactivation, and thecomponent directory is flushed so the rename survives a crash;
ActivationWriteError(RecordNotRegular,RecordOversize,TempNameExhausted,TempCreate,TempWrite,Rename,SyncDir). The threebroker call sites drop it explicitly: activation is diagnostics and never a
request or stop gate.
F2 — the read bound was not a bound
The size came from
symlink_metadatawhilestd::fs::readre-resolved the path,so a symlink swapped in afterwards was followed and read to EOF. Now the record
is opened once without following a link (
O_NOFOLLOW|O_NONBLOCK|O_CLOEXECviarustix/nix,FILE_FLAG_OPEN_REPARSE_POINTon Windows, fail-closed on aplatform without such an open), the regular-file test and length come from that
handle, and the read is
take(MAX + 1)with a length-mismatch rejection, so arecord that grew between snapshot and read is rejected instead of parsed. A FIFO
at the record path can no longer block the open.
B1 — vacuous ignored acceptance test
real_bitty_net_serves_and_denies_with_a_named_classreturnedOkwhenBITTY_NET_COMPONENTS_DIRwas unset, so--run-ignored ignored-onlyreportedPASS without running. It now panics with a clear message when the fixture is
missing, and asserts the fixture actually contains the installed component, so a
green run always means the acceptance flow executed. (I did not re-run the real
bitty-netflow: the recorded evidence inrecording/ctx-1361-component-broker/still stands, and this PR only changes the guard.)
B2 — docs
Docs-only sync merged first: bitty-terminal/bitty-terminal-docs#249
(squash
86e0897), describing the ACTIVATION column, its labels and denialclasses, and the persistent
activationrecord besidecurrent.Deferred (tracked)
bitty#2294 covers F3 (name-scoped state on every version row), F4 (
activeislast-recorded, not liveness), F5/P3 (system-tier projection), F6 (a denial
overwriting the
crashedlatch), F7 (stale temp files blocking prune).Tests and mutation evidence
New tests (
crates/bitty-runtime/src/component/activation.rs):planted_temp_link_is_refused_and_the_write_retries_under_a_fresh_nameactivation.tmp-*symlink is not followed and the write lands under a fresh nameexhausted_temp_names_surface_a_typed_errorTempNameExhausted, create nothinggrown_record_is_rejected_by_the_handle_boundsymlinked_oversize_record_is_rejected_without_reading_itinstalledsymlinked_record_is_never_followed(extended)RecordNotRegular, link target untouchedMutation checks (each reverts one guard; the named test fails):
create_new(true)->create(true).truncate(true): the planted link isfollowed and the victim is overwritten with
v1 stopped(
planted_temp_link_...,exhausted_temp_names_...fail).bytes.len() != metadata.len()rejection:grown_record_is_rejected_by_the_handle_boundfails.open_record_no_follow->std::fs::File::open:symlinked_record_is_never_followedfails.returnguard: the ignored acceptance test reports PASSwithout the fixture (with the guard it fails, see the run log in the PR
conversation).
Gates (local)
cargo fmt --all -- --check: PASScargo clippy --workspace --all-targets --lockedwithRUSTFLAGS=-D warnings: PASScargo nextest run -p bitty-terminal -p bitty-runtime --locked: 3881 passed, 3 skippedcargo check --workspace --all-targets --locked --target x86_64-pc-windows-msvc: PASSjust scratch-paths: OKjust ci-local: not run — the repository lock(
.git/ci-local.lock) is held by another run in this repo; remoteQuality gatesruns the same job.CARGO_BUILD_JOBS=8,CARGO_TARGET_DIR=$BITTY_WORKSPACE/.targets/ctx-1361-findings(removed after the PR).
Refs #2276, #2254, #2294