Skip to content

1bit-update --latest: install only the release it asked for, newer than this one - read from the VERIFIED image (rollback protection, security) - #3454

Merged
bong-water-water-bong merged 2 commits into
mainfrom
cl-release/update-identity-check
Nov 24, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
cl-release/update-identity-check

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Security fix 1 of 2 that must land before any image ships the updater (orchestrator, from cl-kernel's review). Stacked on #3451, the private work dir: this branch contains #3451's commit, so merge #3451 first and this diff shrinks to its own commit.

The problem: --latest trusted GitHub's tag_name, which is not signed. An old, genuinely signed image re-published under a newer tag passes verify-image (its signature and digest are real) and would install: a rollback to a release with known holes.

The fix:

  • Record the request: update_latest records what it asked for (tag, channel, running release). expect_tag is initialised empty in every run, so the environment can never set it.
  • Read the truth from the image: after the image's own files are verified, and before a byte is written to the other slot, the install reads the tag the image itself carries: etc/1bit/release-identity inside its puppy_*.sfs, via unsquashfs -cat, the same way the shadow code already reads it.
  • update_identity_check refuses:
    • an image with no identity;
    • a tag other than the one asked for, i.e. the re-published old image;
    • a release not strictly newer than the running one. Order is vYYYY.WW[-rcN], a final after its own rcs (update_ver_gt);
    • an -rc on the stable channel;
    • no running identity to compare with.
  • Unchanged: 1bit-update <image> and --rollback stay deliberate, manual downgrades.

Measured: tests/update_identity_test.sh (new, ctest update_identity) covers every refusal above, the two cases that install (newer stable, rc on test), the version order, the tag read out of a real puppy_*.sfs built with mksquashfs, and expect_tag initialised. 11/11 under dash (env -i), busybox ash and as root. update_check, update_latest and update_workdir: ok. Pre-PR checks after committing: 17 green, 3 skipped.

🤖 Generated with Claude Code

bong-water-water-bong and others added 2 commits November 23, 2026 23:49
…t-update; /data/updates must be root-only (security)

Security review (cl-npuconc via the orchestrator, 24 Nov): the root-run updater used a FIXED, world-writable-parent
path, /tmp/1bit-update, for releases.json, check.err, the ESP mount, the image's data-partition mount and sums. A
directory or symlink planted there in advance decides where root writes, mounts and reads back.
- work_dir: one directory per run from mktemp -d (a fresh random name, created atomically with mode 0700; nothing
  pre-existing is followed): under /run for root (root's own tmpfs; /tmp is world-writable and on Puppy a symlink),
  under $TMPDIR for a person's --check. Every former /tmp/1bit-update path is $WORK/....
- work_done removes it at exit, AFTER the image and ESP are unmounted, and never while a mount is left inside it (the
  ESP is mounted there: rm -rf over a live mount would empty the ESP).
- safe_dir for /data/updates and each /data/updates/<tag>: created 0700; an existing one is accepted only as a real
  directory (not a symlink) owned by root and not group/other-writable - /data is shared with people's files.
tests/update_workdir_test.sh (new, ctest update_workdir): a symlink planted at the old path receives nothing, the work
dir is gone after the run, it is new/0700/random (under /run as root, $TMPDIR otherwise) and never shared; safe_dir
refuses a symlink (target untouched), a non-root owner, a file. Passes as a user AND as root (CI's container), dash +
busybox ash; update_check/latest/shadow and one_bit_update_slots: ok as user and root.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…an this one - read from the VERIFIED image (rollback protection, security)

Security review (cl-kernel via the orchestrator, 24 Nov): --latest trusted GitHub's tag_name, which is not signed. An
old, genuinely signed image re-published under a newer tag would pass verify-image and install - a rollback to a
release with known holes.
- update_latest records what it asked for (tag, channel, running release); expect_tag starts empty in every run, so
  the environment can never set it.
- After the image's own files are verified and BEFORE a byte is written to the other slot, the install reads the tag
  the image carries (etc/1bit/release-identity inside its puppy_*.sfs, unsquashfs -cat) and update_identity_check
  refuses: no identity; a tag other than the one asked for (the re-published image); not STRICTLY newer than the
  running release (vYYYY.WW[-rcN], a final after its own rcs: update_ver_gt); an -rc on the stable channel; no running
  identity to compare with. 1bit-update <image> and --rollback stay deliberate, manual downgrades.
tests/update_identity_test.sh (new, ctest update_identity): every refusal, the two installs, version order, the tag
read out of a real puppy_*.sfs, expect_tag initialised: 11/11 under dash (env -i), busybox ash and as root.
update_check / update_latest / update_workdir: ok. Stacked on #3451 (private work dir).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 24, 2026 03:53
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

LGTM (cl-kernel, the reviewer of record for the rollback finding; reviewed at head dbba8ea9).

This closes the rollback hole I raised on #3442/#3447. I tested the function and the wiring: the PR's own tests source the script as a library, so they don't exercise the install path.

End to end, on a loop-mounted installed disk (ryzen, as root, my tests/update_e2e_loop_test.sh driving the REAL install):

  • I ran this PR's 1bit-update with one test-only change: the three expect_* values taken from T_TAG/T_CH/T_RUN, to simulate what update_latest sets. diff confirms nothing else differs.
  • The release's puppy_test.sfs carries etc/1bit/release-identity = v2026.99.
arm asked running result
A, legitimate v2026.99 v2026.48 rc 0, identity: the verified image is v2026.99, as asked for, newer than the running v2026.48, new set in /1bit-alt
B, re-published old image v2027.10 v2026.48 REFUSED: the verified image is v2026.99, but GitHub's release is named v2027.10, /1bit-alt not written
C, not newer v2026.99 v2027.10 REFUSED: v2026.99 is not newer than the running v2027.10, /1bit-alt not written

Ordering (read): the image is loop-mounted read-only (~681-687), then the set's files are hash-checked against the image's own SHA256SUMS (~694-711), then this check (~714), and only then mount_esp (730) and the copy into /$target (744). So no byte reaches the other slot before the decision, and the tag comes from inside the signed image.

Also checked:

  • tests/update_identity_test.sh, update_workdir_test.sh and update_latest_test.sh pass under env -i dash.
  • update_ver_gt: numeric week and rc, final > its rcs, junk is never newer.
  • expect_* are initialised empty after the LIB split, so the environment can't set them.
  • ONEBIT_UPDATE_ANY now only skips the API-side "newer" test; the identity check still refuses, which is the safe direction.

Nits, not blocking (a follow-up is fine):

  1. Test the wiring in CI: the identity block could be dropped by a later merge and no test would notice. A cheap guard in update_identity_test.sh: assert that the expect_tag block appears between the SHA256SUMS verification and the == install line. Or add an e2e row behind a test hook.
  2. Which sfs is read: the tag comes from ls "$src"/puppy_*.sfs | head -1, while the verify and copy loops use $need. It's authentic either way, since the whole image is hash-checked under the signature. Reading it from the $need member that gets installed would make "the tag of what we install" exact.
  3. 1bit-update: a private per-run work dir instead of the fixed /tmp/1bit-update; /data/updates must be root-only (security) #3451's comment says /run is "root's own tmpfs". On 1bit OS it isn't (strixhalo: no /run mount, a dir on the save-layer overlay). A work dir left by a killed run therefore persists across reboots in the save layer. That's not a security issue (mktemp, 0700, root); maybe clear stale /run/1bit-update.* at the start.

🤖 Generated with Claude Code

@bong-water-water-bong
bong-water-water-bong merged commit 69bb03f into main Nov 24, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-release/update-identity-check branch November 24, 2026 04:07
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential Security Issue

The code introduces a new mechanism for verifying image identity by reading the etc/1bit/release-identity file from within the image's puppy_*.sfs archive. While this is a security improvement, it relies on the unsquashfs command to extract the identity file. If unsquashfs is not available or behaves unexpectedly, the verification could be bypassed or fail incorrectly. This could lead to an installation of an unverified or malicious image.

if [ -n "${expect_tag:-}" ]; then
    isfs=$(ls "$src"/puppy_*.sfs 2> /dev/null | head -1)
    itag=
    [ -n "$isfs" ] && itag=$(unsquashfs -q -cat "$isfs" etc/1bit/release-identity 2> /dev/null | sed -n 's/^payload=lemonade-onebit-//p' | head -1)
    why=$(update_identity_check "$itag" "$expect_tag" "$expect_run" "$expect_ch") || die "$why"
    say "identity: the verified image is $itag, as asked for, newer than the running $expect_run ($expect_ch channel)"
fi
Incorrect Version Comparison

The update_ver_gt function uses Python to compare version strings, but it does not correctly handle all version formats. Specifically, it assumes that version strings follow the pattern vYYYY.WW[-rcN], but it does not validate that WW is a valid week number (e.g., between 1 and 52). This could lead to incorrect version comparisons and potentially allow older versions to be installed when newer ones are available.

update_ver_gt() {
    python3 -I -c '
import re, sys
def ver(t):
    m = re.fullmatch(r"v(\d{4})\.(\d{1,2})(?:-rc(\d+))?", t)
    return None if not m else (int(m.group(1)), int(m.group(2)), 1 if m.group(3) is None else 0, int(m.group(3) or 0))
a, b = ver(sys.argv[1]), ver(sys.argv[2])
sys.exit(0 if a is not None and b is not None and a > b else 1)
' "$1" "$2"
}

bong-water-water-bong added a commit that referenced this pull request Nov 24, 2026
…eftover work dir, and say so (follow-up to #3454) (#3461)

cl-kernel on #3457: /run on 1bit OS is a directory on the root overlay, whose upper is the persistent save layer in
PUPMODE 12, not a tmpfs. The private work dir (#3451, merged in #3454) is removed by work_done at exit, but a run that
dies before that (power cut, kill -9) leaves /run/1bit-update.XXXXXX in the save layer for good.
- work_sweep, at the start of every run, removes such leftovers in the same base: only 1bit-update.* entries that are
  real directories (never a symlink), owned by this uid, older than a day, and with no mount left inside them (a
  crashed run's ESP mount would otherwise be emptied).
- The work-dir comment no longer calls /run a tmpfs; it is chosen because it is root-only.
tests/update_workdir_test.sh +1: a day-old leftover is removed, a fresh dir is kept, a symlink is never followed (its
target untouched). ok under dash (env -i), busybox ash and as root; update_check/latest/identity: ok.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 24, 2026
…o, and draft the freeze RFC (engine#3448)

Security review (cl-flm lane, 24 Nov). Issue #3448 has two halves. The rollback half is fixed by #3454
(69bb03f): --latest reads the release identity from inside the verified image and refuses anything that
is not the tag asked for and strictly newer. The freeze half is open, and it is a release-trust decision
(CONTRIBUTING.md: anything touching security is an RFC), so this commit does NOT invent a fix for it: it
stops the tool from claiming the freshness it cannot prove, and puts the decision on record.

Rebased onto origin/main a95beca (after #3465/#3466/#3467); the line references below are that tree's.

The mechanism, as it stands (os/v3/puppy/embed/usr/local/bin/1bit-update):
- update_pick decides which release is the channel's newest and whether it is newer than the running one,
  from GitHub's release list (:257-302). That list is not signed; the first signature is checked at
  :453-455, after the "is it newer" decision, and the early exit says "up to date" without checking any
  signature (:430-438). So a release host that keeps serving the current release also keeps the machine
  answering "up to date" (freeze).

What changed:
- update_pick prints ahead=yes when the RUNNING release is newer than the channel's newest (a final against
  its own -rcs, or a channel that has not caught up), which used to be folded into newer=no (:291-295).
- update_check and update_latest answer that case "up to date: running X is newer than the CHANNEL's newest
  Y" and print one note that the answer is the unsigned release list's word, so a host that hides a newer
  release is not detectable (:328-336, :430-438). A plain "up to date" line is kept for the same-tag case,
  so the console, the notice and the board rows keep reading it.
- docs/update-trust.md (new): what the signature covers today (tools/release_sign.py), the exact order
  --latest decides in with file:line, what #3454 closed and what it leaves open, the freeze threat model
  (adversaries, in/out of scope, P1-P3), and the draft RFC body: options A (signed, expiring latest per
  channel reusing release_sign.py), B (TUF-style metadata), C (signed tag -> commit), D (tag+channel in the
  signed SHA256SUMS), E (accept the risk), each with its trust assumptions and cost, the test plan and the
  NOTICE impact, and the open owner questions.
- docs/os-v3.md, "In-system updates": a paragraph after the trust order saying what the order does not
  prove - freeze, with the release-list/commit/rollback facts - and pointing at the draft.
- tests/update_check_test.sh: two arms (the ahead wording, the note), and the existing "a final release
  sorts after its own release candidates" arm now asserts the ahead wording, which is what the tool says
  there now. os/mini/release-check.sh --self-test gains that same output as a PASS fixture, so the
  update-check row still recognises the answer on the board.

What remains open, and is the RFC's first question: is a compromised release host (freeze) in the threat
model? If yes, option A is the recommendation; if no, record that in docs/os-v3.md and close #3448. No code
in this commit closes it - the honest wording says exactly that.

Evidence:
- Control (new test, PRE-FIX updater from origin/main a95beca):
    c=~/.cache/scratch-3448/control; mkdir -p $c/tests $c/os/v3/puppy/embed/usr/local/bin
    git show origin/main:os/v3/puppy/embed/usr/local/bin/1bit-update > $c/os/v3/puppy/embed/usr/local/bin/1bit-update
    cp tests/update_check_test.sh $c/tests/
    (cd $c && sh tests/update_check_test.sh)
  FAIL a final release sorts after its own release candidates (v2026.49 > v2026.49-rc1)
  FAIL a running release newer than the channel's newest is said as ahead, not as a flat 'up to date'
  FAIL the up-to-date answer names the unsigned release list it rests on, and what that cannot detect
  update_check_test: FAIL
- Branch: sh tests/update_check_test.sh -> "update_check_test: ok" (12 arms).
- Sanity: the same control tree with origin/main's own test and updater -> "update_check_test: ok" (only the
  arms this change adds or re-words differ).
- ctest --test-dir build -R 'update|release_check_selftest|release_sign' --output-on-failure --timeout 600:
  "100% tests passed, 0 tests failed out of 12" (update_e2e_loop skipped: needs root/loop, unchanged).
- scripts/pre-pr-checks.sh --tree-only --base origin/main:
  "pre-pr-checks: all 15 check(s) green, 3 skipped, 0 could not be told, 2 open-PR row(s) not run
  (--tree-only)"; skips: submodule_pin (0 submodules initialised), hip_f16_audit and kernel_id_selftest
  (no gpu-kernels tree).

Refs #3448.
bong-water-water-bong added a commit that referenced this pull request Nov 24, 2026
…o, and draft the freeze RFC (engine#3448) (#3474)

Security review (cl-flm lane, 24 Nov). Issue #3448 has two halves. The rollback half is fixed by #3454
(69bb03f): --latest reads the release identity from inside the verified image and refuses anything that
is not the tag asked for and strictly newer. The freeze half is open, and it is a release-trust decision
(CONTRIBUTING.md: anything touching security is an RFC), so this commit does NOT invent a fix for it: it
stops the tool from claiming the freshness it cannot prove, and puts the decision on record.

Rebased onto origin/main a95beca (after #3465/#3466/#3467); the line references below are that tree's.

The mechanism, as it stands (os/v3/puppy/embed/usr/local/bin/1bit-update):
- update_pick decides which release is the channel's newest and whether it is newer than the running one,
  from GitHub's release list (:257-302). That list is not signed; the first signature is checked at
  :453-455, after the "is it newer" decision, and the early exit says "up to date" without checking any
  signature (:430-438). So a release host that keeps serving the current release also keeps the machine
  answering "up to date" (freeze).

What changed:
- update_pick prints ahead=yes when the RUNNING release is newer than the channel's newest (a final against
  its own -rcs, or a channel that has not caught up), which used to be folded into newer=no (:291-295).
- update_check and update_latest answer that case "up to date: running X is newer than the CHANNEL's newest
  Y" and print one note that the answer is the unsigned release list's word, so a host that hides a newer
  release is not detectable (:328-336, :430-438). A plain "up to date" line is kept for the same-tag case,
  so the console, the notice and the board rows keep reading it.
- docs/update-trust.md (new): what the signature covers today (tools/release_sign.py), the exact order
  --latest decides in with file:line, what #3454 closed and what it leaves open, the freeze threat model
  (adversaries, in/out of scope, P1-P3), and the draft RFC body: options A (signed, expiring latest per
  channel reusing release_sign.py), B (TUF-style metadata), C (signed tag -> commit), D (tag+channel in the
  signed SHA256SUMS), E (accept the risk), each with its trust assumptions and cost, the test plan and the
  NOTICE impact, and the open owner questions.
- docs/os-v3.md, "In-system updates": a paragraph after the trust order saying what the order does not
  prove - freeze, with the release-list/commit/rollback facts - and pointing at the draft.
- tests/update_check_test.sh: two arms (the ahead wording, the note), and the existing "a final release
  sorts after its own release candidates" arm now asserts the ahead wording, which is what the tool says
  there now. os/mini/release-check.sh --self-test gains that same output as a PASS fixture, so the
  update-check row still recognises the answer on the board.

What remains open, and is the RFC's first question: is a compromised release host (freeze) in the threat
model? If yes, option A is the recommendation; if no, record that in docs/os-v3.md and close #3448. No code
in this commit closes it - the honest wording says exactly that.

Evidence:
- Control (new test, PRE-FIX updater from origin/main a95beca):
    c=~/.cache/scratch-3448/control; mkdir -p $c/tests $c/os/v3/puppy/embed/usr/local/bin
    git show origin/main:os/v3/puppy/embed/usr/local/bin/1bit-update > $c/os/v3/puppy/embed/usr/local/bin/1bit-update
    cp tests/update_check_test.sh $c/tests/
    (cd $c && sh tests/update_check_test.sh)
  FAIL a final release sorts after its own release candidates (v2026.49 > v2026.49-rc1)
  FAIL a running release newer than the channel's newest is said as ahead, not as a flat 'up to date'
  FAIL the up-to-date answer names the unsigned release list it rests on, and what that cannot detect
  update_check_test: FAIL
- Branch: sh tests/update_check_test.sh -> "update_check_test: ok" (12 arms).
- Sanity: the same control tree with origin/main's own test and updater -> "update_check_test: ok" (only the
  arms this change adds or re-words differ).
- ctest --test-dir build -R 'update|release_check_selftest|release_sign' --output-on-failure --timeout 600:
  "100% tests passed, 0 tests failed out of 12" (update_e2e_loop skipped: needs root/loop, unchanged).
- scripts/pre-pr-checks.sh --tree-only --base origin/main:
  "pre-pr-checks: all 15 check(s) green, 3 skipped, 0 could not be told, 2 open-PR row(s) not run
  (--tree-only)"; skips: submodule_pin (0 submodules initialised), hip_f16_audit and kernel_id_selftest
  (no gpu-kernels tree).

Refs #3448.

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