Skip to content

T91 — Check that min-answerer links only system libraries - #1954

Merged
norrietaylor merged 8 commits into
mainfrom
agent/1947-check-that-min-answerer-links-only-system-librar
Oct 4, 2026
Merged

norrietaylor merged 8 commits into
mainfrom
agent/1947-check-that-min-answerer-links-only-system-librar

Conversation

@minimal-foundry

Copy link
Copy Markdown
Contributor

T91 — Check that min-answerer links only system libraries

slice: S9
kind: task
covers: NET-122
size: S
est: 80 code, 140 tests
executor: agent
difficulty: needs care
model: strongest
diagnostics: the link check prints each dynamic dependency, RPATH/RUNPATH or LC_RPATH entry it found with its verdict and names each offender, so a build that would install a root service able to resolve a user-writable library fails with the library named
observability: one line per checked dependency; one named line when the OS-native half is skipped on the other OS
layers:
- release:
- scripts/check-answerer-links.sh (new): fails unless the given binary resolves only system libraries, naming each offender: on Linux, ldd entries only in the loader's default dirs (/lib, /lib64, /usr/lib, /usr/lib64 and their multiarch subdirs) or linux-vdso, and no RPATH or RUNPATH entry at all in readelf -d; on macOS, otool -L entries only under /usr/lib and /System, and no LC_RPATH load command at all in otool -l
- scripts/check-answerer-links_test.sh (new): builds fixture binaries in the test; positives are a static Linux binary and a macOS binary linking only /usr/lib and /System; negatives are one each for a non-system .so or dylib, an RPATH, a RUNPATH and an LC_RPATH, each asserted to name its offender; the OS-native half for the other OS is skipped with a named line, never silently
test: bash scripts/check-answerer-links_test.sh
produces:
- scripts/check-answerer-links.sh
consumes: none
proof: The link check passes a system-only binary and fails, naming the offender, any binary with a non-system library or any RPATH, RUNPATH or LC_RPATH entry.

Proof

scripts/check-answerer-links.sh now exists: run it on a binary and it prints one line per dynamic dependency and per RPATH/RUNPATH/LC_RPATH entry with its verdict, and it exits 0 only for a binary that resolves solely from the loader's default dirs (/lib, /lib64, /usr/lib, /usr/lib64 on Linux, /usr/lib and /System on macOS) with no embedded search path at all — a binary with a non-system library, an RPATH, a RUNPATH or an LC_RPATH exits 1 naming the offending entry and its path, and so does anything it cannot inspect. The harness proves each case with fixture binaries it builds itself, and skips the other OS's half with one named line, never silently.

Notes from the agent: The macOS half of the harness is written (clang builds a /usr/lib-only positive, a non-system-dylib negative and an LC_RPATH negative; otool parsing for check-answerer-links.sh is implemented) but cannot be executed on this Linux box — it is skipped with a named line here and will run where otool exists, e.g. just test-shell on a macOS host. Both files are committed with the executable bit (git mode 100755) like every other script under scripts/, because the harness invokes the gate directly. The non-system-.so fixture resolves its library through LD_LIBRARY_PATH rather than an embedded rpath, so it offends in exactly one class; the check deliberately reads what ldd reports, including env-driven resolution, which is the release-gate threat it exists to catch. No files outside the two named layers were touched.

Tests

line exit tail
bash scripts/check-answerer-links_test.sh 0 ok - the static binary passes ok - a system-only dynamic binary passes ok - a non-system .so fails the gate named ok - a dependency that resolves from nowhere fails the gate named ok - an RPATH entry fails the gate ok - the RPATH entry is named with its directory ok - a RUNPATH entry f

Verify

min task run agent-verify exited 101, so this PR is a draft.

