Repository navigation
fix(sandbox): keep the scope probe refresh off PATH, decode bus paths - #15636
Conversation
Two defects the post-logout probe fix (#15622) introduced, from its review: - The probe now refreshes on a TTL, and every refresh resolved systemd-run with shutil.which on the event loop. A PATH entry on a stalled mount would hang the gateway's loop. The probe now uses platform_compat.trusted_system_bin, the same fixed-directory lookup cgroup_scope_argv already pins its wrapper with. - DBUS_SESSION_BUS_ADDRESS unix:path= values may percent-escape any byte. Probing the escaped spelling literally misses a live bus that lives outside XDG_RUNTIME_DIR and drops the cgroup ceiling. The value is now decoded before it is dialed.
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing to check. [DESIGN-REVIEWED] 5843231 Description read[DESCRIPTION-READ] 4d764448cf0d1ba8ec2bfa4f11fa0fab658188ef0b00f11b3233d4348c2d6e2b That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify on one real NixOS/Homebrew-style host (systemd-run on PATH only) that the probe's new "unavailable" answer gates nothing beyond the wrapper that already refused. What this change shipsInventory (7 items) — 7 justifiedIntent: FIX — stop the TTL-refreshed cgroup-scope probe from freezing the event loop on a stalled-mount
[FIRST-PRINCIPLES-REVIEWED] 5843231 Description read[DESCRIPTION-READ] 984cf95cb7d7ffd37c33cba0e80564b8d408e5b7f66d2520c800a2f16679e286 That sha256 names the PR description this verdict read. Recompute it with |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Second-round review of this PR: trusted_system_bin's miss diagnostic still calls shutil.which, so a host with no trusted systemd-run walked PATH on the event loop at the first probe refresh. The probe now uses platform_compat.trusted_system_bin_quiet, the same fixed-directory lookup without the diagnostic, and reports the miss in its reason. A D-Bus unix:path= value that decodes to an empty path or one holding a NUL cannot name a socket and made os.stat raise ValueError on the spawn path; such values are now skipped.
|
The Backend Tests (Windows) (2) failure is |
Problem / Motivation
Goal: The cgroup-scope probe added in #15622 never stalls the gateway's event loop on a hung
PATHentry, and never drops the cgroup ceiling because a D-Bus bus address was percent-escaped.#15622 merged with two blocking findings from its GPT 5.6 review still open, both in code that PR added:
shutil.which("systemd-run")on the event loop. That is a walk of everyPATHentry, and one entry on a stalled network mount freezes the loop and the liveness heartbeat._user_bus_socket_pathsdialedDBUS_SESSION_BUS_ADDRESSunix:path=values literally. The D-Bus spec lets any byte be%XX-escaped, so an escaped address that names a bus outsideXDG_RUNTIME_DIRprobed as unreachable, and spawns ran without the fork-bomb/memory ceiling.Why it matters
(1) is a gateway-wide freeze that ends in a watchdog kill and a crash loop on hosts with automounted or network
PATHentries. (2) silently drops a security ceiling on hosts whose bus address is escaped.Not a goal
What changed (motivation → approach → change)
_compute_cgroup_scope_proberesolvessystemd-runthrough the newplatform_compat.trusted_system_bin_quiet, a handful ofstats over fixed system directories. This is the lookupcgroup_scope_argvalready uses to pin the wrapper it prepends, without its miss diagnostic, which itself walksPATHwithshutil.which; the review's second round found that walk.trusted_system_binnow delegates to it and keeps the diagnostic, so its behaviour is unchanged. The probe's answer also matches what the wrapper can actually use. Before, asystemd-runfound only onPATHmade the probe answer "available", and the wrapper then refused it._user_bus_socket_pathspercent-decodes eachunix:path=value (urllib.parse.unquote_to_bytes→os.fsdecode) before it is stat'ed and dialed. A value that decodes to an empty path or contains a NUL cannot name a socket and would makeos.statraiseValueErroron the spawn path, so it is skipped.Backwards compatibility
Compatible: on a host whose
systemd-runis in a trusted directory and whose bus address is unescaped, the probe's answer is unchanged. A host withsystemd-runonly onPATHalready got no ceiling from the wrapper. It now also gets a probe answer that says so, which also stops the bus locators from being forwarded to a spawn that is not wrapped.Tests
test/test_cgroup_scope_probe_liveness.py:test_a_percent_escaped_bus_address_is_decoded: the only live bus is reachable through an escapedunix:path=. Red without the decode.test_a_probe_refresh_never_walks_path:shutil.whichraises if called, and a TTL refresh must still answer(True, "ok"). Red withshutil.whichrestored.test_a_probe_miss_never_walks_path: no trustedsystemd-runandplatform_compat.shutil.whichraises; the probe must answer unavailable without walkingPATH. Red with the diagnosingtrusted_system_bin.test_a_bus_address_naming_no_socket_never_breaks_a_spawn(%00, an embedded%00, and an emptypath=): the probe and wrapper still work off theXDG_RUNTIME_DIRbus. Red without the NUL filter.All 17 tests in the file pass.
test_sandbox_argv,test_per_runtime_process_resources,test_sandbox_agent_slice_identityandtest_session_scope_reappass (327).test_platform_compatand every test that referencestrusted_system_binpass (6296). The one failure,TestPeakRssIsThisProcesss, fails identically on unmodified main on this host. flake8, isort, mypy (src/kiro_crew, 0 issues), black, docs-lint and the comment-history gate are clean.docs/system-specs/common/platform-compat.mdgains a row for the quiet lookup.Manual verification
N/A — unit coverage sufficient: both changes are pure functions of the environment and the fixed system directories, and both tests exercise them through the real probe against a real listening socket.
Related Issues
Follow-up to #15622 (its GPT 5.6 review findings F1 and F2). Refs #11473. Internal report: https://t.corp.amazon.com/187b5c6e-b5cb-4d1b-9c36-ccf8c598e4f4
Pattern harvest
Rule candidate: review-prompt
Pattern: a once-per-process lookup that becomes periodic (TTL or fingerprint refresh) inherits the event-loop budget of every call, so
PATHwalks and other unbounded filesystem lookups inside it must be swapped for fixed-directory resolution.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement