diff --git a/os/mini/init.sh b/os/mini/init.sh index fb52332b9..970f1fd64 100755 --- a/os/mini/init.sh +++ b/os/mini/init.sh @@ -156,11 +156,15 @@ else fi # The sealed NPU kernels live on the stick (they used to be inside the RAM image, which made it too big -# to load): link them to the path the engine looks for, beside itself. -if [ -d /data/npu/kernels ] && [ -d /home ]; then - mkdir -p /home/bcloud/wt/npupkg-build/npu 2>/dev/null - ln -sfn /data/npu/kernels /home/bcloud/wt/npupkg-build/npu/kernels 2>/dev/null - say "[kernels] $(ls /data/npu/kernels | wc -l) sealed NPU sets linked beside the engine" +# to load): link them to the path the engine looks for, BESIDE ITSELF. The engine is at /bin/1bit as a real +# file (engine#1543 — it used to live at its builder's build path, and this link hardcoded that path, which +# was the same disclosure a script instead of a layout), so "beside itself" is /bin/npu/kernels. A link +# left at the old path is not a cosmetic miss: the engine would find no set, register no NPU device, and the +# boot would otherwise look green. +if [ -d /data/npu/kernels ]; then + mkdir -p /bin/npu 2>/dev/null + ln -sfn /data/npu/kernels /bin/npu/kernels 2>/dev/null + say "[kernels] $(ls /data/npu/kernels | wc -l) sealed NPU sets linked beside the engine (/bin/npu/kernels)" fi n=0 diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index 8c207ae19..4aafeca5d 100755 --- a/os/mini/mkimage.sh +++ b/os/mini/mkimage.sh @@ -66,7 +66,7 @@ set -euo pipefail export PATH="$PATH:/usr/sbin:/sbin" out=${1:?usage: mkimage.sh [engine build dir]} build=${2:-$HOME/.cache/1bit-os/src/build} -build=$(cd "$build" && pwd) # absolute: binaries keep their build paths inside the image +build=$(cd "$build" && pwd) # absolute, so copy_libs resolves NEEDED against it; the image no longer keeps it kver=${KVER:-$(uname -r)} # the kernel image: /boot/vmlinuz-, or VMLINUZ= (e.g. unpacked from its .deb where /boot is root-only); # the engine builds no kernel: the Strix Halo kernel packages come from our separate kernel build @@ -316,12 +316,18 @@ fw "amdgpu/gc_11_5_1_*" "amdgpu/sdma_6_1_1*" "amdgpu/psp_14_0_1*" "amdgpu/smu_14 echo "== the engine" bin=$build/onebit; [ -x "$bin" ] || bin=$build/1bit [ -x "$bin" ] || { echo "no engine binary in $build (build with -DONEBIT_NPU=ON -DONEBIT_HRX=ON)"; exit 1; } -copy_elf "$bin" -ln -s "$bin" "$root/bin/1bit" -# The sealed NPU kernel sets travel BESIDE the engine binary (docs/releases.md, "The NPU engine"): -# in a package that is /npu/kernels next to /1bit, and here the binary keeps its build -# path, so the sets go to the same place relative to it. Without them the image ships the NPU -# route and nothing it can load - the route then refuses rather than falling back. +# The engine goes to /bin/1bit as a REAL FILE: copying it to its build path and symlinking /bin/1bit at it +# shipped the builder's username, working directory and build-directory name in the initrd, plus a second +# copy of the binary at that path (engine#1543 — the fourth leak class: a path delivered as the filesystem +# layout itself, which no content scan can see). Nothing in the image needs the build path: the binary +# carries no RUNPATH (it resolves its NEEDED libraries from the standard loader paths, which copy_libs +# stages), and no NPU kernel set is staged beside it. Keep copy_libs: it walks NEEDED, not the path. +mkdir -p "$root/bin" +cp -L "$bin" "$root/bin/1bit" +chmod 0755 "$root/bin/1bit" +copy_libs "$bin" +# No NPU kernel set is staged into the mini image (the route refuses rather than falling back); if one +# ever is, it goes beside /bin/1bit, which is now where the engine lives. echo "== Lemonade (lemond, the lemonade CLI, the web app)" @@ -471,12 +477,12 @@ lemver=$("$lem/bin/lemond" --version 2>/dev/null | sed -n 's/^lemond version \([ # actually carries, and release-check's identity row SKIPped every mini image for that reason (engine#1481). The engine's # own sha256 is checkable, so it is written BESIDE the git sha rather than replacing it. # - # WHICH file, though: a mini image does not carry the Lemonade package's 1bit/1bit (that layout is os/v3's) - `copy_elf` - # puts this build's engine at "$root$bin" and /bin/1bit is a symlink to that same absolute path. So the bytes to hash are - # the IMAGE's copy, not the build tree's and not the payload's: hashing "$root$bin" is post-`cp -L`, and nothing rewrites it - # afterwards (the only `relocate`/patchelf calls are on the data-partition llama set). Hashing the build file would name - # bytes the image may not carry, and hashing `$root/bin/1bit` would follow the symlink out to the host's build tree. - launcher=${bin:+$root$bin} + # WHICH file, though: a mini image does not carry the Lemonade package's 1bit/1bit (that layout is os/v3's). The engine is + # staged at /bin/1bit as a REAL file (engine#1543 — the build path used to hold it, and the path was the leak), so the + # bytes to hash are the IMAGE's copy, not the build tree's and not the payload's: `$root/bin/1bit` is post-`cp -L`, and + # nothing rewrites it afterwards (the only `relocate`/patchelf calls are on the data-partition llama set). Hashing the build + # file would name bytes the image may not carry; that is why this reads the staged copy and not "$bin". + launcher=${bin:+$root/bin/1bit} if [ -n "${launcher:-}" ] && [ -f "$launcher" ]; then echo "engine_sha256: $(sha256sum "$launcher" | cut -c1-64)" else diff --git a/os/mini/release-check.sh b/os/mini/release-check.sh index d1f35b7ad..1643df8b9 100755 --- a/os/mini/release-check.sh +++ b/os/mini/release-check.sh @@ -656,6 +656,24 @@ memlock_verdict() { "$_p" "$_v" "${_f:+ (highest-numbered memlock file: $_f)}" } +# The image must not carry a builder's home directory (engine#1543). The mini (initramfs) image used to +# ship its engine at the BUILDER's build path and symlink /bin/1bit at it, so the initrd disclosed the +# builder's username, working directory and build-directory name - and carried a second copy of the +# binary there. That is the fourth leak class: a path delivered as the filesystem LAYOUT rather than as +# bytes in a file, which build_path_strings cannot see (it reads the contents of packed ELFs and +# generated text). A mini image ships no users at all, so any /home/* path in its root is a builder's. +# Pure, so --self-test drives it: [] +builder_paths_verdict() { + _n=${1:-} _sample=${2:-} + case "$_n" in ''|*[!0-9]*) printf 'FAIL the image'"'"'s /home paths could not be counted (%s)' "${_n:-empty}"; return 0 ;; esac + if [ "$_n" = 0 ]; then + printf 'PASS the image carries no /home path: its engine is at /bin/1bit as a real file, so no builder directory travels with it' + else + printf 'FAIL %s /home path(s) in the image%s - a mini image ships no users, so this is the builder'"'"'s home (engine#1543: the engine belongs at /bin/1bit as a real file, not at its build path behind a symlink)' \ + "$_n" "${_sample:+: $_sample}" + fi +} + payload_modes_verdict() { # [] _f=${1:-} _d=${2:-} _sample=${3:-} case "$_f" in ''|*[!0-9]*) printf 'FAIL the payload'"'"'s file modes could not be counted (%s)' "${_f:-empty}"; return 0 ;; esac @@ -784,6 +802,11 @@ if [ "${1:-}" = --self-test ]; then check FAIL "$(memlock_verdict '' lemond)" # running but unreadable: unknown is not a pass check FAIL "$(memlock_verdict 'lots' lemond)" # nonsense is a fail, not a skip check PASS "$(payload_modes_verdict 0 0)" + # engine#1543: the fourth leak class - a path delivered as the layout, not as bytes + check PASS "$(builder_paths_verdict 0)" + check FAIL "$(builder_paths_verdict 4 'home/bcloud home/bcloud/wt home/bcloud/wt/build home/bcloud/wt/build/1bit')" + check FAIL "$(builder_paths_verdict 1)" + check FAIL "$(builder_paths_verdict '')" check FAIL "$(payload_modes_verdict 134 49)" # c31/c32's real shape: 134 files AND 49 directories check FAIL "$(payload_modes_verdict 0 1)" # the c33 first cut: no files, the payload ROOT writable check FAIL "$(payload_modes_verdict 1 0 '/opt/1bit-package/1bit/1bit')" @@ -1878,6 +1901,31 @@ else skip identity "no /etc/1bit/release-identity in this image build; the tag and the image sha256 are in the release table beside the .img.zst" fi +# ── the image's own LAYOUT must not name its builder (engine#1543) ─────────────────────────────────── +# A mini image's root IS the image, so a builder's home is visible right here; a stick's base layer has real +# users and /home is its own, so this row is mini-only. `engine: ` in the identity file is the +# mini schema (os/mini/mkimage.sh) - the same marker the identity row keys on above. +if [ -n "$(sed -n 's/^engine: *//p' "${ID:-/etc/1bit/release-identity}" 2>/dev/null | head -1)" ]; then + _bp_paths=$(find / -xdev -maxdepth 6 -path '/home/*' 2>/dev/null | sed 's|^/||' | head -20) + _bp_n=$(printf '%s\n' "${_bp_paths:-}" | sed '/^$/d' | wc -l) + BP=$(builder_paths_verdict "${_bp_n:-0}" "$(printf '%s' "$_bp_paths" | sed '/^$/d' | head -3 | tr '\n' ' ')") + case "$BP" in + PASS*) pass image-builder-paths "${BP#PASS }" ;; + *) fail image-builder-paths "${BP#FAIL }" ;; + esac + # And the coupling that makes the move safe (engine#1543): the engine looks for its sealed NPU sets BESIDE + # ITSELF, and they live on the stick, so init.sh links /data/npu/kernels beside /bin/1bit. A link left at + # the engine's old build path registers no device on an otherwise green boot - so it is checked here. + if [ -d /data/npu/kernels ]; then + if [ -e /bin/npu/kernels ]; then pass npu-kernels-beside-engine "/bin/npu/kernels -> $(readlink /bin/npu/kernels 2>/dev/null || echo '(a directory)')" + else fail npu-kernels-beside-engine "/data/npu/kernels exists but /bin/npu/kernels does not: the engine finds its sealed sets beside itself, so no NPU device would register on this boot"; fi + else + skip npu-kernels-beside-engine "no /data/npu/kernels on this boot, so there is no set to link beside the engine" + fi +else + skip image-builder-paths "not a mini image (no mini identity file), so /home here is not a builder path to check" +fi + # ── the payload's modes (engine #1352) ───────────────────────────────────────────────────────────── # The board-side half of #1361: the packer now normalises and asserts at pack time, and this proves it on the shipped tree. It # also prints the two binaries' modes, so the identity of a boot says 0755 for `1bit` and `bin/lemond` rather than leaving a reader diff --git a/policies/build-path-leak-classes.md b/policies/build-path-leak-classes.md new file mode 100644 index 000000000..04ee88842 --- /dev/null +++ b/policies/build-path-leak-classes.md @@ -0,0 +1,59 @@ + +# Build-path leaks: the four classes, and the guard each one needs + +An artefact that ships its builder is a small disclosure (a username, a working directory, a build-tree +name) and a large reproducibility problem: two builds of the same commit do not produce the same bytes. +By 2026-11-08 the fleet had fixed the same class five times in five artefacts, each time re-deriving the +taxonomy. It is written down here so the next one starts from the list. + +The classes are distinguished by **where the path lives**, because that decides the remedy — and because +a guard that reads one of them cannot see another. + +| # | where the path is | measured example | remedy | +|---|---|---|---| +| 1 | **baked into a binary** by `__FILE__`, `-g`, or a compiled-in absolute path | `1bit` carried `ONEBIT_HRX_LIBHSA=/home//…/libhsa-runtime64.so.1` (engine#1459); `lemond` and `lemonade` carried 126 + 13 paths from `__FILE__` (engine#1461) | a prefix map (`-ffile-prefix-map`, `-fdebug-prefix-map`) at build time; nothing compiled in that the build cannot rewrite | +| 2 | **a build tree that was packaged** | `scripts/mod/devicetable-offsets.s` and friends in a kernel headers `.deb`: 449 absolute paths, the difference between two builds of the same package being exactly 449 lines × 30 B (engine#1487) | do not package the tree; a header package ships the `.c`, not the compiler's by-products | +| 3 | **a symbol table** or a comment in generated text | the same headers package, before it was pruned; `strings` on any Release binary built with debug info | strip, or map, and **assert the result** rather than assuming `-s` was passed | +| 4 | **the filesystem layout itself** | a mini (initramfs) image shipped `/bin/1bit -> /home////1bit`, with the 4.7 MB binary stored at that path: the initrd disclosed the builder's username, working directory and build-directory name (engine#1543) | place the artefact at a **stable** path with `$ORIGIN`-relative libraries — the layout *is* the leak, so there is nothing to map | + +Two lessons that cost time: + +- **"The binary needs its build path so its RUNPATH resolves" is a claim to check, not a reason.** On the + c26 launcher it was false: `readelf -d` showed **no** `RUNPATH`/`RPATH` at all — it resolves its `NEEDED` + libraries from the standard loader paths, which the image already stages. Check `readelf -d` before + accepting the constraint; the payload and the installed package both use `$ORIGIN` and need no build path. +- **A guard that reads contents cannot see a layout.** `build_path_strings` reads the bytes of packed ELFs + and generated text, so class 4 is invisible to it (engine#1519 widened it to generated text and still + could not see a symlink target). Class 4 needs a row that walks the image's own tree. + +## The guards, and where each lives + +| class | guard | +|---|---| +| 1, 2, 3 (contents) | `scripts/pack-check.sh`'s `build_path_strings` — warning for the shapes a prefix map can fix (`*.s`, `*.mod.c`, `Module.symvers`, `modules.order`) and a **failure** for the shapes it cannot (`*.cmd`, `*.d`: a red there means a build tree was packaged) | +| 4 (layout) | `os/mini/release-check.sh`'s `image-builder-paths` row — a mini image ships no users, so any `/home/*` path in its root is the builder's | + +Both read the **artefact**, not the build tree: a guard that inspects what the build machine looks like +answers a different question from the one that matters. + +## Payload permissions are the neighbour of this class, not part of it + +`group/other-writable` modes in a payload (engine#1352) came from `cp -a` preserving a build tree's modes; +it is not a path leak, and it is fixed where it is measured — `pack_normalise_modes` in +`scripts/pack-elf.sh` for the packers, and the `payload-modes` / base-layer rows for the images. Recorded +here only so the two are not confused: one is "who built this", the other is "who may write to it".