Skip to content

os/v3/puppy: the pre-pack chown disarmed every setuid helper in the image - #957

Merged
bong-water-water-bong merged 8 commits into
mainfrom
os/v3-c21-suid
Nov 4, 2026
Merged

bong-water-water-bong merged 8 commits into
mainfrom
os/v3-c21-suid

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

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.

Activated service 'org.freedesktop.login1' failed: The permission of the setuid helper is not correct
... org.freedesktop.hostname1 ... fi.w1.wpa_supplicant1 ...

closes #956

Measured, both sides of the pack

tree setuid/setgid entries
built sandbox3/rootfs-complete 12 — dbus-daemon-launch-helper, passwd, chsh, chfn, gpasswd, sudo.ws, ssh-keysign, su-FULL, mount-FULL, umount-FULL, fusermount3, ntfs-3g
packed puppy_upup64r_26.04.sfs (the c20 image a boot runs) 0

unsquashfs -ll on the shipped sfs prints -rwxr-xr-x for dbus-daemon-launch-helper and for passwd; there is not one s in a mode bit anywhere in the image.

Root cause

os/v3/puppy/container-build.sh patches woof-CE's 3builddistro to run chown -R 0:0 rootfs-complete immediately before mksquashfs — the cycle-16 fix for frugalpup docs that arrived owned by uid 6975. POSIX: chown() clears S_ISUID/S_ISGID on every file it touches, and chown -R touches 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, passwd and su notice.

My first measurement of this was wrong in the informative way: I extracted the sfs as a non-root user, and unsquashfs cannot 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_supplicant activation, no password change, no working su, no sudo setuid path, no ssh-keysign, no fusermount3/ntfs-3g for 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. 3builddistro calls it instead of the bare chown -R, and the build refuses a 3builddistro that still carries a bare chown -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 s and at least 5 setuid/setgid entries, and prints what it found when it refuses.

Checks

  • helper on a real tree: 4755/4754/2755 restored, root:root, idempotent on a second run, bad tree → exit 2;
  • naive chown -R on the same tree reproduces the loss (4755→755, 4754→754), which is the before/after;
  • the packed-image predicate against the shipped c20 sfs: 0 entries → refuses; against a restored listing: matches -rwsr-xr-x and -rwsr-sr-x, ignores a plain file;
  • the sed patch against a pristine upstream 3builddistro (via git show HEAD:): 2 insertions, bash -n clean, 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 warning clean, tools/copyright.py --check rc=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.

…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).
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit f7986d7)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

956 - Partially compliant

Compliant requirements:

  • The PR fixes the issue where chown -R strips setuid/setgid bits by introducing /recipe/fix-ownership.sh
  • The 3builddistro patch now uses sh /recipe/fix-ownership.sh instead of chown -R
  • A verification step is added to check that setuid/setgid entries are preserved in the packed SFS

Non-compliant requirements:

  • The PR does not include a test case to verify the fix

Requires further human verification:

  • The build process should be manually verified to ensure that the setuid/setgid bits are correctly preserved
  • The D-Bus activation, passwd, and su functionality should be tested on the c20 board to confirm the fix
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect setuid/setgid handling

The change in container-build.sh replaces chown -R 0:0 with a call to fix-ownership.sh, which is intended to preserve setuid/setgid bits. However, the verification logic in lines 440-455 only checks for the presence of dbus-daemon-launch-helper and a minimum count of 5 setuid/setgid entries. This could be insufficient if other setuid/setgid entries are missing or if the count is incorrect, potentially allowing a broken image to be built.

suid_n=$(grep -cv "dbus-daemon-launch-helper" /tmp/1bit-suid-report 2> /dev/null || true)
if ! grep -q 'dbus-daemon-launch-helper' /tmp/1bit-suid-report; then
    echo "build: REFUSED: no setuid dbus-daemon-launch-helper in the packed image. The pre-pack chown stripped it," >&2
    echo "       and without it D-Bus cannot activate login1/hostname1/wpa_supplicant (the c20 board's" >&2
    echo "       'permission of the setuid helper is not correct'). Entries found: $suid_n" >&2
    sed 's/^/   /' /tmp/1bit-suid-report >&2
    exit 1
fi
[ "${suid_n:-0}" -ge 5 ] || {
    echo "build: REFUSED: only ${suid_n:-0} setuid/setgid entries in the packed image (expected the 12 helpers the" >&2
    echo "       packages ship: passwd, chsh, chfn, sudo, ssh-keysign, mount/umount/su-FULL, fusermount3, ntfs-3g," >&2
    echo "       gpasswd, the dbus launch helper); the pre-pack chown stripped them again." >&2
    sed 's/^/   /' /tmp/1bit-suid-report >&2
    exit 1
}
echo "   ok: $suid_n setuid/setgid entries survive the pre-pack chown, incl. the D-Bus launch helper"
Potential race condition in ownership restoration

The script fix-ownership.sh uses find to list setuid/setgid entries and then restores them with chmod. If the file system is modified between the initial listing and the restoration, it could lead to incorrect permissions being applied or files not being found, potentially causing the script to fail or restore incorrect permissions.

find "$tree" -perm /6000 \( -type f -o -type d \) -printf '%m %p\n' > "$list" || exit 2
before=$(wc -l < "$list")

chown -R 0:0 "$tree" || { echo "fix-ownership: chown -R 0:0 $tree failed" >&2; exit 2; }

while IFS=' ' read -r mode path; do
    [ -n "$mode" ] && [ -n "$path" ] || continue
    chmod "$mode" "$path" || { echo "fix-ownership: chmod $mode $path failed" >&2; exit 2; }
done < "$list"

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit e46b930

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 8ec89e9

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit de25d7d

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 4398929

@bong-water-water-bong
bong-water-water-bong merged commit 92964a5 into main Nov 4, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the os/v3-c21-suid branch November 4, 2026 07:28
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit f7986d7

bong-water-water-bong added a commit that referenced this pull request Nov 4, 2026
…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]>
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.

os/v3/puppy: the pre-pack chown strips every setuid bit, so the D-Bus launch helper, passwd and su cannot work

1 participant