russh-cryptovec v0.62.0
   Compiling enum_dispatch v0.3.13
    Checking num-bigint v0.5.1
    Checking russh-util v0.52.0
   Compiling delegate v0.13.5
   Compiling paste v1.0.15
    Checking hex-literal v1.1.0
   Compiling darling_core v0.20.11
   Compiling heapless v0.9.3
   Compiling stdlib v0.0.21 (/home/runner/.local/state/minimal/sessions/f1671/tree/crates/stdlib)
   Compiling darling_macro v0.20.11
    Checking hash32 v0.3.1
   Compiling smoltcp v0.14.0
    Checking netlink-packet-core v0.8.1
   Compiling darling v0.20.11
    Checking tracing-serde v0.2.0
    Checking symlink v0.1.0
    Checking is_executable v1.0.6
    Checking managed v0.8.0
    Checking bitflags v1.3.2
    Checking clap_complete v4.6.11
    Checking tracing-appender v0.2.5
    Checking json-subscriber v0.3.0
   Compiling derive_builder_core v0.20.2
   Compiling nix v0.30.1
    Checking generational-arena v0.2.9
    Checking tinyvec_macros v0.1.1
    Checking opentelemetry-semantic-conventions v0.33.0
    Checking konst_macro_rules v0.2.19
    Checking tinyvec v1.12.0
   Compiling derive_builder_macro v0.20.2
    Checking konst v0.2.20
   Compiling pathrs v0.2.5
   Compiling nix v0.29.0
   Compiling const_format_proc_macros v0.2.34
   Compiling heapless v0.7.17
    Checking netlink-sys v0.8.8
   Compiling procfs v0.18.0
    Checking derive_builder v0.20.2
    Checking hickory-proto v0.26.3
    Checking const_format v0.2.36
    Checking mlog v0.0.1 (/home/runner/.local/state/minimal/sessions/f1671/tree/crates/mlog)
    Checking switch v0.0.1 (/home/runner/.local/state/minimal/sessions/f1671/tree/crates/switch)
    Checking netlink-packet-route v0.25.1
    Checking procfs-core v0.18.0
    Checking hash32 v0.2.1
   Compiling strum_macros v0.27.2
error: using `chunks_exact` with a constant chunk size
   --> crates/switch/src/refusal.rs:205:10
    |
