From f5ff5223338620ee9b962f0a14f872a7e386eef3 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 17:36:02 -0400 Subject: [PATCH 1/4] os: the BASE layer's group/other-writable modes are taken off, and a row keeps them off (Fixes #1474) The payload class (#1352/#1361/#1360/#1435/#1459/#1461/#1463) is closed for opt/1bit-package; this is the same class one layer down, which none of those rows looked at. Measured on the base SFS this pass: **2,176** group/other-writable paths outside the payload (1,814 files + 362 dirs), **2,166 of them outside a keep-list** - 352 directories, 542 executables, 1,272 other files, all inherited from woof-CE's build with the builder's umask. * `pack_normalise_base_modes` / `pack_writable_base_files` in scripts/pack-elf.sh, beside the payload pair. The normaliser applies **go-w ONLY**. The payload's rule (dirs 0755, executables 0755, other files 0644) is right for a package and wrong for an operating system: it GRANTS bits, and it would have made /etc/shadow and /etc/gshadow world-readable and every 0600 private key readable. The base layer has all of the secrets the payload does not. * `os/v3/puppy/base-modes-keep`: the eight classes that DO need to stay writable (tmp, var/tmp, var/run, var/lock, var/spool, var/log, run, dev, proc, sys) plus opt/1bit-package (the payload has its own normaliser and its own row). A prefix covers the path itself, so /tmp keeps 1777 rather than losing its sticky bit. * `scripts/base-modes.sh`: the CLI (`` normalises and self-checks, `--report-only` prints what is dirty). * applied in `os/v3/puppy/fix-ownership.sh`, the hook 3builddistro calls immediately before mksquashfs - the last moment the tree exists, and the same place that already refuses to pack when the setuid count moves. * `base_modes_verdict` + the `base-modes` row in os/mini/release-check.sh: counts the root filesystem outside the keep-list, PRINTS the keep-list that decided it (a silent change to that list is what a row should make visible), and the keep-list ships at /etc/1bit/base-modes-keep so the row judges against the machine's own copy. Six self-test arms. * `tests/base_modes_test.sh`: 16 arms, including the two that would have caught my own first version - a 0640 file stays 0640 and a 0700 directory stays 0700 (the normaliser must never widen), and `var/logrotate` is not kept by `var/log`. Boot proof on the real base tree: normalised (2,166 paths, 193 kept) -> mksquashfs with woof-CE's options -> mkimage.sh -> vm-check.sh: **77 PASS / 0 FAIL / 4 SKIP** (the 4 are structural: ssh key, two board rows, a second disk). After the run the reporter says clean and the bits that matter are untouched: etc/shadow 600, etc/gshadow 600, etc/sudoers 640, usr/bin/passwd 4755, tmp 1777, dev 775. --- os/mini/release-check.sh | 54 +++++++++++++++++ os/v3/puppy/base-modes-keep | 40 +++++++++++++ os/v3/puppy/container-build.sh | 4 ++ os/v3/puppy/fix-ownership.sh | 23 ++++++++ scripts/base-modes.sh | 71 +++++++++++++++++++++++ scripts/pack-elf.sh | 102 +++++++++++++++++++++++++++++++++ tests/base_modes_test.sh | 99 ++++++++++++++++++++++++++++++++ tools/copyright.py | 3 + 8 files changed, 396 insertions(+) create mode 100644 os/v3/puppy/base-modes-keep create mode 100755 scripts/base-modes.sh create mode 100755 tests/base_modes_test.sh diff --git a/os/mini/release-check.sh b/os/mini/release-check.sh index d4d433426..64447d45a 100755 --- a/os/mini/release-check.sh +++ b/os/mini/release-check.sh @@ -655,6 +655,27 @@ payload_modes_verdict() { # [] 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: [] +base_modes_verdict() { # [] + _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 @@ -737,6 +758,13 @@ 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 10)" + 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)" # 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 @@ -1831,6 +1859,32 @@ else esac fi +# ── the BASE layer's modes (engine#1474) ──────────────────────────────────────────────────────────────────────── +# The scan is the root filesystem only: /data carries the models (7.9 GB on the board) and is not the OS, and the +# mounts below are either kept writable by the keep-list or are not on the image at all. Everything else is counted, with +# the keep-list applied from the machine's own copy so the row prints the list that decided it. +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_n=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP" | wc -l) + _bm_keep=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP") + # -prune the trees that are not the OS image, and the keep-list entries; count the rest + _bm_prune= + for _p in /proc /sys /dev /run /tmp /data /initrd /mnt /media /var/tmp /var/run /var/lock /var/spool /var/log /opt/1bit-package; do + _bm_prune="$_bm_prune -path $_p -prune -o" + done + # shellcheck disable=SC2086 # the prune expression is built as separate words on purpose + _bm_b=$(find / $_bm_prune \( -type f -o -type d \) \( -perm -g+w -o -perm -o+w \) -print 2>/dev/null | head -40) + _bm_n_paths=$(printf '%s' "$_bm_b" | grep -c . || true) + _bm_s=$(printf '%s\n' "$_bm_b" | head -3 | while IFS= read -r _p; do [ -n "$_p" ] && printf '%s %s ' "$(stat -c %A "$_p" 2>/dev/null)" "$_p"; done) + 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 diff --git a/os/v3/puppy/base-modes-keep b/os/v3/puppy/base-modes-keep new file mode 100644 index 000000000..bd3a917d6 --- /dev/null +++ b/os/v3/puppy/base-modes-keep @@ -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/ diff --git a/os/v3/puppy/container-build.sh b/os/v3/puppy/container-build.sh index b2e45345f..25cffedd0 100644 --- a/os/v3/puppy/container-build.sh +++ b/os/v3/puppy/container-build.sh @@ -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 \ diff --git a/os/v3/puppy/fix-ownership.sh b/os/v3/puppy/fix-ownership.sh index 1b10b79d5..0943b56fe 100755 --- a/os/v3/puppy/fix-ownership.sh +++ b/os/v3/puppy/fix-ownership.sh @@ -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" diff --git a/scripts/base-modes.sh b/scripts/base-modes.sh new file mode 100755 index 000000000..1e5af8048 --- /dev/null +++ b/scripts/base-modes.sh @@ -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 [--keep ] [--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 normalise and report (dirs 0755, executables 0755, other files 0644) +# base-modes.sh --report-only print the group/other-writable paths outside the keep-list, change nothing +# base-modes.sh --keep 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 diff --git a/scripts/pack-elf.sh b/scripts/pack-elf.sh index 3d74c0db6..e61cecc80 100644 --- a/scripts/pack-elf.sh +++ b/scripts/pack-elf.sh @@ -27,6 +27,11 @@ # and its RUNPATH becomes $ORIGIN plus the entries outside the # build tree and $HOME (TheRock in /opt, which HRX needs anyway) # pack_strip strips symbol tables and debug info from every ELF under +# pack_normalise_base_modes +# the BASE layer's modes: dirs 0755, executables 0755, other files 0644, keeping the +# paths in (engine#1474). Prints what it changed, by class +# pack_writable_base_files +# the reporter for the same thing: group/other-writable paths outside the keep-list # pack_build_rpaths prints each ELF under whose RPATH/RUNPATH still points # into or $HOME # pack_missing_libs prints ": ..." for each ELF under whose @@ -247,6 +252,103 @@ pack_normalise_modes() { find "$stage" -type f ! -perm -u+x -exec chmod 0644 {} + 2>/dev/null || true } +# ── the BASE layer's modes (engine#1474) ───────────────────────────────────────────────────────────────────────────── +# The payload's modes are settled (pack_normalise_modes above): c33 ships 0 group/other-writable files under +# opt/1bit-package. The layer UNDER it had 2,176 such paths measured on the c33 base SFS, 1,814 of them regular files -- +# every one of them inherited from woof-CE's build with the builder's umask, carried faithfully by `cp -a`, and none of +# them relied on by anything: the appliance runs as root, and root does not need group-write. Eight classes of path DO +# need it, and they are the ones in os/v3/puppy/base-modes-keep. +# +# These two functions are the fix and its reporter, in the same split as pack_normalise_modes/pack_writable_files: a +# function that normalises and then checks its own work can never fail. + +# _pack_keep_list : the keep-list as a newline-joined string, comments and whitespace gone. +# Read ONCE per run: the first version of the matcher re-read the file for every path in the tree, which is 60,000 file +# reads on a real base layer and took longer than the rest of the cycle put together. +_pack_keep_list() { + sed -e 's/#.*//' -e 's/[[:space:]]//g' "$1" 2> /dev/null | grep -v '^$' || true +} + +# _pack_keep_match : 0 when the path is a keep-list entry or below one. +# An entry covers the path ITSELF as well as everything under it -- `tmp/` keeps /tmp's mode 1777, not just `tmp/...` -- +# and matching is per COMPONENT (`var/log` does not keep `var/logrotate`). +_pack_keep_match() { + local rel=$1 pfx + while IFS= read -r pfx; do + [ -n "$pfx" ] || continue + pfx=${pfx%/} + case $rel in "$pfx"|"$pfx"/*) return 0 ;; esac + done <<< "$2" + return 1 +} + +# _pack_chmod_batch : chmod in chunks, because a tree this size overruns the argument list. +_pack_chmod_batch() { + local mode=$1 batch=() n=0 p + shift + for p in "$@"; do + batch+=("$p") + n=$((n + 1)) + if [ $n -ge 400 ]; then chmod "$mode" "${batch[@]}" 2> /dev/null; batch=(); n=0; fi + done + [ $n -gt 0 ] && chmod "$mode" "${batch[@]}" 2> /dev/null + return 0 +} + +# pack_normalise_base_modes : drop the GROUP AND OTHER WRITE BITS on every path in outside the +# keep-list, and change nothing else. +# +# The first version set "dirs 0755, executables 0755, other files 0644" the way the payload's normaliser does, and that +# was wrong for a whole operating system: it TAKES BITS AWAY FROM NOBODY but GRANTS them -- /etc/shadow and /etc/gshadow +# (0640) become 0644, every 0600 private key becomes readable, and a 0700 directory becomes traversable. The payload has no +# secrets, which is why the blunt rule is fine there; the base layer has all of them. `go-w` is the property engine#1474 +# is actually about (2,176 group/other-writable paths), it can only narrow, and the reporter below checks exactly it. +# +# Symlinks are skipped: their mode is not used by the kernel, and chmod would follow the link. +pack_normalise_base_modes() { + local tree=$1 list=$2 keep m rel + [ -d "$tree" ] || { echo "pack_normalise_base_modes: no tree $tree" >&2; return 2; } + [ -f "$list" ] || { echo "pack_normalise_base_modes: no keep-list $list" >&2; return 2; } + keep=$(_pack_keep_list "$list") + local -a dirs_=() execs_=() files_=() + local kept=0 + # three passes, each one find + a printf: nothing is stat'ed or forked per path + while IFS=$'\t' read -r rel; do + [ -n "$rel" ] || continue + if _pack_keep_match "$rel" "$keep"; then kept=$((kept + 1)); continue; fi + dirs_+=("$tree/$rel") + done < <(find "$tree" -type d \( -perm -0020 -o -perm -0002 \) -printf '%P\n') + while IFS=$'\t' read -r rel; do + [ -n "$rel" ] || continue + if _pack_keep_match "$rel" "$keep"; then kept=$((kept + 1)); continue; fi + execs_+=("$tree/$rel") + done < <(find "$tree" -type f -perm -u+x \( -perm -0020 -o -perm -0002 \) -printf '%P\n') + while IFS=$'\t' read -r rel; do + [ -n "$rel" ] || continue + if _pack_keep_match "$rel" "$keep"; then kept=$((kept + 1)); continue; fi + files_+=("$tree/$rel") + done < <(find "$tree" -type f ! -perm -u+x \( -perm -0020 -o -perm -0002 \) -printf '%P\n') + # go-w on the three classes -- BOTH group and other write: `g-w` alone left a 757 (o+w) behind, which the reporter + # then caught (measured). The counts are what the cycle log shows. + [ ${#dirs_[@]} -gt 0 ] && _pack_chmod_batch go-w "${dirs_[@]}" + [ ${#execs_[@]} -gt 0 ] && _pack_chmod_batch go-w "${execs_[@]}" + [ ${#files_[@]} -gt 0 ] && _pack_chmod_batch go-w "${files_[@]}" + printf 'base modes: go-w on %s directories, %s executables, %s other files (%s path(s) kept by the keep-list); no other bit changed\n' \ + "${#dirs_[@]}" "${#execs_[@]}" "${#files_[@]}" "$kept" +} + +# pack_writable_base_files : the reporter the release row uses -- group/other-writable paths in the base +# layer OUTSIDE the keep-list, which is what has to be zero. Prints " " and nothing when clean. +pack_writable_base_files() { + local tree=$1 list=$2 keep m rel + keep=$(_pack_keep_list "$list") + while IFS=$'\t' read -r m rel; do + [ -n "$rel" ] || continue + _pack_keep_match "$rel" "$keep" && continue + printf '%s %s\n' "$rel" "$m" + done < <(find "$tree" \( -type f -o -type d \) \( -perm -0020 -o -perm -0002 \) -printf '%m\t%P\n') +} + pack_build_rpaths() { local f find "$1" -type f -print0 | while IFS= read -r -d '' f; do diff --git a/tests/base_modes_test.sh b/tests/base_modes_test.sh new file mode 100755 index 000000000..e51dc06ef --- /dev/null +++ b/tests/base_modes_test.sh @@ -0,0 +1,99 @@ +#!/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_test.sh: the BASE layer's mode normaliser and its reporter (engine#1474), run over a real tree. +# +# What must hold, and each of these broke a plausible implementation while this was being written: +# * a keep-list line ending in "/" covers the directory ITSELF as well as everything under it, or /tmp loses its +# sticky+writable mode -- the single most damaging mistake this work can make; +# * a keep-list line without a trailing "/" is an exact name or a prefix of a component, not a string prefix +# (`var/lo` must not keep `var/lock`'s sibling `var/lost+found`... and `var/log` must not keep `var/logrotate`); +# * the normaliser only NARROWS: a 0600 secret and a 0700 directory keep every bit they had. Setting "other files +# 0644" the way the payload's normaliser does would have made /etc/shadow world-readable -- this is an operating +# system's base layer, not a package; +# * the reporter agrees with the normaliser: after a normalisation of a tree the reporter prints nothing except the +# keep-list's own entries, and it prints every one of them before the fix. +# +# usage: tests/base_modes_test.sh +# +# bash, not sh: scripts/pack-elf.sh is a bash library (process substitution, `local`), and this sources it. +set -u +root=${1:?usage: base_modes_test.sh } +lib=$root/scripts/pack-elf.sh +keep=$root/os/v3/puppy/base-modes-keep +[ -f "$lib" ] || { echo "no $lib"; exit 1; } +[ -f "$keep" ] || { echo "no $keep"; exit 1; } +# shellcheck disable=SC1090 +. "$lib" + +fail=0 +check() { if [ "$2" = 0 ]; then echo "ok $1"; else echo "FAIL $1"; fail=1; fi; } +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +tree=$t/tree +mkdir -p "$tree/bin" "$tree/usr/bin" "$tree/etc/acpi" "$tree/tmp" "$tree/var/log" "$tree/var/tmp" \ + "$tree/var/lock/subsys" "$tree/dev" "$tree/opt/1bit-package/1bit" "$tree/var/logrotate" +# the classes: a plain data file, an executable, a directory, and paths the keep-list protects +printf 'data\n' > "$tree/usr/share-doc.txt"; chmod 0664 "$tree/usr/share-doc.txt" +# a secret and a restricted directory: the property is go-w ONLY, so neither may gain a bit +printf 'secret\n' > "$tree/etc-shadow-like"; chmod 0600 "$tree/etc-shadow-like" +printf 'group\n' > "$tree/etc-shadow-0640"; chmod 0640 "$tree/etc-shadow-0640" +mkdir -p "$tree/private"; chmod 0700 "$tree/private" +chmod 0770 "$tree/etc/acpi" +printf '#!/bin/sh\n' > "$tree/usr/bin/tool"; chmod 0775 "$tree/usr/bin/tool" + +chmod 1777 "$tree/tmp" +chmod 0775 "$tree/var/log"; chmod 0775 "$tree/var/tmp"; chmod 0775 "$tree/var/lock"; chmod 0775 "$tree/var/lock/subsys" +chmod 0775 "$tree/dev" +chmod 0775 "$tree/var/logrotate" +mkdir -p "$tree/opt/1bit-package/1bit"; printf 'payload\n' > "$tree/opt/1bit-package/1bit/data"; chmod 0664 "$tree/opt/1bit-package/1bit/data"; chmod 0775 "$tree/opt/1bit-package/1bit" + +# a keep-list that is the repository's, plus the payload excluded by the caller (the reporter is pointed at the base only) +before=$(pack_writable_base_files "$tree" "$keep" | wc -l) +[ "$before" -ge 2 ]; check "the reporter finds the writable base paths before the fix ($before)" $? + +out=$(pack_normalise_base_modes "$tree" "$keep") +case $out in *"go-w on"*) true ;; *) false ;; esac +check "the normaliser reports what it changed [$out]" $? + +[ "$(stat -c %a "$tree/usr/share-doc.txt")" = 644 ]; check "a world-writable data file loses o+w (0664 -> 0644)" $? +[ "$(stat -c %a "$tree/usr/bin/tool")" = 755 ]; check "a group-writable executable loses g+w (0775 -> 0755)" $? +[ "$(stat -c %a "$tree/etc/acpi")" = 750 ]; check "a 0770 directory keeps its owner/group bits (-> 0750, not 0755)" $? +[ "$(stat -c %a "$tree/etc-shadow-like")" = 600 ]; check "a 0600 secret stays 0600 (the normaliser never grants a bit)" $? +[ "$(stat -c %a "$tree/etc-shadow-0640")" = 640 ]; check "a 0640 file stays 0640 (/etc/shadow must not become world-readable)" $? +[ "$(stat -c %a "$tree/private")" = 700 ]; check "a 0700 directory stays 0700" $? +[ "$(stat -c %a "$tree/tmp")" = 1777 ]; check "the keep-list line 'tmp/' keeps /tmp ITSELF (sticky 1777)" $? +[ "$(stat -c %a "$tree/var/log")" = 775 ]; check "the keep-list keeps var/log" $? +[ "$(stat -c %a "$tree/var/log/subsys" 2>/dev/null || stat -c %a "$tree/var/tmp")" = 775 ] +check "the keep-list keeps a path BELOW a prefix (var/tmp)" $? +[ "$(stat -c %a "$tree/var/logrotate")" = 755 ]; check "a sibling that merely shares a prefix (var/logrotate) is NOT kept" $? +[ "$(stat -c %a "$tree/dev")" = 775 ]; check "the keep-list keeps dev" $? + +# a second run is a no-op: idempotent, and the second report says so +out2=$(pack_normalise_base_modes "$tree" "$keep") +case $out2 in "base modes: go-w on 0 directories, 0 executables, 0 other files ("*) + check "a second run changes nothing [$out2]" 0 ;; + *) check "a second run changes nothing [$out2]" 1 ;; +esac + +after=$(pack_writable_base_files "$tree" "$keep") +[ -z "$after" ]; check "the reporter is clean after the fix (outside the keep-list)" $? +# and it still sees everything if the keep-list is absent -- the row must be able to fail +: > "$t/empty-keep" +nostray=$(pack_writable_base_files "$tree" "$t/empty-keep" | wc -l) +[ "$nostray" -ge 5 ]; check "with an empty keep-list the reporter reports the kept paths too ($nostray)" $? + +[ $fail = 0 ] && echo "base_modes: ok" || echo "base_modes: FAILED" +exit $fail diff --git a/tools/copyright.py b/tools/copyright.py index bbe742caf..384ae2ec9 100644 --- a/tools/copyright.py +++ b/tools/copyright.py @@ -34,6 +34,9 @@ (("*.py", "*.sh", "*.yml", "*.yaml", "*.cff", "*.cmake", "*.cmake.in", "CMakeLists.txt", ".gitmodules", ".gitignore", ".gitattributes", ".clang-format", "*.toml", "*.config", "*.fragment", "*.example", "*.service", "*.timer", "*.conf", "*.env", "lemonade-hrx", "packages-extra", "05onboard-data", "10lemonade", "zz-onboard-ports", "20onboard-ssh", + # engine#1474: the BASE layer's keep-list is a '#'-comment data file read by scripts/base-modes.sh, listed by name + # like packages-extra above because it has no extension + "base-modes-keep", "21serial-console", "90onboard-limits", "Dockerfile", "*.Dockerfile", # cycle 17: Puppy's switch that skips its first-run Quick Setup is an empty marker file whose only content # is this notice - Puppy tests for its existence, so a comment is free From a1b61a32cb179fb4816d4dfa159e9e04481d7693 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 17:41:53 -0400 Subject: [PATCH 2/4] os: patch-sfs can normalise the base layer as it packs, so a CYCLE cut gets the fix too (#1474) The previous commit put the normaliser in fix-ownership.sh, which runs for a full woof-CE build. A cycle does not build: it unpacks the previous SFS, replaces a few paths and repacks - and that is what ships. `patch-sfs.sh --keep-modes ` now normalises BOTH trees immediately before mksquashfs (the artifact IS $work/new), which keeps the declared-set metadata proof honest - the same transformation on each side means a mode line that differs is still a difference the patch made - and it refuses the packed SFS if the verify tree is still writable outside the keep-list. Measured on a fixture: `changed.txt` 664 -> 644 in the artifact, `other.txt` 775 -> 755, the keep-listed `usr/bin/kept.sh` stays 775, and the run ends "base modes: the packed SFS is clean outside keep.txt". `tests/patch_sfs_atomic_test.sh` still 11/11 (the flag is opt-in; without it a cut behaves exactly as before). The first attempt put the block after the pack, which the tool's own verify check caught as 'modes/owners/types/sizes are not the packed tree's' - the artifact had the un-normalised modes. --- os/v3/puppy/patch-sfs.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/os/v3/puppy/patch-sfs.sh b/os/v3/puppy/patch-sfs.sh index 197fe2707..e77f20ec6 100755 --- a/os/v3/puppy/patch-sfs.sh +++ b/os/v3/puppy/patch-sfs.sh @@ -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 : 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 @@ -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; @@ -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 From 8570c8f6867b47c6f82044f81491444807b4d5fb Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 17:57:49 -0400 Subject: [PATCH 3/4] os: the base-modes row can be pointed at a tree, so it can be tested off a board (#1474) A row that can only be judged by booting an image cannot be tested - and this one was written with no way to run it. It now takes `BASE_SCAN_ROOT=` (the same trick the payload row already uses with `PAYLOAD_DIR`), with the prunes relative to that root, and it was checked both ways before the commit: the un-normalised base SFS tree reports 40+ writable paths (FAIL) and the normalised tree reports 0 (PASS). The boot-based check stays what the row does on a machine; this only makes it possible to run the scan without one. --- os/mini/release-check.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/os/mini/release-check.sh b/os/mini/release-check.sh index 64447d45a..0140281c2 100755 --- a/os/mini/release-check.sh +++ b/os/mini/release-check.sh @@ -1869,13 +1869,19 @@ if [ ! -f "$BKEEP" ]; then else _bm_n=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP" | wc -l) _bm_keep=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP") - # -prune the trees that are not the OS image, and the keep-list entries; count the rest + # 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, and the first version of this one could not be run at all off a board. `BASE_SCAN_ROOT=` + # points it at any tree of the same shape, which is how it was checked both ways: the un-normalised base SFS tree gives + # "40+ writable path(s)" (head-capped, so FAIL) and the normalised one gives "0 writable path(s)" (PASS). + BROOT=${BASE_SCAN_ROOT:-/} + BROOT=${BROOT%/} + # -prune the trees that are not the OS image; count the rest _bm_prune= - for _p in /proc /sys /dev /run /tmp /data /initrd /mnt /media /var/tmp /var/run /var/lock /var/spool /var/log /opt/1bit-package; do - _bm_prune="$_bm_prune -path $_p -prune -o" + for _p in proc sys dev run tmp data initrd mnt media var/tmp var/run var/lock var/spool var/log opt/1bit-package; do + _bm_prune="$_bm_prune -path $BROOT/$_p -prune -o" done # shellcheck disable=SC2086 # the prune expression is built as separate words on purpose - _bm_b=$(find / $_bm_prune \( -type f -o -type d \) \( -perm -g+w -o -perm -o+w \) -print 2>/dev/null | head -40) + _bm_b=$(find "${BROOT:-/}" $_bm_prune \( -type f -o -type d \) \( -perm -g+w -o -perm -o+w \) -print 2>/dev/null | head -40) _bm_n_paths=$(printf '%s' "$_bm_b" | grep -c . || true) _bm_s=$(printf '%s\n' "$_bm_b" | head -3 | while IFS= read -r _p; do [ -n "$_p" ] && printf '%s %s ' "$(stat -c %A "$_p" 2>/dev/null)" "$_p"; done) BM=$(base_modes_verdict "$_bm_n_paths" "$_bm_n" "$_bm_s") From 29c501a47d685e70d66a6aace348477591087094 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Sun, 8 Nov 2026 18:13:03 -0400 Subject: [PATCH 4/4] os: the base-modes row counts the whole set, and its prune list comes from the keep-list (#1544 review) Two defects in the row, both real, both cheap: 1. `find ... | head -40` ran BEFORE the count, so `_bm_n_paths` was min(actual, 40): on the base layer this row exists for (2,176 writable paths) the failure sentence would have read "40 path(s)" - a 50x understatement in the one line a reader uses to judge severity. The find writes to a temp list, the count is `wc -l`, and only the SAMPLE is head-ed. 2. the prune list was a hand-copy of the keep-list, in a comment that claimed they were one thing. The next cycle to add a keep-list entry would have had no prune for it and the row would have failed on a path the keep-list explicitly allows, while the PASS branch printed that list as "the keep-list" that decided. The prune is now BUILT from the keep-list, and the four paths pruned for a different reason (`data initrd mnt media` - not part of the OS image) are named separately. Checked off-image with `BASE_SCAN_ROOT` (no boot needed): a fixture with 60 writable files and 7 writable directories now reports **67**, where the old row said 40; adding `big/` to the keep-list drops it to **65** with no other edit, which is the property the hand-copied list did not have. Also: the self-test's keep-list size is 11 (the shipped file's count, was 10), and the note about a zero-sized keep-list says where that case is covered (the row SKIPs on a missing file; an empty one is a repository error, not a machine state). --- os/mini/release-check.sh | 43 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/os/mini/release-check.sh b/os/mini/release-check.sh index 0140281c2..51391be1d 100755 --- a/os/mini/release-check.sh +++ b/os/mini/release-check.sh @@ -759,12 +759,15 @@ if [ "${1:-}" = --self-test ]; then 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 10)" + 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)" + 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 @@ -1860,30 +1863,40 @@ else fi # ── the BASE layer's modes (engine#1474) ──────────────────────────────────────────────────────────────────────── -# The scan is the root filesystem only: /data carries the models (7.9 GB on the board) and is not the OS, and the -# mounts below are either kept writable by the keep-list or are not on the image at all. Everything else is counted, with -# the keep-list applied from the machine's own copy so the row prints the list that decided it. +# 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=` 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_n=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP" | wc -l) _bm_keep=$(awk '{ sub(/#.*/, ""); gsub(/[[:space:]]/, ""); if ($0 != "") print }' "$BKEEP") - # 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, and the first version of this one could not be run at all off a board. `BASE_SCAN_ROOT=` - # points it at any tree of the same shape, which is how it was checked both ways: the un-normalised base SFS tree gives - # "40+ writable path(s)" (head-capped, so FAIL) and the normalised one gives "0 writable path(s)" (PASS). + _bm_n=$(printf '%s\n' "$_bm_keep" | grep -c . || true) BROOT=${BASE_SCAN_ROOT:-/} BROOT=${BROOT%/} - # -prune the trees that are not the OS image; count the rest + # 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 proc sys dev run tmp data initrd mnt media var/tmp var/run var/lock var/spool var/log opt/1bit-package; do + 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 - _bm_b=$(find "${BROOT:-/}" $_bm_prune \( -type f -o -type d \) \( -perm -g+w -o -perm -o+w \) -print 2>/dev/null | head -40) - _bm_n_paths=$(printf '%s' "$_bm_b" | grep -c . || true) - _bm_s=$(printf '%s\n' "$_bm_b" | head -3 | while IFS= read -r _p; do [ -n "$_p" ] && printf '%s %s ' "$(stat -c %A "$_p" 2>/dev/null)" "$_p"; done) + 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' ' '))" ;;