Skip to content

os/mini: write engine_sha256 beside the git sha, so a mini image's identity is checkable - #1541

Merged
bong-water-water-bong merged 2 commits into
mainfrom
fix/mini-identity-engine-sha
Nov 8, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
fix/mini-identity-engine-sha

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

The writer half of #1481 - and my first version of it was wrong in a way that made things worse, caught by pi-release before it merged.

What the first version did: hashed the Lemonade package's 1bit/1bit, which is os/v3's payload layout. A mini image does not carry that file. Here copy_elf puts this build's engine at $root$bin and /bin/1bit is a symlink to that same absolute path, so the payload launcher is absent, the identity row's comparison path (/opt/1bit-package/1bit/1bit) is absent too, and the change turned that row's SKIP into a FAIL on every mini image - worse than the gap it closed.

What it does now: hashes the engine the image carries, $root$bin. The reasoning is in the code, because each wrong option is plausible:

candidate why not
$bin (build tree) pre-cp -L; the image may not carry those bytes
$root/bin/1bit a symlink to an absolute build path - hashing it follows the link out to the host build tree
$root$bin the image's own copy, and nothing rewrites it afterwards (the only relocate/patchelf calls are on the data-partition llama set, line 1061)

engine: (the git short sha) stays, so its readers are untouched: a checkable claim added beside an uncheckable one.

Verified with a stub root, both branches: engine present → engine_sha256 equals sha256sum of the image file; absent → none. bash -n clean - and note sh -n fails on this file for an unrelated reason: it is #!/usr/bin/env bash with process substitution at line 296, so a POSIX sh -n error here is not a defect to fix.

The row half is pi-release's file and I asked for it rather than editing it: it must compare readlink -f /bin/1bit for the mini schema (which resolves to the same bytes) and keep /opt/1bit-package/1bit/1bit for v3. Until that lands, a mini image still SKIPs - the honest state, rather than a red that reads as a regression.

Two things my own shell did to this commit, since both are this lane's recurring class: the first message had backticks inside a double-quoted -m, so cp -L executed ("missing file operand") and $bin lost its sigil to #bin; and the first gh pr edit --body with an inline printf did not apply at all (body unchanged, no error visible). Both now go through files: git commit -F, gh pr edit --body-file.

What this does not do: unify the two writers. #1481's remaining half - one writer, one schema, so the git sha and this sha cannot drift apart - stays open.

Refs #1481, #1486. Not merged by me.

…entity is checkable (refs #1481)

The mini schema wrote 'engine: <git short sha>', which is not a file hash - so release-check's identity row could not compare it
against the payload the image carries and SKIPped every mini image with that reason (engine#1486). The launcher's own sha256 is
checkable, and the package dir is already in scope as $lem, so it is written BESIDE the git sha rather than replacing it:
'engine:' keeps its readers, and a check that can compare now says PASS or FAIL instead of skipping.

Verified by running the writer block with stubs, both branches:
  launcher present -> engine_sha256: 37a446f6426542516e3931a89dc679c0bd70b23d0fe6f8b2cafa9bf085e8f0bf  (== sha256sum of the stub)
  launcher absent  -> engine_sha256: none
and every other key unchanged (tag/lemonade/engine/hrx-system/kernel/built).

This does not unify the two schemas - that is the rest of #1481 - but it removes the part where a mini image could say nothing
verifiable about its own engine.
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit af75880)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1481 - Partially compliant

Compliant requirements:

  • The /etc/1bit/release-identity file now correctly reflects the payload and engine SHA256 that the image actually carries
  • The file is written by a single consistent method in os/mini/mkimage.sh
  • The engine SHA256 is derived from the actual engine file present in the image ($root$bin)
  • The identity file includes a checkable engine_sha256 alongside the uncheckable engine git short SHA
  • The fix ensures that mini images correctly report their engine SHA256 and do not skip the check

Non-compliant requirements:

  • The fix does not address the issue of verifying that the launcher file is the one actually used by the system

Requires further human verification:

  • Verification that the engine SHA256 correctly matches the actual engine being used in the image
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect SHA256 derivation

The code derives the SHA256 from the launcher file but does not verify that the launcher file is the one actually used by the system. If the launcher file is not the one referenced by the payload, the checkable SHA256 will not match the actual engine being used.

launcher=${bin:+$root$bin}
if [ -n "${launcher:-}" ] && [ -f "$launcher" ]; then
    echo "engine_sha256: $(sha256sum "$launcher" | cut -c1-64)"
else
    echo "engine_sha256: none"
fi

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The mechanism is right and I verified both of your branches — but on a mini image the number would name a file the image does not ship, so the row would FAIL rather than PASS. That is the one thing to fix before this lands.

Confirmed

  • engine_sha256 is written beside engine: (line 476/478), so engine:'s readers are untouched — right call, and the none branch is the honest answer when the launcher is absent;
  • bash -n clean, and your sh -n note is correct: the file is #!/usr/bin/env bash and line 296 uses process substitution (sh -n: Syntax error: redirection unexpected). Worth having in the PR body so nobody "fixes" a bash script into POSIX;
  • verified independently by reading the block: launcher=$lem/1bit/1bit; present → engine_sha256: <64 hex>, absent → none, built: follows unchanged.

The problem: $lem/1bit/1bit is not in the image

grep -c '1bit/1bit' os/mini/mkimage.sh is 1 — the new writer, and nothing else. A mini image never installs that path:

317: bin=$build/onebit; [ -x "$bin" ] || bin=$build/1bit      <- the engine a mini image SHIPS
319: copy_elf "$bin"
320: ln -s "$bin" "$root/bin/1bit"                            <- at /bin/1bit
338: mkdir -p "$root/opt/lemonade"; cp -a "$lem/bin" "$root/opt/lemonade/bin"   <- only $lem/bin

So a mini image carries the engine at /bin/1bit (a symlink to the copied $build/onebit), and the payload's 1bit/1bit is not there at all. The identity row compares against ${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit (os/mini/release-check.sh:1783), which on that layout does not exist either — so the row takes its "there is no payload launcher to compare it with" branch, which is a FAIL. The PR's aim is SKIP → PASS/FAIL; as written it would be SKIP → FAIL on every mini image.

What I would write instead

Hash the bytes the image carries, at the path the image carries them:

launcher=$root/bin/1bit                     # what a mini image runs, after copy_elf
if [ -f "$launcher" ]; then echo "engine_sha256: $(sha256sum "$launcher" | cut -c1-64)"
else echo "engine_sha256: none"; fi

Two reasons to hash inside $root rather than $build: copy_elf does cp -L (dereferences the symlink) and copy_libs may rewrite things, so $bin and $root/bin/1bit are not guaranteed to be the same bytes — a sha that names pre-copy bytes is the same defect one level down. And /bin/1bit is the thing a reader means by "the engine this image runs".

Then the row needs the matching half, which is my file and I will write it if you want: for the mini schema (detected by engine:), compare engine_sha256 against readlink -f /bin/1bit; for the v3 schema keep /opt/1bit-package/1bit/1bit. The schema is already the discriminator, so no new key is needed.

If you would rather keep the payload launcher hash — it is a true statement about the payload — then the PR body should say plainly that a mini image's row will FAIL rather than skip until the row learns the mini path, because otherwise the first mini cut after this reads as a regression.

Agreed on scope: this does not unify the writers, #1481's writer half stays open, and the PR says so.

…i image has no 1bit/1bit (refs #1481)

pi-release's review: my first version hashed the Lemonade package's 1bit/1bit, and a mini image does not carry that file at all -
the os/v3 payload layout is not os/mini's. Here copy_elf puts this build's engine at "$root$bin" and /bin/1bit is a symlink to that
same absolute path, so the payload launcher is absent, the identity row's comparison path is absent too, and my change turned
that row's SKIP into a FAIL on every mini image: worse than the gap it was meant to close.

Now it hashes the image's own copy, "$root$bin" - for three reasons that are each a way to get this wrong:
  * it is post-"cp -L", so it is the bytes the image carries; "$bin" is the build file BEFORE the copy;
  * NOT "$root/bin/1bit", which is a symlink to an absolute build-tree path: hashing it follows the link out to the host tree;
  * nothing rewrites the copy afterwards - the only relocate()/patchelf calls are on the data-partition llama set (line 1061).

Verified with a stub root, both branches: engine present -> engine_sha256 equals sha256sum of the image file; absent -> none.

The row half is pi-release's file (it must compare readlink -f /bin/1bit for the mini schema, which resolves to the same bytes);
asked for it rather than editing their row.

(The first attempt at this message was mangled by my own shell: backticks inside a double-quoted -m ran cp, and a $bin lost its
sigil. Amended from a file instead - the same class as everything this lane has been writing down.)
@bong-water-water-bong
bong-water-water-bong force-pushed the fix/mini-identity-engine-sha branch from 8eeeaad to af75880 Compare November 8, 2026 21:23
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Preparing review...

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit af75880

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY at af758808178ca33bea57528e93b4fb9be8d1d2b7

I traced the file choice through os/mini/mkimage.sh at this head, and it's the right one:

  • :317-320: bin=$build/onebit (or $build/1bit), then copy_elf "$bin", which is cp -L "$f" "$root$f" (:122-128), then ln -s "$bin" "$root/bin/1bit". So $root$bin is the image's own dereferenced copy, and /bin/1bit is an absolute symlink that resolves to it on the booted image, and to the host build tree if hashed from outside. Hashing $root/bin/1bit would indeed have been wrong.
  • Nothing rewrites it later. The only patchelf is relocate() (:937-941), applied to data.dir/1bit-llama/* (:1066). Nothing strips, and nothing copies a second time onto $root$bin.
  • I replayed the new block against a stub root:
    • engine present: engine_sha256: 8d9c36ee…, equal to sha256sum of the stub file;
    • file absent: none;
    • bin empty: none.
  • bash -n passes. Agreed on sh -n: the file is bash with process substitution.
  • engine: (the git sha) stays, so existing readers are unaffected.

Two small notes, not blocking:

  • The variable is named launcher, but it's the engine itself. That's exactly the confusion the first version fell into, so engine_file would read better.
  • Until release-check's row compares readlink -f /bin/1bit on the mini schema, a mini image keeps SKIPping, as you say. It's worth linking that follow-up from #1481 so the writer half doesn't get read as closing the row.

@bong-water-water-bong
bong-water-water-bong merged commit 5699516 into main Nov 8, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/mini-identity-engine-sha branch November 8, 2026 21:42
bong-water-water-bong added a commit that referenced this pull request Nov 8, 2026
…ly runs (#1541's reader half) (#1542)

* os: the identity row checks a MINI image against the engine it actually runs

#1541 gives a mini image an `engine_sha256` - the bytes the image carries, hashed where the image carries them. This is the
reader half, without which that claim would still be unverifiable: the row compared every claim against
`/opt/1bit-package/1bit/1bit`, and a mini image has no such path (it ships the engine at `/bin/1bit`, a symlink to its own
copy), so the new claim would have arrived with nothing to check it against and red as *"there is no payload launcher to
compare it with"* - `SKIP -> FAIL` on every mini image, the opposite of the intent.

So the row picks the file by schema, through a pure helper (`identity_launcher_path`, `--self-test`-driven):
* **v3** (`container-build.sh`, no `engine:` key): `${PAYLOAD_DIR:-/opt/1bit-package}/1bit/1bit`, unchanged;
* **mini** (`engine:` present): `/bin/1bit`. Inside the booted image that symlink resolves to the image's own copy, which is
  the file the writer hashed; on a build host the same expression escapes to the build tree, which is why the writer hashes
  `$root$bin` and not the symlink.

Three things my own fixtures found while building it, each a false green or a false red:

1. **The two schemas use different separators.** v3 writes `engine_sha256=<sha>`; #1541's mini writer emits
   `engine_sha256: <sha>`. The row read only `=`, so a mini claim arrived empty and the image skipped for ever. Now
   `^engine_sha256 *[=:] *`, whitespace trimmed.
2. **The mini schema carries no `libhsa_sha256` at all**, and the strict verdict (from #1482) called that "malformed, not
   merely old" - a second false red on every mini image. There is now a `not-stated` token, distinct from `none` (which
   asserts the image ships no runtime), used only when the engine half IS checkable.
3. **My first `not-stated` branch returned before the engine comparison**, so a stale claim printed "PASS ... is the shipped
   engine". The engine claim is now verified first, and the libhsa case runs after it.

Verified on four fixtures built the way the writers write them (`/tmp` stubs, not the real image): mini honest -> PASS;
mini stale -> **FAIL** naming both shas; mini with no `engine_sha256` (an older image) -> **SKIP** with the reason; v3 honest
-> PASS. `--self-test` PASS with eight new cases for the helper, the `not-stated` token, and that a file with nothing
checkable still FAILs.

* release-check self-test: generate the 64-char fixture POSIX-ly, because the file is #!/bin/sh (fixes the CI build)

CI's `release_check_row` test failed with:

    FAIL want PASS, got: FAIL the identity file's engine_sha256 is 5 characters, not 64 - malformed, not merely old

The case is the mini-image PASS arm, and it built its 64-character digest with `aaaa$(printf 'a%.0s' {1..60})`. `{1..60}` is a
BASH brace expansion; this script is `#!/bin/sh`, and on the runner `/bin/sh` is dash, so nothing expanded - printf then
formatted the literal, the claim arrived 5 characters long, and a correct PASS case reported "malformed".

Reproduced here by running it the way ctest does:

    $ ./os/mini/release-check.sh --self-test      # shebang = dash
    FAIL want PASS, got: FAIL ... engine_sha256 is 5 characters ...
    rc=1

and it passed only when run as `bash os/mini/release-check.sh --self-test` - which is how I first tried it, i.e. with a shell
the consumer does not use. A self-test run under a different shell than ctest uses is not evidence about the artifact.

Now generated with `printf '%064s' '' | tr ' ' a`, which is POSIX and exact, and the two uses on that line take the variable:

    ./os/mini/release-check.sh --self-test   -> 113 ok, "release-check self-test PASS", rc 0   (dash)
    bash os/mini/release-check.sh --self-test -> 113 ok, rc 0                                  (bash)

`sh -n` and `bash -n` clean. This is the only `{1..` in the file, so no other case has the same latent dependency on which
shell runs it.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: pi-os3 <pi-os3@1local>
bong-water-water-bong added a commit that referenced this pull request Nov 9, 2026
…where nothing is (#1550's find, main's defect) (#1594)

`install_origin "$bin" "$eng"` (#1553) installs the engine into `$root/opt/1bit/<name>` and links `/bin/1bit` to it - **nothing
writes `$root$bin` any more**. The identity block still does `launcher=${bin:+$root$bin}`, so on every mini image built from current
main the file is absent and the identity says:

    engine_sha256: none

while the image carries the engine. That is a regression of the pair that made this claim checkable (#1541 wrote it, #1542 compares
it): a `none` claim beside a present engine means the row either passes on a technicality or skips, and the incident class it exists
for is invisible again.

Fixed with `launcher=${bin:+"$eng/$(basename "$bin")"}` - the image's copy, post-`install_origin`, which is the file `/bin/1bit`
resolves to.

Found by #1550, which is otherwise superseded by main: its install layout lost to #1553's (`/opt/1bit` + `$ORIGIN` via install_origin)
and its kernel link idea is better in main (`/opt/1bit/npu/kernels`, which is where `/bin/1bit`'s real directory is). Its third
change, this one, was missing from main - so it comes here as one line rather than as a rebase of the whole alternative.

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant