Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions os/mini/release-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,27 @@ payload_modes_verdict() { # <writable files> <writable directories> [<sample>]
fi
}

# The BASE layer's modes (engine#1474). The payload row above closes the same class for opt/1bit-package; this one is one
# layer down, where woof-CE's build left 2,176 group/other-writable paths (1,814 of them files) inherited from the
# builder's umask. The appliance runs as root, so none of them was reachable by anything that should not have it - the
# defect is the same one: a mode in a release artifact that nobody decided.
#
# The keep-list is the point of the row as much as the count: eight classes of path DO need to stay writable (tmp,
# var/tmp, var/run, var/lock, var/spool, var/log, run, dev, proc, sys), and a cycle that silently changes that list is
# exactly what a row should make visible. So the row PRINTS it, and the verdict takes its size.
# Pure, so --self-test drives it: <writable count> <keep-list entries> [<sample>]
base_modes_verdict() { # <writable> <keeplist entries> [<sample>]
_b=${1:-} _k=${2:-} _bs=${3:-}
case "$_b" in ''|*[!0-9]*) printf 'FAIL the base layer'"'"'s modes could not be counted (%s)' "${_b:-empty}"; return 0 ;; esac
case "$_k" in ''|*[!0-9]*) printf 'FAIL the base keep-list could not be read (%s)' "${_k:-empty}"; return 0 ;; esac
if [ "$_b" = 0 ]; then
printf 'PASS no path in the BASE layer is group- or other-writable outside the %s keep-list entr(y/ies) - the packer normalises them and this is the proof (engine #1474)' "$_k"
else
printf 'FAIL %s path(s) in the BASE layer are group- or other-writable outside the keep-list%s - a packing site is not normalising (engine #1474: scripts/base-modes.sh / pack-elf.sh)' \
"$_b" "${_bs:+: $_bs}"
fi
}

# The payload's RUNPATH (the orchestrator's rule of 2026-11-08, after an installed engine's RUNPATH into a build tree made a
# rebuild swap the libraries under two running services: coder-llm on :8090 crash-looped 154 times and 1bit-canonical on :8095
# 755 times). An installed package must carry `$ORIGIN` ONLY: it finds its own libraries beside itself, and a path into a build
Expand Down Expand Up @@ -737,6 +758,16 @@ if [ "${1:-}" = --self-test ]; then
check FAIL "$(payload_modes_verdict '' 0)"
check FAIL "$(payload_modes_verdict 0 '')"
check FAIL "$(payload_modes_verdict x 0)"
# engine #1474: the base layer's row - clean only when the count is 0 AND a keep-list was read
check PASS "$(base_modes_verdict 0 11)" # 11: the entry count in os/v3/puppy/base-modes-keep today
check FAIL "$(base_modes_verdict 2166 10 'drwxrwxr-x usr/share')" # c33's base layer, the shape this closes
check FAIL "$(base_modes_verdict 1 10 'drwxrwxr-x usr')"
check FAIL "$(base_modes_verdict '' 10)" # unreadable count
check FAIL "$(base_modes_verdict 0 '')" # no keep-list to judge against
check FAIL "$(base_modes_verdict 0 x)" # a non-numeric keep count
# a ZERO keep count is not a verdict failure: the row SKIPs when the keep-list file is absent, and a present-but-empty
# one is a repository error rather than a machine state, so it is covered at the call site (documented here so the
# split is not mistaken for a gap)
# c32: the HRX weight placement. The measured arms from #1339 are the first two; the failure shapes are a default
# that already imported (2), an unreadable arm, and a zero.
check PASS "$(hrx_placement_verdict 5692 3010)" # 4B perplexity, #1339
Expand Down Expand Up @@ -1831,6 +1862,48 @@ else
esac
fi

# ── the BASE layer's modes (engine#1474) ────────────────────────────────────────────────────────────────────────
# The scan is the root filesystem only, and the keep-list is the ONE source of truth for what may stay writable: the prune
# list is BUILT from it rather than copied beside it (the first version hardcoded the same eleven entries by hand, so the
# next cycle to edit the keep-list - the file whose whole purpose is to be edited - would have had no prune for its new
# entry, and the row would have failed on a path the keep-list explicitly allows). The four paths pruned for a DIFFERENT
# reason are named separately, because "not part of the OS image" is not "allowed to be writable".
#
# The scan root is overridable for the same reason PAYLOAD_DIR is above: a row that can only be judged by booting an image
# cannot be tested. `BASE_SCAN_ROOT=<tree>` points it at any tree of the same shape.
BKEEP=${BASE_KEEP:-/etc/1bit/base-modes-keep}
if [ ! -f "$BKEEP" ]; then
skip base-modes "no $BKEEP on this system: this image predates the base-layer row (engine #1474), so there is no keep-list to judge against"
else
_bm_keep=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP")
_bm_n=$(printf '%s\n' "$_bm_keep" | grep -c . || true)
BROOT=${BASE_SCAN_ROOT:-/}
BROOT=${BROOT%/}
# the rows that are not the OS image at all (a mounted data partition, the initramfs, removable media)
_bm_excl='data initrd mnt media'
_bm_prune=
for _p in $_bm_excl; do
_bm_prune="$_bm_prune -path $BROOT/$_p -prune -o"
done
# and everything the keep-list names, from the keep-list itself
for _p in $_bm_keep; do
_bm_prune="$_bm_prune -path $BROOT/${_p%/} -prune -o"
done
# COUNT the whole set, then sample from it: `find … | head -40` before the count capped the number at 40, so the one
# sentence a reader uses to judge severity said "40 path(s)" for a base layer with 2,176 of them (review on #1544)
_bm_list=${TMPDIR:-/tmp}/.1bit-base-modes.$$
# shellcheck disable=SC2086 # the prune expression is built as separate words on purpose
find "${BROOT:-/}" $_bm_prune \( -type f -o -type d \) \( -perm -g+w -o -perm -o+w \) -print 2> /dev/null > "$_bm_list" || true
_bm_n_paths=$(wc -l < "$_bm_list" | tr -d ' ')
_bm_s=$(head -3 "$_bm_list" | while IFS= read -r _p; do [ -n "$_p" ] && printf '%s %s ' "$(stat -c %A "$_p" 2>/dev/null)" "$_p"; done)
rm -f "$_bm_list"
BM=$(base_modes_verdict "$_bm_n_paths" "$_bm_n" "$_bm_s")
case "$BM" in
PASS*) pass base-modes "${BM#PASS } (keep-list: $(printf '%s' "$_bm_keep" | tr '\n' ' '))" ;;
*) fail base-modes "${BM#FAIL }" ;;
esac
fi

