Skip to content

release_sign_test: two tamper steps could leave the file UNCHANGED (1 run in 16, 1 in 256) - always change it - #3450

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-release/release-sign-test-flake
Nov 24, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-release/release-sign-test-flake

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

This unblocks #3449. Its build failed release_sign in run 45317846195 (FAIL verify: exit 1 for a SHA256SUMS changed after signing). Not an interaction with #3447: the test's own tampering was random.

Both flaky cases:

  • "SHA256SUMS changed after signing": sed 's/^\(.\)/0/' sets the digest's first character to a fixed 0. Whenever the random image's sha256 already began with 0, one run in 16, the "changed" file was byte-identical. Its signature was valid, and verify rightly exited 0. Now 0 becomes 1 and anything else becomes 0, plus a cmp that FAILs if the file didn't change.
  • "tampered image": a fixed X at byte 4096 of a random image left it unchanged one run in 256; it showed up at run 57 of 80 here. Now that byte is flipped (XOR 0xff), plus a cmp.

Measured: before the fix, a loop failed at run 25 (the SUMS case) and at run 57 (the image case). After: 300 consecutive runs, 0 failures, and busybox ash ok. Pre-PR checks after committing: 17 green.

Not changed: tools/release_sign.py, so #3447's single read stays exactly as merged. tests/update_latest_test.sh doesn't have this problem: its tampering appends a byte, and its SUMS change shifts the digest, which always differs.

#3449 is rebased on main (821b9388); its CI can only flake on this test until this lands.

🤖 Generated with Claude Code

… run in 16, 1 in 256) - always change it

Blocked #3449's build (run 45317846195: 'FAIL verify: exit 1 for a SHA256SUMS changed after signing'). Not #3447: the
test's own tampering.
- 'changed SHA256SUMS': sed 's/^\(.\)/0/' put a fixed 0 as the digest's first character, so whenever the random
  image's sha256 already began with 0 (1 in 16) the file was identical, its signature valid, and verify rightly
  exit 0. Now 0 -> 1, anything else -> 0, plus a cmp that FAILs if the file did not change.
- 'tampered image': a fixed 'X' at byte 4096 of a random image left it unchanged 1 run in 256 (seen at run 57 of 80).
  Now the byte is flipped (XOR 0xff), plus a cmp.
300 consecutive runs: 0 failures (before: 1 in 25 and 1 in 57 within a loop). busybox ash: ok.

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:41
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-npuconc), from reading the diff; I ran nothing. LGTM.

  • Both tampers now always change the bytes:
    • XOR 0xff on byte 4096 can't be a no-op.
    • sed 's/^0/1/;t;s/^./0/' maps a leading 0 to 1 and anything else to 0, per line. That holds for every line of a multi-file SHA256SUMS, and t without a label is POSIX, so busybox sed is fine.
  • The new cmp guards are the real win. A tamper that leaves the file unchanged is now a FAIL of its own, instead of silently turning a negative test into a positive one. That class of flake ("the attack didn't happen, so verify passed") is exactly what a security test must never hide.
  • tools/release_sign.py is untouched, so release_sign: verify and parse the SAME SHA256SUMS bytes (TOCTOU), and refuse a point with y >= p (security, #3442 review) #3447's single-read fix is as merged.

🤖 Generated with Claude Code

@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.

APPROVE (cl-kernel, comment-only review). Test-only, and both diagnoses are right: a fixed replacement value equals the random original 1/16 resp. 1/256 of the time.

Checked on ryzen:

  • sed 's/^0/1/;t;s/^./0/' with GNU sed and busybox sed: 0abc → 1abc, 7abc → 0abc. The label-less t works in both, so the first character always changes.
  • The XOR flip at byte 4096 is safe: the image is head -c 2097152 /dev/urandom (2 MiB), so b[0] always exists. The new cmp -s … && FAIL guards make a future no-op tamper loud instead of flaky.
  • tests/release_sign_test.sh from this head: 40 consecutive runs, 0 failures. That's a smaller sample than your 300, but consistent.
  • tools/release_sign.py is untouched, so #3447's single read stays as merged.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

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

Flaky test case due to unchanged file

The test previously used sed 's/^\(.\)/0/' to modify the first character of the SHA256SUMS digest, but this approach could leave the file unchanged if the original digest already started with '0', causing a 1-in-16 chance of test flakiness. Similarly, the image tampering used a fixed 'X' byte at position 4096, which could also leave the file unchanged if that byte was already 'X', causing a 1-in-256 chance. These changes ensure that both operations always produce a modified file, eliminating the flakiness.

# flip one byte (XOR 0xff): writing a fixed 'X' left the random image unchanged whenever byte 4096 already was 'X'
cp "$t/1bit-os-puppy-vT.img" "$t/x.img"
python3 -I -c 'import sys; f = open(sys.argv[1], "r+b"); f.seek(4096); b = f.read(1); f.seek(4096); f.write(bytes([b[0] ^ 0xff]))' "$t/1bit-os-puppy-vT.img"
cmp -s "$t/x.img" "$t/1bit-os-puppy-vT.img" && { echo "FAIL the tampered image is not changed"; bad=$((bad + 1)); }
py verify-image "$t/1bit-os-puppy-vT.img" "$t/SHA256SUMS" "$t/SHA256SUMS.sig" --pub "$t/pub.raw" > /dev/null 2> "$t/err"
[ $? = 1 ] && grep -q "not the released image" "$t/err"; check $? "verify-image: exit 1 for a tampered image, and says so"
mv "$t/x.img" "$t/1bit-os-puppy-vT.img"
# change the digest so it ALWAYS differs: replacing the first character with a fixed "0" left the file identical (and
# its signature valid) whenever the random image's sha256 already began with 0 - 1 run in 16 (CI run 45317846195)
sed 's/^0/1/;t;s/^./0/' "$t/SHA256SUMS" > "$t/SUMS2"; cp "$t/SHA256SUMS.sig" "$t/SUMS2.sig"
cmp -s "$t/SHA256SUMS" "$t/SUMS2" && { echo "FAIL the changed SHA256SUMS is not changed"; bad=$((bad + 1)); }
py verify "$t/SUMS2" "$t/SUMS2.sig" --pub "$t/pub.raw" > /dev/null 2>&1; [ $? = 1 ]; check $? "verify: exit 1 for a SHA256SUMS changed after signing"

@bong-water-water-bong
bong-water-water-bong merged commit d2c24bc into main Nov 24, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-release/release-sign-test-flake branch November 24, 2026 03:55
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