From b37da8f03cf30636313c971175afb9fb50755ce2 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Wed, 11 Nov 2026 09:34:53 +0000 Subject: [PATCH 1/3] test(ts): stop the spin tenant racing two resource limits The nightly `ts-stress-soak` job went red on its first scheduled run while every PR run of the same test stayed green. `ts_mixed_hostile_and_good_tenants_stay_isolated` asserted that the spin tenant (`while (true) {}`, 300 ms `max_duration`) exits 124. But ZapCode charges one allocation per VM stack push and never decrements the counter (`zapcode_vendor/sandbox.rs`, `track_allocation`), so `max_allocations` is a per-run budget of pushes, not a live heap bound. The loop spends about one per iteration, so the two limits race: a release build burns the 1,000,000 default in a few milliseconds and exits 1 with "allocation limit exceeded", while a debug build reaches 300 ms first and exits 124. PR CI runs debug, the soak runs release, so the assertion picked the winner of a build-speed race. Both outcomes are correct bounded termination, so the spin tenant now asserts only that it stopped on one of its own limits. Dropping a precise assertion would have cost coverage, so each limit is instead pinned on its own, and deterministically in either profile: - `ts_runaway_loop_stops_on_the_wall_clock` raises the allocation budget past what a 300 ms loop can spend, so the clock binds and exit 124 is exact. This is the case the soak was really meant to cover (TM-TS-027). - `ts_runaway_loop_stops_on_the_allocation_budget` lowers it to 50,000 against a 60 s limit, so the push budget binds and exit 1 is exact. No product change: the limits already bounded the loop and no tenant could reach the host abort either way. Before: release soak fails in 0.33s, exit 1 "allocation limit exceeded" vs expected 124, on 3 of 4 spin tenants. After: 7/7 green in release at the nightly's 300 rounds (112.91s) and 7/7 green in debug (2.09s). Knowledge records that `max_allocations` bounds operations rather than heap, and why the spin assertion is deliberately loose. --- .../integration/ts_tenant_stress_tests.rs | 65 ++++++++++++++++++- knowledge/runtimes/zapcode-runtime.md | 17 +++++ 2 files changed, 79 insertions(+), 3 deletions(-) diff --git a/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs b/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs index b1934ea9d..63bde11c1 100644 --- a/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs +++ b/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs @@ -18,6 +18,17 @@ use std::time::Duration; /// headroom in `tenant` so the soak never fails on that cap instead. const MAX_ROUNDS: usize = 1000; +/// Allocation budget large enough that `max_duration` is what stops a runaway +/// loop. ZapCode charges one allocation per VM stack push and never decrements +/// the counter (`zapcode_vendor/sandbox.rs`, `track_allocation`), so +/// `max_allocations` is really a per-run budget of pushes: a `while (true) {}` +/// spends about one per iteration and a release build burns the 1,000,000 +/// default in a few milliseconds, while a debug build reaches a 300 ms +/// `max_duration` first. That made the release-mode nightly soak fail on a +/// tenant whose debug-mode PR run was green. This is ~100x the pushes a 300 ms +/// loop can make, so the clock binds in either profile. +const SPIN_ALLOCATIONS: usize = 1_000_000_000; + fn rounds() -> usize { std::env::var("BASHKIT_STRESS_ROUNDS") .ok() @@ -89,8 +100,9 @@ fn script(load: Load) -> &'static str { } async fn run(load: Load) { - // Only the runaway loop should end on time; the rest must end on their - // own limit (memory, stack) or finish, even in a slow debug build. + // The runaway loop ends on one of its own resource limits; the rest must + // end on their own limit (memory, stack) or finish, even in a slow debug + // build. let max_ms = if matches!(load, Load::Spin) { 300 } else { @@ -112,7 +124,16 @@ async fn run(load: Load) { ); } Load::Spin => { - assert_eq!(r.exit_code, 124, "{load:?} stderr: {}", r.stderr); + // Whichever of the two limits the loop reaches first bounds it, + // and which one that is depends on how fast the build is (see + // SPIN_ALLOCATIONS). Both are correct bounded termination; the + // two tests at the end of this file pin each limit on its own. + assert_ne!(r.exit_code, 0, "{load:?} stdout: {}", r.stdout); + assert!( + r.stderr.contains("timed out") || r.stderr.contains("allocation limit exceeded"), + "{load:?} stderr: {}", + r.stderr + ); } Load::Recurse => { assert_ne!(r.exit_code, 0, "{load:?}"); @@ -255,3 +276,41 @@ async fn ts_host_call_loops_stop_at_the_wall_clock_limit() { "ran {elapsed:?} past a 500 ms limit" ); } + +/// A pure runaway loop, with no host calls to carry the deadline check, stops +/// on `max_duration` once its allocation budget is not what binds (TM-TS-027). +#[tokio::test] +async fn ts_runaway_loop_stops_on_the_wall_clock() { + let mut bash = Bash::builder() + .typescript_with_limits( + TypeScriptLimits::default() + .max_memory(16 * 1024 * 1024) + .max_duration(Duration::from_millis(300)) + .max_allocations(SPIN_ALLOCATIONS), + ) + .build(); + let r = exec_ts(&mut bash, script(Load::Spin)).await; + assert_eq!(r.exit_code, 124, "stderr: {}", r.stderr); + assert!(r.stderr.contains("timed out"), "stderr: {}", r.stderr); +} + +/// The allocation budget bounds the same loop on its own, well before a +/// generous `max_duration`, because the push counter never decreases. +#[tokio::test] +async fn ts_runaway_loop_stops_on_the_allocation_budget() { + let mut bash = Bash::builder() + .typescript_with_limits( + TypeScriptLimits::default() + .max_memory(16 * 1024 * 1024) + .max_duration(Duration::from_secs(60)) + .max_allocations(50_000), + ) + .build(); + let r = exec_ts(&mut bash, script(Load::Spin)).await; + assert_eq!(r.exit_code, 1, "stderr: {}", r.stderr); + assert!( + r.stderr.contains("allocation limit exceeded"), + "stderr: {}", + r.stderr + ); +} diff --git a/knowledge/runtimes/zapcode-runtime.md b/knowledge/runtimes/zapcode-runtime.md index 2f9edff8d..dc6099d94 100644 --- a/knowledge/runtimes/zapcode-runtime.md +++ b/knowledge/runtimes/zapcode-runtime.md @@ -66,6 +66,13 @@ Configurable via `TypeScriptLimits`: | Max stack depth | 512 | `.max_stack_depth(n)` | Prevent stack overflow | | Max allocations | 1,000,000 | `.max_allocations(n)` | Bound VM allocation count | +`max_allocations` counts VM stack pushes and array/object creations, and the +counter never decreases within a run (`zapcode_vendor/sandbox.rs`, +`track_allocation`), so it is a per-run budget of operations rather than a live +heap bound - that is `max_memory`. A `while (true) {}` spends about one per +iteration, so the 1M default stops a runaway loop after about 1M iterations +regardless of how little heap it holds. + Every VM entry charges source bytes, a fixed 4096 work units, and the microseconds each synchronous VM step ran to the request-scoped `ExecutionBudget`. Suspend/resume cycles and external/VFS callbacks retain the @@ -250,6 +257,16 @@ must hit only its own limit. It runs 3 rounds on every PR; heap, so a held 8 MiB string costs about 3x that during the call and counts against `max_memory`. +Decision (2026-11-11): the spin tenant asserts only that it stopped on one of +its own limits, because `max_allocations` and `max_duration` race and the +winner depends on build speed. A release build burns the 1M push budget in a +few milliseconds; a debug build reaches a 300 ms `max_duration` first. Pinning +exit 124 there passed every debug PR run and failed the release nightly soak. +Each limit is instead pinned on its own by +`ts_runaway_loop_stops_on_the_wall_clock` (budget raised so the clock binds) +and `ts_runaway_loop_stops_on_the_allocation_budget` (budget lowered so it +binds), both deterministic in either profile. + Nightly (`nightly.yml`): an ASan pass over the ts unit, threat-model, security and stress tests (`--features typescript`, filters `typescript threat_ts ts_tenant_stress zapcode`), and a `ts-stress-soak` job at 300 rounds in From 2dc9838cea9b959c56b19aa3684766277b9881d4 Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Wed, 11 Nov 2026 09:59:05 +0000 Subject: [PATCH 2/3] fix(deps): bump rustix to 1.1.6 for RUSTSEC-2026-0486 The Audit job went red on every PR and on main without any change to the repository: RUSTSEC-2026-0486 was published against rustix on 2026-10-27, and `scripts/audit-lockfiles.sh` reads the advisory database live. This is exactly the case the scheduled advisory scan exists for. The advisory is an unsoundness in six xattr functions (`fgetxattr`, `flistxattr`, `getxattr`, `lgetxattr`, `listxattr`, `llistxattr`), which mark unwritten bytes as initialized when handed a zero-length buffer. It covers `>=1.0.0, <1.1.6`, and the scan runs `cargo audit --deny unsound`, so it fails rather than warns. Three lockfiles carried an affected version, and all three move to the patched 1.1.6: - `Cargo.lock` 1.1.4 - `crates/bashkit/fuzz/Cargo.lock` 1.1.5 - `examples/hyperlight/host/Cargo.lock` 1.1.4 rustix is transitive everywhere (tempfile, polling, memfd and four others), and bashkit calls none of the six functions, so this is a supply-chain hygiene bump rather than a reachable defect. A patched release exists, so nothing is suppressed and the threat model needs no new entry. Also folds in the `rust-dependencies` group bump from #2913, which was blocked on a stale `supply-chain/imports.lock`: toml 1.2.0 -> 1.2.1, serde_spanned 1.1.2 -> 1.1.3 and toml_datetime 1.1.2 -> 1.1.3. All three are already publisher-trusted to Ed Page (epage) through 2027-05-16, so refreshing the publisher records in imports.lock is all `cargo vet` needed - no new audit or exemption. rustix was already an exemption at 1.1.4 and stays one at 1.1.6: nobody reviewed the 1000-line upstream diff, and an audit entry would assert a source review that did not happen. Verified: `scripts/audit-lockfiles.sh` exits 0 with the rustix denial gone (remaining atomic-polyfill, ttf-parser and crypto-bigint warnings are the pre-existing allowed ones), `cargo vet --locked` succeeds (97 fully audited, 79 partially audited, 585 exempted), the workspace builds with http_client,ssh,sqlite,typescript, and the main test slice passes ~7,900 tests. The only local failure is `ssh_supabase_connects`, which dials the live public supabase.sh over port 22; this sandbox refuses outbound 22, and that test is a network gate that passes in CI. --- Cargo.lock | 30 ++++++++++++++--------------- crates/bashkit/fuzz/Cargo.lock | 10 +++++----- examples/hyperlight/host/Cargo.lock | 4 ++-- supply-chain/config.toml | 2 +- supply-chain/imports.lock | 12 ++++++------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60ebca454..6aa958eb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1232,7 +1232,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1699,7 +1699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d045de693cb712d0b22c6a64be5b953f67b3ce00ab5ad3dd5d8b441886ab8e1a" dependencies = [ "quote", - "syn 3.0.9", + "syn 2.0.119", ] [[package]] @@ -2107,7 +2107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5576,15 +5576,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.13.2", "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5642,7 +5642,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5973,9 +5973,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" dependencies = [ "serde_core", ] @@ -6521,7 +6521,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6717,9 +6717,9 @@ dependencies = [ [[package]] name = "toml" -version = "1.2.0+spec-1.1.0" +version = "1.2.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ffcdf8f50436dbbfd675c1fe1b8e0854f42b7defea8584bdebe1aee900e561" +checksum = "d5755c51863cdac711f1956baf8eb9588e060755f7d3c4c979e70ea1e1f32cd7" dependencies = [ "indexmap", "serde_core", @@ -6732,9 +6732,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "1.1.2+spec-1.1.0" +version = "1.1.3+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" dependencies = [ "serde_core", ] @@ -7671,7 +7671,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/crates/bashkit/fuzz/Cargo.lock b/crates/bashkit/fuzz/Cargo.lock index 6b70a67be..3c0ef0c9b 100644 --- a/crates/bashkit/fuzz/Cargo.lock +++ b/crates/bashkit/fuzz/Cargo.lock @@ -951,7 +951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2616,15 +2616,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.13.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -3523,7 +3523,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/examples/hyperlight/host/Cargo.lock b/examples/hyperlight/host/Cargo.lock index 3db19814a..ed941f3ee 100644 --- a/examples/hyperlight/host/Cargo.lock +++ b/examples/hyperlight/host/Cargo.lock @@ -667,9 +667,9 @@ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags", "errno", diff --git a/supply-chain/config.toml b/supply-chain/config.toml index 525a6d122..2eb905d8d 100644 --- a/supply-chain/config.toml +++ b/supply-chain/config.toml @@ -1934,7 +1934,7 @@ version = "0.3.0" criteria = "safe-to-deploy" [[exemptions.rustix]] -version = "1.1.4" +version = "1.1.6" criteria = "safe-to-deploy" [[exemptions.rustls]] diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index c2c57197a..3ae387734 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -105,8 +105,8 @@ user-login = "cfallin" user-name = "Chris Fallin" [[publisher.serde_spanned]] -version = "1.1.2" -when = "2026-10-08" +version = "1.1.3" +when = "2026-11-06" user-id = 6743 user-login = "epage" user-name = "Ed Page" @@ -119,15 +119,15 @@ user-login = "Darksonn" user-name = "Alice Ryhl" [[publisher.toml]] -version = "1.2.0+spec-1.1.0" -when = "2026-11-04" +version = "1.2.1+spec-1.1.0" +when = "2026-11-06" user-id = 6743 user-login = "epage" user-name = "Ed Page" [[publisher.toml_datetime]] -version = "1.1.2+spec-1.1.0" -when = "2026-10-08" +version = "1.1.3+spec-1.1.0" +when = "2026-11-06" user-id = 6743 user-login = "epage" user-name = "Ed Page" From 315e2a6e214aec6774e75e37b0f6ccf13b987bbd Mon Sep 17 00:00:00 2001 From: Mykhailo Chalyi Date: Wed, 11 Nov 2026 10:03:02 +0000 Subject: [PATCH 3/3] test(ts): name the spin tenant's actual allocation budget Review follow-up. The comment pointed at SPIN_ALLOCATIONS to explain which limit stops this tenant, but the tenant is built by `tenant(16, 300)`, which keeps the default `max_allocations`; SPIN_ALLOCATIONS is only the budget for `ts_runaway_loop_stops_on_the_wall_clock`. A reader following the pointer would have tried to tune this tenant through a constant that does not govern it. Names the default budget instead and keeps the explanation local. No assertion or behavior change. --- .../tests/integration/ts_tenant_stress_tests.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs b/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs index 63bde11c1..d021549ec 100644 --- a/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs +++ b/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs @@ -124,10 +124,13 @@ async fn run(load: Load) { ); } Load::Spin => { - // Whichever of the two limits the loop reaches first bounds it, - // and which one that is depends on how fast the build is (see - // SPIN_ALLOCATIONS). Both are correct bounded termination; the - // two tests at the end of this file pin each limit on its own. + // `tenant` keeps the default `max_allocations`, so this loop + // races the push budget against its 300 ms `max_duration` and + // which one binds depends on how fast the build is: release + // burns the 1,000,000 default in milliseconds, debug reaches the + // clock first. Both are correct bounded termination, so neither + // is asserted here; the two tests at the end of this file pin + // each limit on its own, with a budget chosen so it cannot race. assert_ne!(r.exit_code, 0, "{load:?} stdout: {}", r.stdout); assert!( r.stderr.contains("timed out") || r.stderr.contains("allocation limit exceeded"),