From fdbab3e18f8cf16a2ea2dfc66a8e0e251cf76caf Mon Sep 17 00:00:00 2001 From: pi-tmplsec Date: Sun, 8 Nov 2026 17:51:10 -0400 Subject: [PATCH 1/3] os/mini: the engine ships at /bin/1bit as a real file, so the initrd stops naming its builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `mkimage.sh` copied the engine to its **build path** inside the initramfs and symlinked `/bin/1bit` at it, so a shipped image disclosed the builder's username, working directory and build-directory name — and carried a second 4.7 MB copy of the binary at that path (engine#1543). Measured on a real artefact: $ zstd -dc initramfs.img | cpio -itv | grep -E 'bin/1bit|home/' lrwxrwxrwx bin/1bit -> /home/bcloud/wt/issue-709-build/1bit drwxr-xr-x home/bcloud drwxr-xr-x home/bcloud/wt drwxr-xr-x home/bcloud/wt/issue-709-build -rwxr-xr-x home/bcloud/wt/issue-709-build/1bit # 4,692,512 B, sha 89a6c386… The constraint the code documented ("the binary keeps its build path so its RUNPATH resolves") does not hold for this binary: `readelf -d` on the c26 launcher shows **no** RUNPATH/RPATH at all — it resolves its NEEDED libraries (libgomp, libpcre2-8, libcrypto, libzstd, libgcc_s, libstdc++, libm, libc) from the standard loader paths, which `copy_libs` already stages into the image. So the build path bought nothing. Before/after, staged from the same binary with the same commands the script runs: before (cp -L "$bin" "$root$bin" + ln -s): /home paths in the staged tree = 4 after (cp -L "$bin" "$root/bin/1bit"): /home paths in the staged tree = 0 engine sha: build 89a6c386… == staged 89a6c386… (the image carries the same engine, at a stable path) `copy_libs` stays: it walks NEEDED, not the path. No NPU kernel set is staged into the mini image (the route refuses rather than falling back); if one ever is, it now goes beside `/bin/1bit`. And the class gets a guard, because the content guard cannot see it: `build_path_strings` reads the bytes of packed ELFs and generated text, so a symlink target is invisible to it. `release-check.sh` gains `image-builder-paths`: a mini image ships no users, so any `/home/*` path in its root is the builder's. The row is mini-only (a stick's base layer has real users), keyed on the mini identity schema (`engine: `), with four `--self-test` cases. `policies/build-path-leak-classes.md` is the taxonomy the issue cites and the repo did not have: the four classes (baked into a binary / a packaged build tree / a symbol table / the filesystem layout), the remedy and the guard for each, and the two lessons — "needs its build path for RUNPATH" is a claim to check (readelf), and a content guard cannot see a layout. Fixes #1543 --- os/mini/mkimage.sh | 20 ++++++---- os/mini/release-check.sh | 39 +++++++++++++++++++ policies/build-path-leak-classes.md | 59 +++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 policies/build-path-leak-classes.md diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index 8c207ae19..67424379f 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)" diff --git a/os/mini/release-check.sh b/os/mini/release-check.sh index d1f35b7ad..0264eb5e5 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,22 @@ 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 +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". From 10c67017ef67a35c77d7e1dda7a09c5d9014a030 Mon Sep 17 00:00:00 2001 From: pi-tmplsec Date: Sun, 8 Nov 2026 17:51:33 -0400 Subject: [PATCH 2/3] os/mini: the identity's engine hash follows the engine to /bin/1bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous commit moves the engine from its build path to `/bin/1bit`; the identity writer hashed `"$root$bin"` — the *image's copy at the build path* — and said so in a comment whose premise ("/bin/1bit is a symlink to it") this change removes. Unpatched, every mini image would have written `engine_sha256: none` and the row #1481 added would have had nothing to check. It now hashes the staged copy at `$root/bin/1bit`, which is still post-`cp -L` and still not the build tree, for the same reason as before: the bytes that matter are the ones the image carries. --- os/mini/mkimage.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index 67424379f..4aafeca5d 100755 --- a/os/mini/mkimage.sh +++ b/os/mini/mkimage.sh @@ -477,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 From d0429c67f936420ee016bb32dbb835ef702d1505 Mon Sep 17 00:00:00 2001 From: pi-tmplsec Date: Sun, 8 Nov 2026 18:37:51 -0400 Subject: [PATCH 3/3] os/mini: the NPU kernel link follows the engine to /bin/1bit, and the row checks the coupling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moving the engine off its build path (previous commits) breaks one call site that no content guard would find, because it is a *link target*, not a string in a binary: `init.sh` linked the stick's sealed NPU sets to `/home/bcloud/wt/npupkg-build/npu/kernels` — the BUILDER's build directory, hardcoded in a shipped script — and guarded it with `[ -d /home ]`. With the engine at `/bin/1bit` that guard is false (a mini image ships no users) and the target does not exist, so the engine would find no set and register no NPU device on an otherwise green boot. The engine looks for its sets beside itself (os/mini/mkimage.sh: "init.sh links them to the engine's expected path at boot, so the engine still finds npu/kernels beside itself"), so "beside the engine" is now /bin/npu/kernels: - if [ -d /data/npu/kernels ] && [ -d /home ]; then - mkdir -p /home/bcloud/wt/npupkg-build/npu; ln -sfn /data/npu/kernels /home/bcloud/wt/npupkg-build/npu/kernels + if [ -d /data/npu/kernels ]; then + mkdir -p /bin/npu; ln -sfn /data/npu/kernels /bin/npu/kernels and release-check gains `npu-kernels-beside-engine`, which reds when /data/npu/kernels exists and /bin/npu/kernels does not — so this exact failure (a green boot with no device) is a row rather than a discovery. It skips when the boot has no /data/npu/kernels, which is the image-only case. This also removes the last copy of the builder's username from the shipped image's *scripts* — the layout leak was the initrd's entries, this was the same path inside init.sh. Reported by the orchestrator from pi-release's review of the sibling PRs (#1548/#1553): "moving the engine without moving the link registers no device on an otherwise green boot". --- os/mini/init.sh | 14 +++++++++----- os/mini/release-check.sh | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) 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/release-check.sh b/os/mini/release-check.sh index 0264eb5e5..1643df8b9 100755 --- a/os/mini/release-check.sh +++ b/os/mini/release-check.sh @@ -1913,6 +1913,15 @@ if [ -n "$(sed -n 's/^engine: *//p' "${ID:-/etc/1bit/release-identity}" 2>/dev/n 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