205 |         .chunks_exact(2)
    |          ^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<2>().0.iter()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.98.0/index.html#chunks_exact_to_as_chunks
    = note: `-D clippy::chunks-exact-to-as-chunks` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::chunks_exact_to_as_chunks)]`

error: using `chunks_exact` with a constant chunk size
   --> crates/switch/src/refusal.rs:209:31
    |
209 |     if let Some(tail) = bytes.chunks_exact(2).remainder().first() {
    |                               ^^^^^^^^^^^^^^^
    |
help: consider using `as_chunks::<2>()` instead
   --> crates/switch/src/refusal.rs:209:31
    |
209 |     if let Some(tail) = bytes.chunks_exact(2).remainder().first() {
    |                               ^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.98.0/index.html#chunks_exact_to_as_chunks

error: could not compile `switch` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Closes #1947

min-answerer is the always-on box-zone answerer the host's service
manager holds as a root service (NET-122 to NET-128), so a dependency
it resolves from a user-writable path — or an RPATH/RUNPATH/LC_RPATH
entry baked into the binary pointing at one — is user-chosen code
running as root.

scripts/check-answerer-links.sh fails any binary that does, naming
each offender: on Linux every ldd entry must resolve inside the
loader's default dirs (/lib, /lib64, /usr/lib, /usr/lib64) or be
linux-vdso, an unresolvable entry is refused too, and readelf -d
must show no RPATH and no RUNPATH entry at all; on macOS every
otool -L entry must live under /usr/lib or /System, and otool -l
must show no LC_RPATH load command at all. Each dependency and each
rpath entry is printed with its verdict, one line per entry, and
the gate fails closed on anything it cannot inspect.

The harness builds real fixtures with the host compiler: static and
system-only positives, and one negative per offender class (a
non-system .so or dylib, an RPATH, a RUNPATH, an LC_RPATH), each
asserted to fail naming its offender. Each OS runs only its own
half and says so on one named line when the other is skipped.
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ae47c0c-13d4-43ae-a140-9010b36d86af

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@norrietaylor

Copy link
Copy Markdown
Member

/review

@minimal-foundry

minimal-foundry Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Approved: no findings at 8afb5574e462.

Nothing to do.

Verdict APPROVE, posted as a comment: the App cannot review its own pull request; the check and the label carry it.

Clobber: none: git diff a248cafc..8afb5574 --name-only is exactly the two scripts, and git log on the base shows no prior fix reverted.

@norrietaylor

Copy link
Copy Markdown
Member

/revise Apply three design conditions to scripts/check-answerer-links.sh and its harness. Stay inside the two files this task owns.

  1. Scrub the loader environment. Run ldd under env -u LD_LIBRARY_PATH -u LD_PRELOAD, because the service runs with a clean environment and the verdict must not depend on who ran the gate. Update the header comment, which currently says ldd honours LD_LIBRARY_PATH. Add a harness case: LD_LIBRARY_PATH set to a non-system dir does not change the verdict on the positive fixture. The non-system .so negative must then come from a NEEDED path that really resolves outside the system dirs, not from LD_LIBRARY_PATH. Name how it does in the harness comment.
  2. Match whole path components. Accept only /lib/, /lib64/, /usr/lib/, /usr/lib64/ (Linux) and /usr/lib/, /System/ (macOS), each followed by a /. /usr/local/lib, /usr/lib-x/ and /usr/libexec must fail. Fail any path that contains a .. component, naming it. Add negative cases for /usr/local/lib and /usr/lib/../../tmp. Table cases that feed canned ldd and otool output are acceptable if fixtures are awkward.
  3. Check the Linux program interpreter explicitly. The ELF PT_INTERP from readelf -l must be a system loader path under the same component rule. A static binary has none, and passes. Add one negative fixture built with -Wl,--dynamic-linker=<non-system path> and assert the interpreter is named as the offender.

Keep failing closed and keep one named verdict line per entry. Both halves of bash scripts/check-answerer-links_test.sh must stay green.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approved

Verdict APPROVE — No findings.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 4, 2026
Three conditions the answerer link gate did not hold:

- Its verdict depended on who ran it. ldd honours LD_LIBRARY_PATH, so the
  same binary resolved differently in CI and in a developer's shell, and
  LD_LIBRARY_PATH could make an unresolvable dependency resolve. ldd now
  runs under `env -u LD_LIBRARY_PATH -u LD_PRELOAD`, matching the clean
  environment the service manager starts the answerer with, and the
  header comment says why instead of claiming ldd's view is the user's.
  The non-system .so negative now resolves through a real DT_NEEDED path —
  the fixture library is linked by path with no SONAME, so the loader
  loads it directly — rather than through LD_LIBRARY_PATH.
- The system dirs were prefix-matched, which refused /usr/local/lib but
  not a `..` component: /usr/lib/../../tmp/libnope.so starts inside a
  system dir and passed. Every path the gate inspects now goes through
  one shared whole-component check (a path is in /usr/lib only when it
  starts /usr/lib/, so /usr/local/lib, /usr/lib-x and /usr/libexec are
  not) that also refuses any path carrying a `..` component, naming the
  offender either way.
- The ELF program interpreter was never looked at, and ldd cannot stand
  in for it: it maps a non-system PT_INTERP onto the system loader and
  reports it satisfied. readelf -l now runs first, so a binary linked
  with --dynamic-linker at a user-writable path is named as the offender
  before anything else is checked; a static binary has none and passes.

The harness covers each: the scrub is proved rather than asserted
(LD_LIBRARY_PATH at the directory holding the library fails to rescue a
nowhere-resolving dependency), a real ..-spelled DT_NEEDED fixture is
built by naming the fixture library through /<system dir>/../../<tmp>, a
--dynamic-linker fixture asserts the interpreter is named, and the paths
no unprivileged build can produce (/usr/local/lib, /usr/lib-x,
/usr/libexec, the .. spellings) are table-checked with canned ldd and
otool output on every host — the only place the macOS parsing runs on
Linux, since no macOS CI lane runs this harness.
The table harness stored each canned output as <tool>.<flag>, so otool.-L and otool.-l
collided on a case-insensitive filesystem and the macOS table cases read the load
commands as dependencies. Mark upper-case flag letters in the file name.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Comment thread scripts/check-answerer-links.sh Resolved
@minimal-foundry minimal-foundry Bot added the needs-human An agent handed off; a human must act, then clear this label. Set by defer and handoffs. label Oct 4, 2026
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

The runtime will not revise this pull request again on its own: round 2 would exceed the cap of 1 (the last trigger was the runtime's review findings). A person decides now. Remove needs-human from this pull request to let /revise <note> or the automatic rounds resume, or finish #1947 by hand.

@minimal-foundry minimal-foundry Bot removed the review:approved minimal-review approved the current head label Oct 4, 2026
…k check

glibc ldd prints a warning line for a binary without the exec bit and then lists its
dependencies as usual; the parser refused that line as unrecognized.
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

Round 1 of 1 on a /revise note, pushed as fd3d4540aac0.

line exit tail
bash scripts/check-answerer-links_test.sh 0 ok - the static binary passes, with no interpreter to check ok - the static binary passes ok - a system-only dynamic binary passes ok - the system program interpreter is checked and passes ok - LD_LIBRARY_PATH at a non-system dir does not change the verdict on the positive fixture ok - a

Verify min task run agent-verify exited 101.

generic-array v1.4.4
    Checking russh-cryptovec v0.62.0
   Compiling enum_dispatch v0.3.13
    Checking num-bigint v0.5.1
    Checking russh-util v0.52.0
   Compiling delegate v0.13.5
   Compiling paste v1.0.15
    Checking hex-literal v1.1.0
   Compiling darling_core v0.20.11
   Compiling stdlib v0.0.21 (/home/runner/.local/state/minimal/sessions/78254/tree/crates/stdlib)
   Compiling heapless v0.9.3
   Compiling darling_macro v0.20.11
    Checking hash32 v0.3.1
   Compiling smoltcp v0.14.0
   Compiling darling v0.20.11
    Checking netlink-packet-core v0.8.1
    Checking tracing-serde v0.2.0
    Checking bitflags v1.3.2
    Checking symlink v0.1.0
    Checking is_executable v1.0.6
    Checking managed v0.8.0
    Checking tracing-appender v0.2.5
    Checking clap_complete v4.6.11
    Checking json-subscriber v0.3.0
   Compiling derive_builder_core v0.20.2
   Compiling nix v0.30.1
    Checking generational-arena v0.2.9
    Checking opentelemetry-semantic-conventions v0.33.0
    Checking tinyvec_macros v0.1.1
    Checking konst_macro_rules v0.2.19
   Compiling derive_builder_macro v0.20.2
    Checking tinyvec v1.12.0
    Checking konst v0.2.20
   Compiling pathrs v0.2.5
   Compiling nix v0.29.0
   Compiling const_format_proc_macros v0.2.34
   Compiling heapless v0.7.17
    Checking netlink-sys v0.8.8
   Compiling procfs v0.18.0
    Checking derive_builder v0.20.2
    Checking hickory-proto v0.26.3
    Checking const_format v0.2.36
    Checking mlog v0.0.1 (/home/runner/.local/state/minimal/sessions/78254/tree/crates/mlog)
    Checking switch v0.0.1 (/home/runner/.local/state/minimal/sessions/78254/tree/crates/switch)
    Checking netlink-packet-route v0.25.1
    Checking procfs-core v0.18.0
    Checking hash32 v0.2.1
error: using `chunks_exact` with a constant chunk size
   --> crates/switch/src/refusal.rs:205:10
    |
205 |         .chunks_exact(2)
    |          ^^^^^^^^^^^^^^^ help: consider using `as_chunks` instead: `as_chunks::<2>().0.iter()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.98.0/index.html#chunks_exact_to_as_chunks
    = note: `-D clippy::chunks-exact-to-as-chunks` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::chunks_exact_to_as_chunks)]`

error: using `chunks_exact` with a constant chunk size
   --> crates/switch/src/refusal.rs:209:31
    |
209 |     if let Some(tail) = bytes.chunks_exact(2).remainder().first() {
    |                               ^^^^^^^^^^^^^^^
    |
help: consider using `as_chunks::<2>()` instead
   --> crates/switch/src/refusal.rs:209:31
    |
209 |     if let Some(tail) = bytes.chunks_exact(2).remainder().first() {
    |                               ^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.98.0/index.html#chunks_exact_to_as_chunks

error: could not compile `switch` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Converted to a draft: something above needs a person before review.

The link check still passes a system-only binary (static, with no interpreter to check, and dynamic, with a system one) and now fails — naming the offender on a verdict line of its own — any binary whose dependency, install name or ELF program interpreter resolves outside the whole system dirs (/lib, /lib64, /usr/lib, /usr/lib64 on Linux; /usr/lib, /System on macOS), or carries a .. path component, or carries any RPATH, RUNPATH or LC_RPATH entry, and its verdict no longer depends on LD_LIBRARY_PATH or LD_PRELOAD.

Notes from the agent: Revise round: the directive's three design conditions, all inside the two files the task owns. (1) ldd now runs under env -u LD_LIBRARY_PATH -u LD_PRELOAD, the header comment no longer claims ldd's view is the invoking environment's, and the non-system .so negative resolves through a real DT_NEEDED path (fixture library linked by path with no SONAME, so the loader loads the absolute DT_NEEDED directly) instead of through LD_LIBRARY_PATH; the harness comment names how. (2) The whole-component rule is one shared check (system_dir + carries_dotdot + path_state in the gate) applied to every path: dependencies, install names and the interpreter; /usr/local/lib, /usr/lib-x and /usr/libexec are refused, and so is any path carrying a .. component, named as such. (3) readelf -l runs first on Linux so PT_INTERP is checked explicitly; a static binary has none and passes, and a --dynamic-linker fixture asserts the interpreter is named as the offender. Two of the three were real holes, not paperwork: the previous round's gate exited 0 on a binary whose DT_NEEDED was spelled /usr/lib/../..//libfixture.so, and exited 0 on an unresolvable dependency once LD_LIBRARY_PATH named the directory; both were reproduced against HEAD before the fix. The .. fixture is real end-to-end (DT_NEEDED records the path exactly as spelled, and ldd prints it back), so the directive's /usr/lib/../../tmp shape is built, not canned; /usr/local/lib, /usr/l…[truncated]

@minimal-foundry
minimal-foundry Bot marked this pull request as draft October 4, 2026 10:44
@norrietaylor
norrietaylor marked this pull request as ready for review October 4, 2026 11:02

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — 1 finding, 1 inline.

Comment thread scripts/check-answerer-links.sh Resolved
@minimal-foundry

Copy link
Copy Markdown
Contributor Author

The runtime will not revise this pull request again on its own: round 2 would exceed the cap of 1 (the last trigger was the runtime's review findings). A person decides now. Remove needs-human from this pull request to let /revise <note> or the automatic rounds resume, or finish #1947 by hand.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — approved

Verdict APPROVE — No findings.

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at 8afb557. The link check rules match the design: scrubbed loader environment, whole-component paths with no '..', PT_INTERP check, no rpath of any kind, and a fail-closed parser. ARCH PASS. The harness is green on both halves (macOS 18, Linux 30) and every lane is green.

@norrietaylor norrietaylor removed the needs-human An agent handed off; a human must act, then clear this label. Set by defer and handoffs. label Oct 4, 2026
@norrietaylor
norrietaylor enabled auto-merge October 4, 2026 11:31
@norrietaylor
norrietaylor added this pull request to the merge queue Oct 4, 2026
Merged via the queue into main with commit f4b5854 Oct 4, 2026
34 checks passed
@norrietaylor
norrietaylor deleted the agent/1947-check-that-min-answerer-links-only-system-librar branch October 4, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T91 — Check that min-answerer links only system libraries

1 participant