Repository navigation
os/v3/puppy: the pre-pack chown disarmed every setuid helper in the image - #957
Conversation
…mage closes #956 The c20 board's "The permission of the setuid helper is not correct" (login1, hostname1, wpa_supplicant) is not a staging problem - it is the cycle-16 ownership fix. container-build.sh patches woof-CE's 3builddistro to run `chown -R 0:0 rootfs-complete` just before mksquashfs, and POSIX clears S_ISUID/S_ISGID on every file chown touches. Measured on the built tree vs the packed image: 12 setuid entries in rootfs-complete (dbus-daemon-launch-helper, passwd, chsh, chfn, gpasswd, sudo.ws, ssh-keysign, su-FULL, mount-FULL, umount-FULL, fusermount3, ntfs-3g), 0 in the puppy sfs a boot runs. Nothing in the boot path needs them, which is why the image boots and serves and only D-Bus activation, passwd and su fail. fix-ownership.sh takes the tree, records every setuid/setgid entry with its mode, chowns, puts the modes back, and refuses to return if the count changed; 3builddistro now calls it instead of the bare chown, and the build refuses a patched-in bare `chown -R`. The assertion reads the PACKED sfs (unsquashfs -ll), because a helper that lost its bit still looks present in the tree: it requires the dbus launch helper to carry an `s` and at least 5 setuid/setgid entries, and prints what it found when it refuses. Checked: helper on a real tree (4755/4754/2755 restored, root:root, idempotent, bad tree -> exit 2), the packed-image predicate against the shipped c20 sfs (0 entries -> refuses) and against a restored listing (matches -rwsr-xr-x and -rwsr-sr-x, ignores plain files), and the sed patch on a pristine upstream 3builddistro (2 insertions, parses, helper wired).
PR Reviewer Guide 🔍(Review updated until commit f7986d7)Here are some key observations to aid the review process:
|
|
#957 ready for review at 2337d49. One correction to the bot's ticket row: 'does not include a mechanism to automatically restore setuid/setgid bits' is the whole fix - fix-ownership.sh records every setuid/setgid entry with its mode, chowns, restores the modes, and refuses to return if the count changed; the build then refuses a 3builddistro that still carries a bare 'chown -R', and the gate reads the packed sfs. The two 'requires human verification' rows are correct and are the next board run's, not this PR's. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 2337d49ba. This is the right fix and I ran the new script rather than reading it.
The premise, reproduced. A bare chown -R 0:0 on a tree really does strip the bit: a file at 4755 reads 755 after it (that is my own first attempt at this test going wrong, before I learned to set the bits after the chown).
The fix, run as root on a tree shaped like the image (2 setuid files, 1 setgid file, 1 setgid directory, 1 plain file, all 1000:1000 first):
before: 4755 dbus-daemon-launch-helper, 4755 passwd, 2755 wall, 2775 sub/grpdir, 644 plain.conf
$ sh fix-ownership.sh /tmp/fown/tree
fix-ownership: /tmp/fown/tree is root:root with 4 setuid/setgid entries restored rc 0
after: 4755 0:0 dbus-daemon-launch-helper, 4755 0:0 passwd, 2755 0:0 wall, 2775 0:0 sub/grpdir, 644 0:0 plain.conf
Every bit survived with its exact mode (including the setgid directory), ownership is normalised, and the plain file stayed 644.
The refusal guard, run. With the restore loop disabled and the same tree:
fix-ownership: /tmp/fo4/tree had 2 setuid/setgid entries, now 0 - refusing to pack it rc 1
so a silently-stripping chown cannot be packed. bash -n clean on both fix-ownership.sh and container-build.sh.
The /recipe path is right, which is the one thing that would have silently broken the build: os/v3/puppy/build.sh:173 mounts that directory -v "$recipe":/recipe:ro, so sh /recipe/fix-ownership.sh resolves. The new REFUSED guards (helper substring present, suid_n >= 5, dbus launch helper found) are read, not run — they only execute inside a real image build, and the numbers they compare against (12 helpers in the tree, the c20 image with none) are the lane's measurements, not mine.
One small thing, not a gate: the suid report greps $1 ~ /^-.{2}[sS]/ from unsquashfs -ll, so a setgid directory (d..S) is counted in suid_n — fine for a ">= 5" floor, but the message says "setuid/setgid entries", which is what it actually counts, so it is honest as written.
|
Persistent review updated to latest commit e46b930 |
|
Persistent review updated to latest commit 8ec89e9 |
|
Persistent review updated to latest commit de25d7d |
|
Persistent review updated to latest commit 4398929 |
|
Persistent review updated to latest commit f7986d7 |
…ts previous version (#976) The #957 patch is guarded by its own marker comment, and the cycle-16 version of the same patch wrote that same comment on a bare `chown -R 0:0 rootfs-complete` line. A woof-CE clone or build root reused from an earlier cycle therefore matched the guard, skipped the sed, and refused the build with "3builddistro still chowns with a bare chown -R" - which reads as an upstream change and was in fact our own older patch. Measured on the cycle-21 build: ~/wt/1bit-puppy-build11/woof-CE is dirty with exactly those two lines (git status: M woof-code/3builddistro), so every build from it refused. The guard now asks for the CALL (sh /recipe/fix-ownership.sh), a line carrying the marker comment is dropped as a previous version of this patch before the current one is inserted, and a second assertion counts the calls (2) and refuses any remaining bare chown beside them. Reproducer, the real patch text against both tree states: before -> rc=1, calls=0, barechown=2; after -> rc=0, calls=2, barechown=0, and the same on a re-run and on an unpatched tree. Co-authored-by: pi-os3 <[email protected]>
The c20 board reported this for the second cycle running, as three unrelated-looking lines. They are one cause, and it is our own build patch.
closes #956
Measured, both sides of the pack
sandbox3/rootfs-completedbus-daemon-launch-helper,passwd,chsh,chfn,gpasswd,sudo.ws,ssh-keysign,su-FULL,mount-FULL,umount-FULL,fusermount3,ntfs-3gpuppy_upup64r_26.04.sfs(the c20 image a boot runs)unsquashfs -llon the shipped sfs prints-rwxr-xr-xfordbus-daemon-launch-helperand forpasswd; there is not onesin a mode bit anywhere in the image.Root cause
os/v3/puppy/container-build.shpatches woof-CE's3builddistroto runchown -R 0:0 rootfs-completeimmediately beforemksquashfs— the cycle-16 fix for frugalpup docs that arrived owned by uid 6975. POSIX:chown()clearsS_ISUID/S_ISGIDon every file it touches, andchown -Rtouches all of them. So the ownership fix silently disarmed every setuid helper in the image, and the two facts were never connected because nothing in the boot path needs them: the image boots, serves and passes its gates, and only D-Bus activation,passwdandsunotice.My first measurement of this was wrong in the informative way: I extracted the sfs as a non-root user, and
unsquashfscannot set setuid bits, so the extracted tree showed 0 too. The claim only stands because it is read from the sfs metadata (unsquashfs -ll), which is also where the build now checks it.Effect on the appliance: no
login1/hostname1/wpa_supplicantactivation, no password change, no workingsu, nosudosetuid path, nossh-keysign, nofusermount3/ntfs-3gfor a non-root user.Fix
os/v3/puppy/fix-ownership.sh <tree>— records every setuid/setgid entry with its mode,chown -R 0:0, puts the modes back, and refuses to return if the count changed.3builddistrocalls it instead of the barechown -R, and the build refuses a3builddistrothat still carries a barechown -R(so a future upstream change cannot silently re-break it).The gate is on the packed sfs, not the tree: a helper that lost its bit still looks present. It requires the D-Bus launch helper to carry an
sand at least 5 setuid/setgid entries, and prints what it found when it refuses.Checks
4755/4754/2755restored,root:root, idempotent on a second run, bad tree → exit 2;chown -Ron the same tree reproduces the loss (4755→755,4754→754), which is the before/after;-rwsr-xr-xand-rwsr-sr-x, ignores a plain file;3builddistro(viagit show HEAD:): 2 insertions,bash -nclean, helper wired — a dry run against the already-patched build clone gave 4, which is the difference between the two and is why the count assertion exists;bash -n,shellcheck -S warningclean,tools/copyright.py --checkrc=0.Not claimed: that login1/hostname1/wpa_supplicant activation then succeeds on the board — that is a boot, and the next stick's board run is where it shows. What this proves is that the bits the packages ship are present in the artifact again.