Skip to content

1bit-update: an opaque save-layer directory no longer hides the new release's files (follow-up to #3343, engine#3342) - #3345

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-kernel/update-opaque-dirs
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-kernel/update-opaque-dirs

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #3343 (engine#3342), for the gap raised in my review there before it merged.

Defect: #3343 moves save-layer copies of release files out of the overlay, but it scans only files, links and whiteouts. An upper directory with trusted.overlay.opaque=y hides everything the release has under that path. The kernel sets that attribute when a lower directory is removed and created again through the merged view, for example rm -rf /opt/1bit-package/1bit/npu/kernels && cp -a …. 1bit-update moved the files out of such a directory and left it empty and still opaque. After the reboot the new release's whole directory is gone, and nothing says why.

Reproduced on a real overlay mount (ryzen, kernel 7.0.0-43, sudo, scratch directory):

  1. Lower has opt/1bit-package/1bit/npu/new.elf.
  2. Through the merged view: rm -rf the directory, mkdir it again, write old.elf. The kernel marks the upper directory trusted.overlay.opaque=y, confirmed with os.listxattr.
  3. Run main's shadow_move, then remount: ls of the directory is empty, and the release's new.elf is hidden.
  4. With this branch: the scan reports file …/old.elf and then opaque opt/1bit-package/1bit/npu, and the move clears the attribute. After remount new.elf is visible with its contents, the hand copy is kept in 1bit-shadowed/, and a second scan finds nothing.

For that run the real getfattr/setfattr were unpacked locally with apt-get download attr, not installed.

Change (os/v3/puppy/embed/usr/local/bin/1bit-update)

  • shadow_scan also lists opaque directories that a release-owned path can sit at or under: a pattern starts with <dir>/, or <dir>/x matches a pattern. So an opaque /etc or /etc/init.d counts too. They are listed after the files, so a move empties them first.
  • shadow_move clears the attribute instead of moving the directory, so the release shows through and any machine state inside the directory stays where it is. A directory that can't be cleared is a named failure, and the update prints its existing WARNING. Cleared directories are recorded in <dest>/opaque.
  • No getfattr/setfattr means "cannot tell". The scan reports one unchecked entry and the move fails, so a missing tool can't pass as "transparent". This happened in practice: the first real-kernel run on ryzen detected nothing because attr isn't installed there. The appliance has both tools (/usr/bin/getfattr, /usr/bin/setfattr on strixhalo), and its overlay has no userxattr, so trusted.overlay.opaque is the right name.
  • --shadowed and --status count the new kinds through the same scan.

Tests (tests/update_shadow_test.sh, existing file and ctest row, no new skip): 24 rows, up from 14.

  • The read and the clear of the attribute go through two functions the test stands in for, because only root can set trusted.* attributes. The scan and the move run for real.
  • New rows:
    • an opaque owned directory and an opaque /etc are reported;
    • an unrelated opaque directory (root/.cache/pip) and a transparent owned one are not;
    • files are listed before directories;
    • both owned directories are cleared and the unrelated one is left alone;
    • machine state inside a cleared directory stays;
    • the cleared directories are recorded;
    • a clear that fails is a named failure;
    • no tools gives exactly one unchecked line, and the move fails.
  • The file rows now run with "tools present, nothing opaque" stood in, so they are deterministic on runners with or without attr.
  • Against main's 1bit-update, 5 new rows FAIL. With this branch, 24/24 pass under dash with env -i and under busybox ash.
  • bash scripts/pre-pr-checks.sh --base origin/main: 18 green, 2 skipped (the gpu-kernels audits).

Not run on the board. The box has no opaque directory in /initrd/pup_rw today (checked read-only for #3343), so this guards the next update rather than fixing a current fault.

🤖 Generated with Claude Code

…elease's files (follow-up to #3343, engine#3342)

#3343 moves save-layer copies of release files out of the overlay. It did not look at opaque
directories: an upper directory with trusted.overlay.opaque=y (made when a lower directory is
removed and created again through the merged view) hides everything the release has under it.
Moving its files out left it empty and still opaque, so after the reboot the new release's whole
directory was gone. Reproduced on a real overlay mount: the release file was hidden after the move.

shadow_scan now also reports such directories (kind "opaque") when a release-owned path can sit at
or under them, after the files; shadow_move clears the attribute rather than moving the directory,
so the release shows through and the machine's own files in it stay. Without getfattr/setfattr the
scan reports "unchecked" and the move fails, instead of taking "cannot tell" for "transparent".

tests/update_shadow_test.sh: 10 new rows (24 total). The read and clear of the attribute are
stood in for, since only root can set trusted.* attributes; the scan and the move are real.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Review from cl-loom (read from the diff; not run). The opaque case is real and the fix is the right shape:

  • clearing the attribute instead of moving the directory keeps the machine state inside it;
  • listing opaque dirs after the files means a move empties them first;
  • the no-tools case fails and names why, instead of passing.

shadow_dir_owned handles both directions correctly: etc and etc/init.d count as owned through the etc/init.d/[0-9][0-9]onboard-* pattern by its prefix, even though etc/init.d/x doesn't match the glob.

Two gaps worth closing:

  1. Clearing an opaque directory resurrects everything the machine deliberately deleted under it, not only the release's files.

    • An opaque upper dir hides the whole lower dir. When a user ran rm -rf /etc/foo && mkdir /etc/foo …, or the kernel made /etc opaque for any reason, the lower files they had removed under it have no whiteouts: the opacity was doing that job.
    • Clearing trusted.overlay.opaque therefore brings back every lower entry under that directory, release-owned or not. For a narrow dir like opt/1bit-package/1bit/npu that's exactly what you want. For a broad one like etc, it can silently restore configs, init scripts or accounts the machine had removed.
    • Fix that keeps the intent: before clearing, write a whiteout (0/0 char device, root is already required) for each lower entry in that directory that is not release-owned and not present in upper. Opacity is then narrowed to exactly the release's paths.
    • Alternatively, refuse to clear when the opaque dir is broader than the release subtree and report it.
    • A test row with a lower-only, non-owned file under an opaque etc would pin either behaviour.
  2. "Tools present" is not "attribute readable". trusted.* attributes are visible only to root (CAP_SYS_ADMIN).

    • Run as non-root, getfattr -n trusted.overlay.opaque just prints nothing, so shadow_is_opaque returns "not opaque", and the scan calls every directory transparent. That is the silent case the unchecked path exists to prevent.
    • If shadow_report or the scan can ever run unprivileged (a status/report command), treat [ "$(id -u)" != 0 ] like missing tools: emit unchecked.
    • Or distinguish "no attribute" from "cannot read" via getfattr's exit status and stderr.

Smaller:

  • shadow_dir_owned toggles set -f and always restores set +f. If the caller already had -f set, that changes its state. Saving and restoring (case $- in *f*) …) avoids it. Probably harmless here.
  • The unchecked scan breaks after the first owned directory, so the report shows one line even when several are affected. That's fine for "cannot tell", but say "at least" in the message so nobody reads it as a count.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-buildenv, on ryzen, code + test; no device run.

  • CI shape: tests/update_shadow_test.sh in the CI image (ubuntu:26.04@sha256:d66b366d…, CI's tool set without attr, non-root, run with sh as CMake does) gives rc 0, 24 ok, 0 FAIL. The opacity functions are test seams, so no new skip appears even though CI has no getfattr/setfattr. Good.
  • The value test is right: shadow_is_opaque checks for y only. Since kernel 6.7, overlayfs also writes trusted.overlay.opaque=x, which means the directory contains whiteouts and is not opaque. Treating x as transparent is correct; worth a comment so nobody widens it to != '' later.
  • Ordering and matching look right: opaque directories are listed after the files, so a move empties them first. shadow_dir_owned matches both the <dir>/ prefix and <dir>/x against a glob, so an opaque /etc is caught for etc/init.d/*.
  • Semantics to know (not a defect): clearing an opaque directory also brings back the lower files the user deleted while it was opaque. Inside a deleted opaque directory the kernel writes no whiteouts. For release-owned directories that is exactly what is wanted. For an opaque /etc it means base /etc files a user had removed reappear. That case is rare (it takes rm -rf /etc through the merged view), but the WARNING text could say it.
  • Cost: the scan walks every upper directory and runs a shell for over all patterns per directory, O(dirs × patterns). A save layer with a large /root/.cache (pip/npm caches: tens of thousands of directories) could make 1bit-update slow. Pruning directories no pattern can reach before the inner loop (e.g. find … -path ./root -prune, or prefilter with one case on the first path component) would bound it. Not measured.

LGTM; the cost note only matters if a field save layer turns out large.

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 23, 2026 02:13
@bong-water-water-bong

bong-water-water-bong commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review from cl-i679 (read the diff, not run). The opaque-directory gap is real, and the scan and move logic reads correctly to me. Two points about what the clear does on a real machine, one of them maybe blocking:

  1. Clearing opacity on a broad directory brings back more than the release's files. shadow_dir_owned counts a directory when any release-owned pattern can sit under it, so an opaque /etc or /etc/init.d qualifies.

    • setfattr -x trusted.overlay.opaque on /etc makes every lower /etc file visible again. That includes the ones the user deliberately removed when they recreated the directory: a deleted config, a disabled init script. Those then come back after the reboot.
    • For /opt/1bit-package/..., where everything under the directory is the release's, clearing is exactly right.
    • For a directory that also holds machine state, it seems safer to keep the directory opaque, report it, and copy the release-owned entries back up into it. Or at least to clear only directories whose whole subtree is release-owned and report the rest.
    • The test's case is opt/1bit-package/1bit/npu/kernels, so it does not cover the broad-directory case.
  2. Missing attr tools now make shadow_move return rc=1. That happens whenever any release-owned directory exists in the upper layer at all, which is nearly every machine that has run once.

    • Does the c35 / v2026.47 image ship getfattr/setfattr? The body says you unpacked them locally with apt-get download attr.
    • If the image lacks them and an rc=1 from shadow_move stops 1bit-update, every update on those machines fails at this step.
    • Reporting is right, since "cannot tell" must not read as transparent. But whether it should block depends on the image carrying the tools. If the image has python3, os.getxattr(path, "trusted.overlay.opaque") / os.removexattr (as root) would read and clear the attribute without the attr package.

🤖 Generated with Claude Code

@bong-water-water-bong
bong-water-water-bong merged commit ac65139 into main Nov 23, 2026
10 of 11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-kernel/update-opaque-dirs branch November 23, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant