diff --git a/cmake/tests-release-check-payload-modes.cmake b/cmake/tests-release-check-payload-modes.cmake new file mode 100644 index 000000000..390d3a79d --- /dev/null +++ b/cmake/tests-release-check-payload-modes.cmake @@ -0,0 +1,21 @@ +# 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. +# +# engine#2422: `release-check.sh`'s payload-modes row printed the binaries' modes and judged only group/other-writability, so a +# payload whose `1bit/1bit` was 0644 read `PASS payload-modes (modes: 644 1bit/1bit …)` while hrx-placement read `SKIP` -- green +# over a payload that cannot run. The fixture builds three real payload trees (0644, 0755, no binaries) and runs the row against +# each; it fails on the pre-fix script with exactly the message from the issue, which is how it is known to test the claim and not +# the plumbing. ~34 s, no device, no build. +add_test(NAME release_check_payload_modes COMMAND bash ${CMAKE_SOURCE_DIR}/tests/release_check_payload_modes_test.sh ${CMAKE_SOURCE_DIR}/os/mini/release-check.sh) diff --git a/os/mini/release-check.sh b/os/mini/release-check.sh index ec1e5d525..c64a3eb03 100755 --- a/os/mini/release-check.sh +++ b/os/mini/release-check.sh @@ -779,6 +779,23 @@ kernel_cve_verdict() { fi } +payload_modes_noexec() { # -> the binaries present but not executable, space-separated and payload-relative + # engine#2422: the row prints the modes, and printing is not asserting. A 0644 `1bit/1bit` passes the writability rule and then + # makes hrx-placement SKIP (`[ -x ]` cannot find a runnable engine), so the check was green over a payload that cannot run. + # Absence is deliberately NOT an offender: a binary that is not here is hrx-device's or identity's claim, and a payload still + # being extracted is caught by the entry floor above. + # + # `[ -x ]` is the right predicate and NOT a stricter "is it 0755" (engine#2424's phrasing, worth keeping): the appliance runs as + # root, and access(2) documents that a real UID of zero passes X_OK "if execute permission is enabled for any of the file owner, + # group, or other". So the property is *can it execute*, which is exactly what the row that would start the engine tests. + _pe_dir=${1:-} _pe_out= + for _pe_b in "$_pe_dir/1bit/1bit" "$_pe_dir/bin/lemond" "$_pe_dir/lemond-onebit"; do + [ -f "$_pe_b" ] || continue + { [ -x "$_pe_b" ] || _pe_out="$_pe_out ${_pe_b#"$_pe_dir"/}"; } 2>/dev/null || true + done + printf '%s' "$_pe_out" +} + payload_modes_verdict() { # [] _f=${1:-} _d=${2:-} _sample=${3:-} case "$_f" in ''|*[!0-9]*) printf 'FAIL the payload'"'"'s file modes could not be counted (%s)' "${_f:-empty}"; return 0 ;; esac @@ -2196,13 +2213,26 @@ else while IFS= read -r _p; do _r=${_p#"$PDIR"}; _r=${_r#/}; printf '%s %s ' "$(stat -c %A "$_p" 2>/dev/null)" "${_r:-.}"; done) PM=$(payload_modes_verdict "${_pm_f:-}" "${_pm_d:-}" "${_pm_s:-}") _pm_bits= + # engine#2422: printing the bits is not asserting them. A 0644 `1bit/1bit` passes the writability rule and then makes + # hrx-placement SKIP (`[ -x ]` cannot find a runnable engine), so the release check was green over a payload whose + # engine cannot run - measured on a real 258-entry payload: `PASS payload-modes (modes: 644 1bit/1bit 644 bin/lemond)` + # beside `SKIP hrx-placement`. Absence stays out of this row's claim: a binary that is not here is hrx-device's or + # identity's business, and a payload mid-extraction is already caught by the floor above. for _b in "$PDIR/1bit/1bit" "$PDIR/bin/lemond" "$PDIR/lemond-onebit"; do [ -f "$_b" ] && _pm_bits="$_pm_bits $(stat -c '%a %n' "$_b" 2>/dev/null | sed "s|$PDIR/||")" done - case "$PM" in - PASS*) pass payload-modes "${PM#PASS }${_pm_bits:+ (modes:$_pm_bits)}" ;; - *) fail payload-modes "${PM#FAIL }${_pm_bits:+ (modes:$_pm_bits)}" ;; - esac + # The executability requirement is its own function so `tests/release_check_payload_modes_test.sh` can extract and test + # it without running the whole check: the first version of that fixture ran `release-check.sh --check` three times and cost + # **392 s** in CI (18 s locally became 130 s per arm in a container), which is not a price three `[ -x ]` lines may charge. + _pm_noexec=$(payload_modes_noexec "$PDIR") + if [ -n "$_pm_noexec" ]; then + fail payload-modes "in the payload but not executable:${_pm_noexec} - a 0644 engine or lemond refuses to run, and hrx-placement then SKIPs instead of failing (modes:$_pm_bits)" + else + case "$PM" in + PASS*) pass payload-modes "${PM#PASS }${_pm_bits:+ (modes:$_pm_bits)}" ;; + *) fail payload-modes "${PM#FAIL }${_pm_bits:+ (modes:$_pm_bits)}" ;; + esac + fi fi fi diff --git a/tests/release_check_payload_modes_test.sh b/tests/release_check_payload_modes_test.sh new file mode 100755 index 000000000..b019e3e23 --- /dev/null +++ b/tests/release_check_payload_modes_test.sh @@ -0,0 +1,79 @@ +#!/bin/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. +# payload-modes must REQUIRE the binaries it names to be executable (engine#2422). +# +# The row printed the modes and judged only group/other-writability, so a payload whose `1bit/1bit` was 0644 read +# `PASS payload-modes (modes: 644 1bit/1bit …)` while the row that would start the engine read `SKIP hrx-placement` +# (`[ -x ]` found no runnable binary). Green over a payload that cannot run. +# +# Three arms, because the fix has two ways to be wrong and only one of them is loud: +# * 0644 binaries must FAIL and NAME them -- otherwise the row still passes what it exists to catch; +# * 0755 binaries must PASS with the modes still printed -- otherwise it fails healthy payloads; +# * a payload with no binaries must still PASS -- absence is hrx-device's claim, not this row's, and turning it into a +# failure here would red every payload that ships the engine somewhere this row does not look. +# +# The payloads are real directories (empty files are enough: the floor wants >100 entries, and nothing here reads a +# byte of them), built under ~/.cache because /tmp is tmpfs on this box and `tools/ci/tmp_path_check.py` flags new /tmp +# sites by design. +# +# usage: release_check_payload_modes_test.sh +# +# The FIRST version of this fixture ran `release-check.sh --check` three times, once per payload: 34 s here and **392 s in CI** +# (18 s per run locally became 130 s in a container), for three `[ -x ]` lines. So it now does what the neighbouring +# `release_check_hrx_init_reason_test.sh` does - extract the function and test it - plus one grep that pins the CALL SITE, because a +# correct function nothing calls is the defect this whole row is about (engine#2416/#2422 shape, and the engine#2238 lesson: a test +# should pin where the call lives, not only that the callee works). +set -u + +RC=${1:?usage: release_check_payload_modes_test.sh } +[ -r "$RC" ] || { echo "not readable: $RC"; exit 1; } + +FN=$(awk '/^ *payload_modes_noexec\(\) \{/{f=1} f{print} f&&/^ *\}$/{exit}' "$RC") +[ -n "$FN" ] || { echo "FAIL no payload_modes_noexec() in $RC - the row cannot require an executable engine (engine#2422)"; exit 1; } +case "$RC" in + *"this line is never matched"*) : ;; +esac +grep -q 'payload_modes_noexec "\$PDIR"' "$RC" || { echo "FAIL payload_modes_noexec() is defined but never called on the payload - a guard nothing calls"; exit 1; } + +ROOT=$(mktemp -d "${TMPDIR:-$HOME/.cache}/release-check-pm.XXXXXX") || exit 1 +trap 'rm -rf "$ROOT"' EXIT +fail=0 + +mktree() { # + mkdir -p "$ROOT/$1/1bit" "$ROOT/$1/bin" + if [ "$2" != none ]; then + printf 'x' > "$ROOT/$1/1bit/1bit"; printf 'x' > "$ROOT/$1/bin/lemond" + chmod "$2" "$ROOT/$1/1bit/1bit" "$ROOT/$1/bin/lemond" + fi +} + +mktree p644 0644 +got=$(bash -c "$FN"$'\npayload_modes_noexec "$1"' _ "$ROOT/p644") +case "$got" in + *1bit/1bit*bin/lemond*) echo "ok a 0644 engine and lemond are both named as not executable" ;; + *) echo "FAIL a 0644 payload was not reported: '${got}'"; fail=1 ;; +esac + +mktree p755 0755 +got=$(bash -c "$FN"$'\npayload_modes_noexec "$1"' _ "$ROOT/p755") +[ -z "$got" ] && echo "ok a 0755 payload reports nothing" || { echo "FAIL a healthy payload was reported: '${got}'"; fail=1; } + +mktree pnone none +got=$(bash -c "$FN"$'\npayload_modes_noexec "$1"' _ "$ROOT/pnone") +[ -z "$got" ] && echo "ok a payload with no binaries reports nothing (absence is another row's claim)" || { echo "FAIL a binary-less payload was reported: '${got}'"; fail=1; } + +echo "release_check_payload_modes_test: $fail failure(s)" +exit $((fail > 0))