From f1e7a92689e1a70c53f8a2ea24e09a1174b7b5ce Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 17:51:12 -0400 Subject: [PATCH 1/6] os/mini: the image installs the engine instead of shipping the builder's home (Fixes #1543) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mini image installed the engine AT ITS BUILD PATH and pointed /bin/1bit at it, so every image carried /home//.../build/1bit as a directory, with the 4.7 MB binary inside it, and init.sh re-created a hard-coded /home/bcloud/wt/npupkg-build/npu on every boot for the NPU kernel sets. That is the fourth leak class the content rows cannot see: the path is the filesystem LAYOUT - a directory name, a symlink target - not a string inside a packed ELF, so build_path_strings cannot find it. The engine already resolves its backends BESIDE ITSELF when the build tree is gone (app/built_path.h: the compiled path made relative to ONEBIT_BUILD_DIR against /proc/self/exe's directory), which is exactly the layout scripts/package-linux.sh ships. The image uses that now: - mkimage.sh installs the engine at /opt/1bit - a path 1bit-release-check already probes, and what `command -v 1bit` finds through /bin/1bit - with `patchelf --set-rpath '$ORIGIN'`, its libraries beside it, and each backend (vulkan/…, hrx/…) at the relative path built_path looks up, with its own libraries beside it. After relocating, each program's ldd is re-run and the build refuses if anything is still resolved from outside (that is engine #1411's rule, applied here too); the HRX runtime set travels beside llama-server for the same reason. patchelf is now a build requirement of mkimage.sh, checked up front. - init.sh links /data/npu/kernels to /opt/1bit/npu/kernels. No /home path anywhere in the image scripts. - scripts/pack-check.sh gains layout_build_paths: it walks a tree's NAMES and, separately, the TARGETS of its symlinks, because a symlink's target is not file content. tests/pack_check_test.sh grows three arms (a directory named after the builder, a symlink into their home, and a clean control), so the class is covered in CI beside the other four. - mkimage.sh runs that row on the image tree just before packing it, so a layout that names a build machine refuses to become an image instead of shipping. Measured 2026-11-08, the RED arm on the published artifact the issue was filed from (~/wt/issue-709-img/1bit-os.efi, initrd extracted): FAIL /home/bcloud is a path naming a build machine FAIL /home/bcloud/wt/issue-709-build/1bit is a path naming a build machine FAIL /bin/1bit -> /home/bcloud/wt/issue-709-build/1bit: the target names a build machine (5 FAIL lines, rc 1) tests/pack_check_test.sh: 8/8 arms PASS, the three layout ones included. Acceptance for this issue is a BOOT (the risk is RUNPATH resolution, and an image that builds and then cannot start its engine would be worse than the disclosure): an image is built from the c33 build tree with the relocated engine, its initrd checked for the green arm, and a boot attempted; the result is reported on the issue rather than claimed here. --- os/mini/init.sh | 8 +++-- os/mini/mkimage.sh | 63 ++++++++++++++++++++++++++++++++++++---- scripts/pack-check.sh | 25 ++++++++++++++++ tests/pack_check_test.sh | 21 ++++++++++++++ 4 files changed, 108 insertions(+), 9 deletions(-) diff --git a/os/mini/init.sh b/os/mini/init.sh index fb52332b9..9afefc1b0 100755 --- a/os/mini/init.sh +++ b/os/mini/init.sh @@ -157,9 +157,11 @@ 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 +# engine #1543: the link used to name the BUILDER's home directory - a username and a build path compiled +# into this script, and re-created as a directory on every boot. The engine is installed at /opt/1bit with its +# backends beside it (mkimage.sh), so the sets are linked beside the engine there and no /home path exists. +if [ -d /data/npu/kernels ] && [ -d /opt/1bit ]; then + ln -sfn /data/npu/kernels /opt/1bit/npu/kernels 2>/dev/null say "[kernels] $(ls /data/npu/kernels | wc -l) sealed NPU sets linked beside the engine" fi diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index 8c207ae19..8eade0658 100755 --- a/os/mini/mkimage.sh +++ b/os/mini/mkimage.sh @@ -316,12 +316,56 @@ 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. + +# engine #1543: the engine used to be installed AT ITS BUILD PATH, with /bin/1bit a symlink into the +# builder's home and the whole /home//... tree carried in the image (a 4.7 MB binary included), so +# every mini image disclosed the builder's username, work directory and build-directory name. That is a +# fourth leak class - a path delivered as the filesystem LAYOUT, not as a string inside a file - and the +# content rows (scripts/pack-check.sh: build_path_strings) cannot see it. +# +# The engine finds its backends BESIDE ITSELF when the build tree is gone (app/built_path.h: the compiled +# path made relative to ONEBIT_BUILD_DIR, resolved against /proc/self/exe's directory), which is the layout +# scripts/package-linux.sh ships. So it is installed that way here: /opt/1bit (the path 1bit-release-check +# already probes) carrying the engine, its libraries and every backend beside it, $ORIGIN only, and +# /bin/1bit a symlink to that image path - never to a build path. +command -v patchelf >/dev/null || { echo "patchelf is needed to install the engine at \$ORIGIN instead of at its build path: apt install patchelf"; exit 1; } +eng=$root/opt/1bit +install_origin() { # install_origin : the file, $ORIGIN, and its libs beside + local src=$1 dir=$2 f missing + [ -e "$src" ] || { echo "missing: $src"; exit 1; } + mkdir -p "$dir"; cp -L "$src" "$dir/" + patchelf --set-rpath '$ORIGIN' "$dir/$(basename "$src")" + ldd "$src" 2>/dev/null | grep -o '/[^ ]*' | while read -r f; do + [ -e "$dir/$(basename "$f")" ] || cp -L "$f" "$dir/" + done + missing=$(LD_LIBRARY_PATH=$dir ldd "$dir/$(basename "$src")" 2>/dev/null | awk '/not found/ {print $1}' | tr '\n' ' ') + [ -z "${missing// /}" ] || { echo "$(basename "$src") still needs $missing beside it after relocation (engine #1543)"; exit 1; } +} +install_origin "$bin" "$eng" +ln -sfn ../opt/1bit/1bit "$root/bin/1bit" +# the backends, at the relative paths built_path() looks them up, each with its own libraries beside it +for back in vulkan hrx; do + [ -x "$build/$back/llama/bin/llama-server" ] && install_origin "$build/$back/llama/bin/llama-server" "$eng/$back/llama/bin" +done +# the HRX backend's runtime set, which libhsa opens by name at run time (engine #1411): ldd cannot see it, +# so it travels beside llama-server rather than being resolved from whatever the machine offers +if [ -d "$eng/hrx/llama/bin" ]; then + tc=$(sed -n 's/^ONEBIT_HRX_TOOLCHAIN[^=]*=//p' "$build/CMakeCache.txt" 2>/dev/null | head -1) + core=$(ls -d "$tc"/lib/python3*/site-packages/_rocm_sdk_core/lib 2>/dev/null | head -1) + if [ -n "$core" ]; then + for n in libhsa-runtime64.so.1 libhsa-amd-aqlprofile64.so.1 librocprofiler-register.so.0; do + [ -e "$eng/hrx/llama/bin/$n" ] || cp -L "$core/$n" "$eng/hrx/llama/bin/" || exit 1 + done + for f in "$core"/rocm_sysdeps/lib/librocm_sysdeps_*.so*; do + [ -e "$eng/hrx/llama/bin/$(basename "$f")" ] || cp -L "$f" "$eng/hrx/llama/bin/" + done + fi +fi +# 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. Here they live on the stick's data partition (they +# are ~124 MB and grub would not load an initrd that size) and init.sh links them to /opt/1bit/npu/kernels +# at boot. Without them the image ships the NPU route and nothing it can load - the route then refuses +# rather than falling back. echo "== Lemonade (lemond, the lemonade CLI, the web app)" @@ -707,6 +751,13 @@ root_elfs_load() { # : name every ELF in the image root that cannot reso echo "== load check: every ELF in the image root, against the image's own libraries" root_elfs_load "$root" +# engine #1543: the layout row. A build-machine path can arrive as a directory name or as a symlink target, +# where the content rows cannot see it (they read packed ELFs), so the tree itself is checked before it is +# packed. It runs here rather than in the release gate because this is where the layout is still ours to fix. +# shellcheck source=scripts/pack-check.sh +. "$src/scripts/pack-check.sh" +layout_bad=$(layout_build_paths "$root") || { printf '%s\n' "$layout_bad"; echo "the image layout names a build machine: refusing to pack it (engine #1543)"; exit 1; } + echo "== initramfs" # the builder's umask must not reach the image: nothing group- or world-writable, /root private # (Dropbear, like sshd, refuses keys when the home directory is group-writable) diff --git a/scripts/pack-check.sh b/scripts/pack-check.sh index 47c234fd0..7b1f6bebb 100755 --- a/scripts/pack-check.sh +++ b/scripts/pack-check.sh @@ -145,3 +145,28 @@ runtime_selfcontained() { # runtime_selfcontained -> FAIL line [ "$rc" = 0 ] && echo "ok every packed ELF resolves inside the payload or the system loader, declares no absolute RUNPATH, and the HSA runtime set it dlopens ships beside it" return $rc } + +# engine #1543: the FOURTH leak class - a build-machine path delivered as the filesystem LAYOUT rather than as +# a string inside a file. The rows above read packed ELFs, so neither a directory named after the builder nor +# a symlink pointing into their home is visible to them; the mini image shipped +# /bin/1bit -> /home//.../build/1bit and a whole /home/ tree carrying a 4.7 MB binary. +layout_build_paths() { # layout_build_paths [pattern ...] (default pattern: /home/) + local t=$1 rc=0 f p l pat + shift + [ $# -gt 0 ] || set -- /home/ + while IFS= read -r -d '' f; do + p=${f#"$t"} + for pat in "$@"; do + case $p in *"$pat"*) printf 'FAIL %s is a path naming a build machine\n' "$p"; rc=1 ;; esac + done + # a symlink's TARGET is not file content: it has to be read, not searched + if [ -L "$f" ]; then + l=$(readlink "$f") + for pat in "$@"; do + case $l in *"$pat"*) printf 'FAIL %s -> %s: the target names a build machine\n' "$p" "$l"; rc=1 ;; esac + done + fi + done < <(find "$t" -print0) + [ "$rc" = 0 ] && echo "ok no path in the layout (name or symlink target) names a build machine ($*)" + return $rc +} diff --git a/tests/pack_check_test.sh b/tests/pack_check_test.sh index 439d43cbc..b38013169 100755 --- a/tests/pack_check_test.sh +++ b/tests/pack_check_test.sh @@ -108,5 +108,26 @@ printf 'const char *p = "/home/builder/wt/roll/src/app/serve.cpp";\nint g(void) "$cc" -shared -fPIC -o "$w/buildpath/hrx/llama/bin/libbp.so.0" "$w/bp.c" || exit 2 arm "#1461: a build-machine path in a packed ELF fails" fail "names a build-machine path" "$w/buildpath" +# 6. engine #1543: the layout row. A build-machine path as a DIRECTORY NAME and as a SYMLINK TARGET - the +# two shapes the content rows cannot see, because they read file bytes and these are not bytes a grep +# reaches in the same way (a symlink target is not the link's contents). +mkdir -p "$w/layout/home/builder/wt/roll" +cp "$w/clean/hrx/llama/bin/libhrx.so.0" "$w/layout/home/builder/wt/roll/1bit" +ln -s /home/builder/wt/roll/1bit "$w/layout/bin-1bit-link" +arm_layout() { # arm_layout + local want=$1 phrase=$2 t=$3 out rc=0 + out=$(layout_build_paths "$t" 2>&1) || rc=1 + if [ "$want" = pass ]; then + [ "$rc" = 0 ] && echo "PASS layout: a tree with no build-machine path passes" + [ "$rc" = 0 ] || { echo "FAIL layout: expected pass, got rc=$rc"; printf '%s\n' "$out" | head -3 | sed 's/^/ /'; fail=$((fail+1)); } + else + if [ "$rc" != 0 ] && printf '%s' "$out" | grep -q -- "$phrase"; then echo "PASS $want" + else echo "FAIL $want: expected a FAIL naming '$phrase', got rc=$rc"; printf '%s\n' "$out" | head -3 | sed 's/^/ /'; fail=$((fail+1)); fi + fi +} +arm_layout "#1543: a directory named after the builder fails" "is a path naming a build machine" "$w/layout" +arm_layout "#1543: a symlink into the builder's home fails" "the target names a build machine" "$w/layout" +arm_layout pass "" "$w/clean" + if [ "$fail" = 0 ]; then echo "pack_check: all rows PASS"; else echo "pack_check: $fail row(s) FAILED"; fi [ "$fail" = 0 ] From 9c13d1785afd27cd72d389347cac83d9e390ac22 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 17:59:21 -0400 Subject: [PATCH 2/6] pack-check: a row given a tree that does not exist refuses instead of passing (Fixes #1543) Found by my own accident while proving the image fix: I ran `runtime_selfcontained` with an unexpanded variable, so it was handed an empty path, `find` failed, and the row printed "ok" - a green row over nothing, which is the one failure mode a release check cannot have. All three rows refuse a tree that is not there now, and tests/pack_check_test.sh has an arm for it ("a missing tree is refused by all three rows"), so the shape is covered in CI rather than depending on the caller. 8/9 arms were green before this and 9/9 are now. --- scripts/pack-check.sh | 3 +++ tests/pack_check_test.sh | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/scripts/pack-check.sh b/scripts/pack-check.sh index 7b1f6bebb..fdc54427a 100755 --- a/scripts/pack-check.sh +++ b/scripts/pack-check.sh @@ -72,6 +72,7 @@ gen_text() { } build_path_strings() { # build_path_strings -> one FAIL line per offending file, rc 1 local t=$1 f n pats rc=0 elfs=0 text=0 + [ -d "$t" ] || { printf 'FAIL no such tree: %s\n' "${t:-}"; return 1; } pats=$(printf '%s\n' /home/ "${SRC:-/nonexistent-build-src}" "${W:-/nonexistent-build-w}" \ "${BUILD:-/nonexistent-build-build}") while IFS= read -r -d '' f; do @@ -109,6 +110,7 @@ build_path_strings() { # build_path_strings -> one FAIL line p # paths (readelf) and what the loader actually does (ldd), plus the runtime set the dlopen needs present. runtime_selfcontained() { # runtime_selfcontained -> FAIL lines, rc 1 local t=$1 tcanon f n abs rc=0 + [ -d "$t" ] || { printf 'FAIL no such tree: %s\n' "${t:-}"; return 1; } tcanon=$(readlink -f "$t" 2>/dev/null || printf '%s' "$t") while IFS= read -r -d '' f; do pack_is_elf "$f" || continue @@ -152,6 +154,7 @@ runtime_selfcontained() { # runtime_selfcontained -> FAIL line # /bin/1bit -> /home//.../build/1bit and a whole /home/ tree carrying a 4.7 MB binary. layout_build_paths() { # layout_build_paths [pattern ...] (default pattern: /home/) local t=$1 rc=0 f p l pat + [ -d "$t" ] || { printf 'FAIL no such tree: %s\n' "${t:-}"; return 1; } shift [ $# -gt 0 ] || set -- /home/ while IFS= read -r -d '' f; do diff --git a/tests/pack_check_test.sh b/tests/pack_check_test.sh index b38013169..4cfed65f1 100755 --- a/tests/pack_check_test.sh +++ b/tests/pack_check_test.sh @@ -128,6 +128,12 @@ arm_layout() { # arm_layout arm_layout "#1543: a directory named after the builder fails" "is a path naming a build machine" "$w/layout" arm_layout "#1543: a symlink into the builder's home fails" "the target names a build machine" "$w/layout" arm_layout pass "" "$w/clean" +# a row given a tree that does not exist must refuse: an empty path once made runtime_selfcontained print +# "ok" over nothing, which is the one failure mode a green row cannot be allowed to have +out=$( { build_path_strings ""; runtime_selfcontained ""; layout_build_paths "$w/nonexistent"; } 2>&1 ) || true +n=$(printf '%s\n' "$out" | grep -c 'FAIL no such tree') +if [ "$n" = 3 ]; then echo "PASS a missing tree is refused by all three rows" +else echo "FAIL a missing tree: expected 3 refusals, got $n"; printf '%s\n' "$out" | head -4 | sed 's/^/ /'; fail=$((fail+1)); fi if [ "$fail" = 0 ]; then echo "pack_check: all rows PASS"; else echo "pack_check: $fail row(s) FAILED"; fi [ "$fail" = 0 ] From 8d7b0d92b86ade65c5d1b105d8a71c1448e70121 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 17:59:59 -0400 Subject: [PATCH 3/6] os/mini: patch every relocated copy, not just the program (Fixes #1543) The rows caught my own fix being half a fix. `install_origin` set $ORIGIN on the program it installed, and the libraries it copied beside it kept the RUNPATHs they were built with - absolute, into the build tree and the toolchain. At boot libggml would have looked for libggml-base in the builder's tree, which is exactly the dependency the relocation exists to remove, and the image would have built and then failed to start a backend. Measured on the relocated tree the rows now read: runtime_selfcontained -> ok every packed ELF resolves inside the payload or the system loader, declares no absolute RUNPATH, and the HSA runtime set it dlopens ships beside it layout_build_paths -> ok no path in the layout (name or symlink target) names a build machine /bin/1bit -> ../opt/1bit/1bit ; 1bit RUNPATH = $ORIGIN ; and it runs: `1bit 0.0.1` Every ELF in each destination directory gets `patchelf --set-rpath '$ORIGIN'` (they are all in that directory, so $ORIGIN is the whole answer for each), and scripts/pack-elf.sh is sourced at the top of the engine block because install_origin uses pack_is_elf. --- os/mini/mkimage.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index 8eade0658..fa69409d9 100755 --- a/os/mini/mkimage.sh +++ b/os/mini/mkimage.sh @@ -329,6 +329,8 @@ bin=$build/onebit; [ -x "$bin" ] || bin=$build/1bit # already probes) carrying the engine, its libraries and every backend beside it, $ORIGIN only, and # /bin/1bit a symlink to that image path - never to a build path. command -v patchelf >/dev/null || { echo "patchelf is needed to install the engine at \$ORIGIN instead of at its build path: apt install patchelf"; exit 1; } +# shellcheck source=scripts/pack-elf.sh +. "$here/../../scripts/pack-elf.sh" # pack_is_elf, used below and by the Lemonade section eng=$root/opt/1bit install_origin() { # install_origin : the file, $ORIGIN, and its libs beside local src=$1 dir=$2 f missing @@ -338,6 +340,12 @@ install_origin() { # install_origin : the file, ldd "$src" 2>/dev/null | grep -o '/[^ ]*' | while read -r f; do [ -e "$dir/$(basename "$f")" ] || cp -L "$f" "$dir/" done + # EVERY copy, not just the program: a library from the build tree carries the build tree in its own + # RUNPATH, so patching only the program leaves libggml/libhrx/libloomc looking for each other in the + # builder's tree at boot. They are all in $dir now, so $ORIGIN is the whole answer for each of them. + for f in "$dir"/*; do + pack_is_elf "$f" && patchelf --set-rpath '$ORIGIN' "$f" + done missing=$(LD_LIBRARY_PATH=$dir ldd "$dir/$(basename "$src")" 2>/dev/null | awk '/not found/ {print $1}' | tr '\n' ' ') [ -z "${missing// /}" ] || { echo "$(basename "$src") still needs $missing beside it after relocation (engine #1543)"; exit 1; } } From b14c5b02d7e8f36d576cc854679a5b643894253c Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 18:20:59 -0400 Subject: [PATCH 4/6] pack-check: the header lists the layout row too (Refs #1543) The review's one note: the row list at the top of scripts/pack-check.sh documented build_path_strings and runtime_selfcontained, so a reader would not learn that layout_build_paths exists now. Three rows, three lines, each naming the engine issue it answers. --- scripts/pack-check.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/pack-check.sh b/scripts/pack-check.sh index fdc54427a..fd2b8f087 100755 --- a/scripts/pack-check.sh +++ b/scripts/pack-check.sh @@ -21,6 +21,9 @@ # build_path_strings no packed ELF names a build-machine path (engine #1461) # runtime_selfcontained nothing resolves outside the payload, and the HSA runtime set # that libhsa opens at run time ships beside it (engine #1411) +# layout_build_paths no path in the LAYOUT (a directory name, or a symlink's target) +# names a build machine - the fourth class, which the two rows +# above cannot see because they read file contents (engine #1543) # What the engine tarball must and must not hold (docs/releases.md, "Private components"): # It is packed by scripts/package-linux.sh and folded into the Lemonade + onebit package as 1bit/; From 07e4a8d02a46dc7456d3e97d0e026db91c83f462 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 18:43:26 -0400 Subject: [PATCH 5/6] os/mini: no system libraries beside the engine, no backend in the initramfs, and the kernel link reports itself (Refs #1543) The three items from the review at b14c5b02. 1. **The kernel link no longer lies.** init.sh ran `ln -sfn /data/npu/kernels /opt/1bit/npu/kernels 2>/dev/null` and printed "linked beside the engine" whether or not it worked, because nothing created /opt/1bit/npu. It creates the parent first, checks the link resolves, and prints a FAILED line naming the consequence ("the NPU route will register no device") when it does not; a separate line for "the kernels are there but the engine is not at /opt/1bit", which is the shape a boot with a half-applied package would have. The link target is the engine's REAL directory - /proc/self/exe's, i.e. /opt/1bit - not /bin, which is only the symlink on PATH. 2. **No backend goes into the initramfs.** init.sh points ONEBIT_{,HRX_}LLAMA_SERVER at /opt/1bit-llama, which it links from the data partition, and default_llama_server() (app/serve.cpp:292) returns those first - so an HRX llama-server and its runtime set inside the image were never executed, while the initramfs is at 97.9 MB compressed against the 103 MB grub failed to load. The image now installs the engine only, and the run prints how many MB of backend were left to the stick. I could NOT report the before/after initramfs size as asked: ~/wt/c33-payload was removed by the fleet's disk cleanup while this was in review, so there is no build tree to build an image from on this box. The delta is downwards by the backend directory plus the HSA set. 3. **install_origin copies only what the image does not already carry.** It used to copy every ldd entry beside the engine and point RUNPATH at $ORIGIN, so a copied libc.so.6 SHADOWED the image's own for every ELF in that directory - a set that works on the builder and fails at boot. Libraries on the standard loader path (/lib, /lib64, /usr/lib, /usr/lib64) are the loader's business now, on the image as on any machine. Measured, on a synthetic tree (the real build tree is gone): a program linking one private library and two system ones goes through the copy rule and comes out with the private one copied, libz and libc SKIPPED, every copy patched to $ORIGIN, `ldd` reporting nothing missing, and the program running (rc 0). That is the property item 3 is about - no libc shadowing - and it is checkable without an image. bash -n clean on both scripts; shellcheck -S warning unchanged (init.sh's two findings and mkimage.sh's three are all pre-existing, none in these hunks). --- os/mini/init.sh | 13 +++++++++++-- os/mini/mkimage.sh | 31 ++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/os/mini/init.sh b/os/mini/init.sh index 9afefc1b0..b4e9b118b 100755 --- a/os/mini/init.sh +++ b/os/mini/init.sh @@ -161,8 +161,17 @@ fi # into this script, and re-created as a directory on every boot. The engine is installed at /opt/1bit with its # backends beside it (mkimage.sh), so the sets are linked beside the engine there and no /home path exists. if [ -d /data/npu/kernels ] && [ -d /opt/1bit ]; then - ln -sfn /data/npu/kernels /opt/1bit/npu/kernels 2>/dev/null - say "[kernels] $(ls /data/npu/kernels | wc -l) sealed NPU sets linked beside the engine" + # the parent has to exist before the link, or ln fails and the message below lies about it (engine #1543 + # review item 1): the engine looks for /npu/kernels, and its directory is the real one + # /proc/self/exe resolves to - /opt/1bit - not /bin, which is only the symlink on PATH + mkdir -p /opt/1bit/npu + if ln -sfn /data/npu/kernels /opt/1bit/npu/kernels 2>/dev/null && [ -d /opt/1bit/npu/kernels ]; then + say "[kernels] $(ls /data/npu/kernels | wc -l) sealed NPU sets linked beside the engine" + else + say "[kernels] FAILED to link /data/npu/kernels beside the engine: the NPU route will register no device" + fi +elif [ -d /data/npu/kernels ]; then + say "[kernels] /data/npu/kernels is there but the engine is not at /opt/1bit: nothing to link beside" fi n=0 diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index fa69409d9..f80b2ba32 100755 --- a/os/mini/mkimage.sh +++ b/os/mini/mkimage.sh @@ -337,7 +337,12 @@ install_origin() { # install_origin : the file, [ -e "$src" ] || { echo "missing: $src"; exit 1; } mkdir -p "$dir"; cp -L "$src" "$dir/" patchelf --set-rpath '$ORIGIN' "$dir/$(basename "$src")" - ldd "$src" 2>/dev/null | grep -o '/[^ ]*' | while read -r f; do + # ONLY what the image does not already carry. The image has libc, libstdc++, libgcc_s and the loader; + # copying those beside the engine and then pointing RUNPATH at $ORIGIN makes the copy SHADOW the image's + # own libc for every ELF in that directory - a set that works on the builder and fails at boot. A library + # on the standard loader path is the loader's business, on the image as on any machine. + for f in $(ldd "$src" 2>/dev/null | awk '/=> \// {print $3}'); do + case "$f" in /lib/*|/lib64/*|/usr/lib/*|/usr/lib64/*) continue ;; esac [ -e "$dir/$(basename "$f")" ] || cp -L "$f" "$dir/" done # EVERY copy, not just the program: a library from the build tree carries the build tree in its own @@ -351,24 +356,16 @@ install_origin() { # install_origin : the file, } install_origin "$bin" "$eng" ln -sfn ../opt/1bit/1bit "$root/bin/1bit" -# the backends, at the relative paths built_path() looks them up, each with its own libraries beside it +# NO backend goes into the initramfs. init.sh points ONEBIT_{,HRX_}LLAMA_SERVER at /opt/1bit-llama, which it +# links from the stick's data partition at boot, and default_llama_server() (app/serve.cpp:292) returns those +# first - so an HRX llama-server and its ~40 MB runtime set inside the image were never executed, while the +# initramfs is already 97.9 MB compressed against the 103 MB that grub failed to load on real hardware. One +# copy, and it is the one on the stick (mkimage.sh puts it there below, engine #1543's review item 2). for back in vulkan hrx; do - [ -x "$build/$back/llama/bin/llama-server" ] && install_origin "$build/$back/llama/bin/llama-server" "$eng/$back/llama/bin" -done -# the HRX backend's runtime set, which libhsa opens by name at run time (engine #1411): ldd cannot see it, -# so it travels beside llama-server rather than being resolved from whatever the machine offers -if [ -d "$eng/hrx/llama/bin" ]; then - tc=$(sed -n 's/^ONEBIT_HRX_TOOLCHAIN[^=]*=//p' "$build/CMakeCache.txt" 2>/dev/null | head -1) - core=$(ls -d "$tc"/lib/python3*/site-packages/_rocm_sdk_core/lib 2>/dev/null | head -1) - if [ -n "$core" ]; then - for n in libhsa-runtime64.so.1 libhsa-amd-aqlprofile64.so.1 librocprofiler-register.so.0; do - [ -e "$eng/hrx/llama/bin/$n" ] || cp -L "$core/$n" "$eng/hrx/llama/bin/" || exit 1 - done - for f in "$core"/rocm_sysdeps/lib/librocm_sysdeps_*.so*; do - [ -e "$eng/hrx/llama/bin/$(basename "$f")" ] || cp -L "$f" "$eng/hrx/llama/bin/" - done + if [ -e "$build/$back/llama/bin/llama-server" ]; then + echo " $back backend: left to the data partition ($(du -sm "$build/$back/llama/bin" 2>/dev/null | cut -f1) MB not in the initramfs)" fi -fi +done # 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. Here they live on the stick's data partition (they # are ~124 MB and grub would not load an initrd that size) and init.sh links them to /opt/1bit/npu/kernels From b6778dcb6bd89f0b538921576f22bf7bebcdee52 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 19:11:02 -0400 Subject: [PATCH 6/6] os/mini: the engine's system libraries still reach the image, and the load check sees the host (Refs #1543) Fix 3 opened a hole and the review is right about it: `install_origin` refuses to put a SYSTEM library beside the engine (with $ORIGIN it would shadow the image's own libc), but nothing then staged them into the image either - `copy_elf "$bin"` used to do that through `copy_libs`, and replacing it dropped it. The engine's NEEDED set is libgomp, libpcre2-8, libcrypto, libzstd, libgcc_s, libstdc++, libm and libc, and libgomp/libpcre2-8 have no other ELF in the image pulling them in, so the image could build green and die at boot on "error while loading shared libraries: libgomp.so.1". Both halves, as asked: 1. `copy_libs "$bin"` after `install_origin`, so the engine's NEEDED set lands at its system paths in $root - the job copy_elf did, restored where the layout change removed it. 2. `root_elfs_load` now fails any library ldd reports as "=> /path" outside the image. That is the blind spot: ldd falls back to the BUILD HOST's loader cache, so a NEEDED entry the image does not have resolves here anyway, and the old grep for "not found"/"undefined symbol" never saw it. The vdso and the interpreter are unaffected - neither is reported as "=> /path". Measured on a synthetic root (the real build tree was cleaned up), which is the same blind spot the review named - so the check is what has to be shown, not the host's ldd: program in the root with its private library beside it, system libraries NOT in the root -> ELF would resolve outside the image: /usr/lib/x86_64-linux-gnu/libz.so.1, libzstd.so.1, libc.so.6 (the old rows said nothing: ldd resolved all three from this host) after copy_libs stages the NEEDED set at its paths in the root -> resolved outside the image: none ; unresolved symbols: 0 bash -n clean; shellcheck -S warning unchanged (three pre-existing findings in this file, none in these hunks). --- os/mini/mkimage.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/os/mini/mkimage.sh b/os/mini/mkimage.sh index f80b2ba32..3df472409 100755 --- a/os/mini/mkimage.sh +++ b/os/mini/mkimage.sh @@ -355,6 +355,11 @@ install_origin() { # install_origin : the file, [ -z "${missing// /}" ] || { echo "$(basename "$src") still needs $missing beside it after relocation (engine #1543)"; exit 1; } } install_origin "$bin" "$eng" +# install_origin refuses to put a SYSTEM library beside the engine ($ORIGIN would make it shadow the image's +# own), but the image still has to carry them: copy_elf used to stage the engine's whole NEEDED set at its +# system paths through copy_libs, and replacing it dropped that. libgomp and libpcre2-8 in particular have no +# other ELF in the image pulling them in (engine #1543 review, fix 3's hole). +copy_libs "$bin" ln -sfn ../opt/1bit/1bit "$root/bin/1bit" # NO backend goes into the initramfs. init.sh points ONEBIT_{,HRX_}LLAMA_SERVER at /opt/1bit-llama, which it # links from the stick's data partition at boot, and default_llama_server() (app/serve.cpp:292) returns those @@ -745,6 +750,18 @@ root_elfs_load() { # : name every ELF in the image root that cannot reso echo " ELF does not load: ${f#"$root"}" printf '%s\n' "$res" | grep -E "undefined symbol|not found" | sed 's/^/ /' fi + # ... and a library ldd resolved from the BUILD HOST is not one the image has: ldd falls back to this + # machine's loader cache, so a NEEDED entry the image is missing still resolves here and "loads". + # Every path it reports has to be inside the image; the vdso and the interpreter are the exceptions, + # and neither appears as "=> /path" (engine #1543 review). + outside=$(printf '%s\n' "$res" | awk '/=> \// {print $3}' | while IFS= read -r p; do + case "$p" in "$root"/*) ;; *) printf '%s\n' "$p" ;; esac + done | head -3) + if [ -n "$outside" ]; then + bad=$((bad + 1)) + echo " ELF would resolve outside the image: ${f#"$root"}" + printf '%s\n' "$outside" | sed 's/^/ /' + fi done < <(find "$root" -type f -print0 2>/dev/null) echo " load check: $n ELF files in the image root, $bad that cannot resolve their symbols" if [ "$bad" != 0 ]; then