# ── the payload's RUNPATH (orchestrator's rule, 2026-11-08) ─────────────────────────────────────────────────────
# An installed package must carry `$ORIGIN` ONLY. The incident: an installed engine whose RUNPATH pointed into
# ~/wt/release-rc/work/build had its libraries swapped by a rebuild there, and two running services crash-looped
Expand Down
40 changes: 40 additions & 0 deletions os/v3/puppy/base-modes-keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Paths in the BASE Puppy layer that must stay group/other-writable (engine#1474). One prefix per line, relative to the
# root of the layered tree; `#` and blank lines are ignored. Everything not listed here has `go-w` applied by
# `pack_normalise_base_modes` -- the group and other WRITE bits only, never any other bit: setting "other files 0644" the
# way the payload's normaliser does would make /etc/shadow world-readable, and this is an operating system's base layer.
# A prefix covers the path itself as well as everything below it, which is why `tmp/` keeps /tmp's 1777.
#
# The list is short on purpose and every entry is a place where the running system WRITES at boot or at runtime. A
# missing entry breaks the appliance in ways a boot finds late, which is why the release row prints this file: a change
# here is visible instead of silent.
tmp/
var/tmp/
var/run/
var/lock/
var/spool/
var/log/
run/
dev/
proc/
sys/
# The payload is NOT this list's business: it has its own normaliser (pack_normalise_modes) and its own release row,
# and since c33 it ships 0 group/other-writable files (engine#1352). Keeping it here means the base row can be read as
# "the base layer outside the payload", which is the number engine#1474 is about.
opt/1bit-package/
4 changes: 4 additions & 0 deletions os/v3/puppy/container-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ if [ -n "${PAYLOAD:-}" ]; then
install -D -m 755 /recipe/embed/usr/local/bin/1bit-update "$skeleton/usr/local/bin/1bit-update"
# engine#712: the persistent network identity (a static address on /data, applied at boot, one command to forget)
install -D -m 755 /recipe/embed/usr/local/bin/1bit-network "$skeleton/usr/local/bin/1bit-network"
# engine#1474: the BASE layer's keep-list ships so the board row can print what decided it. The normalisation itself
# runs in fix-ownership.sh, which 3builddistro calls immediately before mksquashfs - the last moment the tree exists,
# and the same hook that already refuses to pack when the setuid count moved.
install -D -m 644 /recipe/base-modes-keep "$skeleton/etc/1bit/base-modes-keep"
install -D -m 755 /recipe/embed/etc/init.d/06onboard-logs "$skeleton/etc/init.d/06onboard-logs"
install -D -m 755 /recipe/embed/etc/init.d/08onboard-presets "$skeleton/etc/init.d/08onboard-presets"
install -D -m 755 /recipe/embed/root/Startup/1bit-lemonade-webapp \
Expand Down
23 changes: 23 additions & 0 deletions os/v3/puppy/fix-ownership.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,27 @@ if [ "$after" != "$before" ]; then
echo "fix-ownership: $tree had $before setuid/setgid entries, now $after - refusing to pack it" >&2
exit 1
fi
# ── the BASE layer's modes (engine#1474) ─────────────────────────────────────────────────────────────────────────────
# This hook runs immediately before mksquashfs, which is the last moment the tree exists and the right place to take the
# group/other-write bits off: woof-CE's build leaves ~2,176 such paths (the builder's umask, carried by `cp -a`), nothing
# needs them because the appliance runs as root, and the keep-list keeps the eight classes that do. The normaliser only
# NARROWS (go-w), so it cannot expose a secret the way "other files 0644" would, and the reporter is checked here rather
# than trusted: a tree that is still writable outside the keep-list is refused, exactly like a moved setuid count.
here=$(cd "$(dirname "$0")" && pwd)
keep=${BASE_KEEP:-$here/base-modes-keep}
# the normaliser is in the repository's scripts/: /repo in the build container (the repo is mounted there), and three
# levels up from this hook on a host. Both are tried, because this file runs in both places.
normaliser=''
for _c in /repo/scripts/base-modes.sh "$here/../../../scripts/base-modes.sh"; do
[ -x "$_c" ] && { normaliser=$_c; break; }
done
if [ ! -f "$keep" ]; then
echo "fix-ownership: no keep-list at $keep: the base layer's modes were NOT normalised (engine#1474)" >&2
elif [ -z "$normaliser" ]; then
echo "fix-ownership: no scripts/base-modes.sh found (looked in /repo and beside this hook): the base layer's modes were NOT normalised (engine#1474)" >&2
else
bash "$normaliser" "$tree" --keep "$keep" || {
echo "fix-ownership: the base layer's modes could not be normalised (engine#1474)" >&2; exit 1; }
fi

echo "fix-ownership: $tree is root:root with $after setuid/setgid entries restored"
31 changes: 31 additions & 0 deletions os/v3/puppy/patch-sfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ replace=''
# so a reader never sees half an artifact and a REFUSED run no longer destroys the previous good one. Handing over an existing
# name is therefore a deliberate act: without the flag the old refusal stands.
if [ "${1:-}" = --replace ]; then replace=1; shift; fi
# --keep-modes <keeplist>: normalise the BASE layer's group/other-write bits (engine#1474) BEFORE the metadata pass, on
# BOTH sides, so the declared-set proof still means "the patch changed nothing outside its targets" and the artifact is
# the normalised tree. Opt-in: a cut that does not pass it ships the base layer's modes exactly as its source had them.
keepmodes=''
if [ "${1:-}" = --keep-modes ]; then keepmodes=${2:?--keep-modes needs a keep-list}; shift 2; fi
[ $# -eq 4 ] || { usage >&2; exit 1; }
manifest=''
if [ "${1:-}" = --manifest ]; then manifest=$2; src=$3; out=$4; target=''; repl=''; else src=$1 target=$2 repl=$3 out=$4; fi
Expand Down Expand Up @@ -198,6 +203,23 @@ else
fi

echo "$prog: packing with woof-CE's options (-comp zstd -Xcompression-level 19 -b 256K -no-exports -no-xattrs)"
# engine#1474: with a keep-list, the BASE layer's group/other-write bits come off here - before the metadata pass and on
# BOTH trees, which is what keeps the declared-set proof honest: after the same transformation on each side, a mode line
# that differs is still a difference the patch made. The normaliser only narrows (go-w), so nothing can gain a bit; the
# reporter is checked on the packed tree at the end, so a tree that is still writable outside the keep-list is refused.
if [ -n "$keepmodes" ]; then
norm=''
for c in /repo/scripts/base-modes.sh "$(cd "$(dirname "$0")/../../.." && pwd)/scripts/base-modes.sh"; do
[ -x "$c" ] && { norm=$c; break; }
done
[ -n "$norm" ] || { echo "$prog: --keep-modes: no scripts/base-modes.sh found (looked in /repo and in the repository)" >&2; exit 1; }
[ -f "$keepmodes" ] || { echo "$prog: --keep-modes: no keep-list at $keepmodes" >&2; exit 1; }
echo "$prog: normalising the base layer's modes in the source tree:"
bash "$norm" "$work/src" --keep "$keepmodes" 2>&1 | sed 's/^/ /'
echo "$prog: and in the patched tree:"
bash "$norm" "$work/new" --keep "$keepmodes" 2>&1 | sed 's/^/ /'
fi

# Packed to a TEMPORARY name and renamed only once every check has passed, for two reasons measured on 2026-11-08:
# * a concurrent reader saw this file growing (127 MB of 490 MB) and misread it - another lane was measuring the
# artifact while a cut was rewriting it in place, which no check on this side can prevent;
Expand Down Expand Up @@ -256,6 +278,15 @@ vmeta=$(diff "$work/meta-new" "$work/meta-verify" || true)
echo "$prog: REFUSED: the repack's modes/owners/types/sizes are not the packed tree's:" >&2
printf '%s\n' "$vmeta" | sed -n '1,8p' >&2; rm -f "$out"; exit 1; }
echo "$prog: metadata: $dn line(s) differ from the source, all inside the declared set; repack matches it exactly"
if [ -n "$keepmodes" ]; then
if dirty=$(bash "$norm" "$work/verify" --keep "$keepmodes" --report-only 2>&1); then
echo "$prog: base modes: the packed SFS is clean outside $(basename "$keepmodes")"
else
printf '%s\n' "$dirty" | sed -n '1,10p' >&2
echo "$prog: REFUSED: the packed SFS is still group/other-writable outside the keep-list (engine#1474)" >&2
rm -f "$out"; exit 1
fi
fi

# Every check above ran against the temporary name; only now does the artifact take the name callers read.
mv -f "$out" "$final"; out=$final
Expand Down
71 changes: 71 additions & 0 deletions scripts/base-modes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# base-modes.sh <tree> [--keep <keeplist>] [--report-only]
#
# The BASE Puppy layer's modes (engine#1474): 2,176 of its paths are group/other-writable, inherited from woof-CE's build
# with the builder's umask. Nothing needs them -- the appliance runs as root -- except the eight classes in
# os/v3/puppy/base-modes-keep (tmp, var/tmp, var/run, var/lock, var/spool, var/log, run, dev, proc, sys).
#
# base-modes.sh <tree> normalise and report (dirs 0755, executables 0755, other files 0644)
# base-modes.sh <tree> --report-only print the group/other-writable paths outside the keep-list, change nothing
# base-modes.sh <tree> --keep <file> use another keep-list
#
# The normaliser and the reporter are the two functions this calls in scripts/pack-elf.sh, so the row that fails a cycle
# and the cycle itself cannot disagree. Run as root (it chmods a tree it did not create).
#
# Exit: 0 done (and, with --report-only, clean), 1 dirty (--report-only found paths), 2 usage/tree, 3 normalisation failed.
set -uo pipefail
prog=$(basename "$0")
tree=''
keep=$(cd "$(dirname "$0")/.." && pwd)/os/v3/puppy/base-modes-keep
mode=normalise
while [ $# -gt 0 ]; do
case $1 in
-h|--help) sed -n "/^# $prog /,/^# Exit:/p" "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
--keep) keep=${2:?--keep needs a file}; shift ;;
--report-only) mode=report ;;
/*) tree=$1 ;;
*) echo "$prog: unknown argument '$1'" >&2; exit 2 ;;
esac
shift
done
[ -n "$tree" ] || { sed -n "/^# $prog /,/^# Exit:/p" "$0" | sed 's/^# \{0,1\}//' >&2; exit 2; }
[ -d "$tree" ] || { echo "$prog: no such tree: $tree" >&2; exit 2; }
[ -f "$keep" ] || { echo "$prog: no keep-list: $keep" >&2; exit 2; }
here=$(cd "$(dirname "$0")" && pwd)
# shellcheck disable=SC1091 # the repository's own library
. "$here/pack-elf.sh"

if [ "$mode" = report ]; then
dirty=$(pack_writable_base_files "$tree" "$keep")
if [ -z "$dirty" ]; then
echo "base-modes: clean - no group/other-writable path outside $(basename "$keep")"
exit 0
fi
printf '%s\n' "$dirty" | sed -n '1,40p'
printf 'base-modes: %s group/other-writable path(s) outside %s\n' "$(printf '%s\n' "$dirty" | wc -l)" "$(basename "$keep")"
exit 1
fi

pack_normalise_base_modes "$tree" "$keep" || exit 3
dirty=$(pack_writable_base_files "$tree" "$keep")
if [ -n "$dirty" ]; then
printf '%s\n' "$dirty" | sed -n '1,20p' >&2
echo "$prog: FAILED: $(printf '%s\n' "$dirty" | wc -l) path(s) are still writable after normalising" >&2
exit 3
fi
exit 0
Loading
Loading