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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,9 @@ add_test(NAME pack_modes COMMAND bash ${CMAKE_SOURCE_DIR}/tests/pack_modes_test.
# patch-sfs needs uid/gid and setuid bits - this is the only test here that does, hence the property.
add_test(NAME patch_sfs_atomic COMMAND ${CMAKE_SOURCE_DIR}/tests/patch_sfs_atomic_test.sh)
set_tests_properties(patch_sfs_atomic PROPERTIES SKIP_RETURN_CODE 77)
# build_path_strings must see compiler output, not only ELFs: a shipped devicetable-offsets.s with 449 build-tree paths
# passed the row that exists to stop that (engine#1487). No root, no fixture beyond two text files.
add_test(NAME pack_check_generated_text COMMAND bash ${CMAKE_SOURCE_DIR}/tests/pack_check_generated_text_test.sh)
# The GEMM designs are derived on the container's K grid and the kernel's N grid (engine#845); a
# model already on both is unchanged. Pure arithmetic + one assemble_B, so it runs without a model.
# The engine's derived design set for a set of dims, as `ROLE M K N elf` lines. The instrument the
Expand Down
49 changes: 43 additions & 6 deletions scripts/pack-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,57 @@
# of lemonade's 13 does not begin a line and `grep -c` reports 12 for a file carrying 13 (measured
# 2026-11-08 on c32's own bytes). /home/ covers any builder's home; the source tree, the workdir and the
# build tree cover a build that ran elsewhere on this machine.
# A GENERATED_TEXT file is compiler output that records a path, and the set is bounded and explained because the files in
# it do NOT all have the same remedy - that distinction is the reason this comment exists:
#
# *.s, *.mod.c, Module.symvers, modules.order what a PREFIX MAP can fix. `gcc -S` writes `.file "<abs path>"`, and the
# map rewrites those. Measured 2026-11-09 (engine#1487): two builds of
# linux-headers-7.4.0-rc1-1bit produced devicetable-offsets.s with the SAME
# 1,182 lines, one 62,895 B and one 49,425 B - the 13,470 B difference is
# exactly 449 lines x 30 B of absolute paths. Reproducible given the path.
# *.cmd, *.d what a prefix map CANNOT fix, by design: a .cmd records the compiler's
# argv as executed and a .d records dependency paths, both absolute on purpose.
# A red here means a BUILD TREE was packaged, whose remedy is to stop packaging
# it - not to map it. Written down because the day this guard meets a real
# kernel build tree it will red on files the map cannot touch, and the next
# reader must not conclude the guard is wrong.
#
# NOT every text file: a licence, a NOTICE or a man page may legitimately name a path, and a guard that reds those is a
# guard people turn off.
gen_text() {
case ${1##*/} in
*.s|*.cmd|*.mod.c|Module.symvers|modules.order|*.d) return 0 ;;
esac
return 1
}
build_path_strings() { # build_path_strings <unpacked tree> -> one FAIL line per offending file, rc 1
local t=$1 f n pats rc=0
local t=$1 f n pats rc=0 elfs=0 text=0
pats=$(printf '%s\n' /home/ "${SRC:-/nonexistent-build-src}" "${W:-/nonexistent-build-w}" \
"${BUILD:-/nonexistent-build-build}")
while IFS= read -r -d '' f; do
pack_is_elf "$f" || continue
n=$(strings -a "$f" | grep -o -F -f <(printf '%s\n' "$pats") | wc -l || true)
if pack_is_elf "$f"; then
elfs=$((elfs + 1))
n=$(strings -a "$f" | grep -o -F -f <(printf '%s\n' "$pats") | wc -l || true)
elif gen_text "$f"; then
# text, so grep reads it directly: `strings` would add nothing and costs a pipe per file
text=$((text + 1))
n=$(grep -o -F -f <(printf '%s\n' "$pats") "$f" 2> /dev/null | wc -l || true)
else
continue
fi
[ "$n" = 0 ] || {
printf 'FAIL %s names a build-machine path (%s occurrences): %s\n' "$(basename "$f")" "$n" \
"$(strings -a "$f" | grep -o -F -f <(printf '%s\n' "$pats") | head -2 | tr '\n' ' ')"
# the sample shows the PATH for a text file and the matching run for a binary: on a .s the pattern match alone
# reads "/home/ /home/", which names nothing and looks like a bug in the guard rather than in the artifact
if pack_is_elf "$f"; then
sample=$(strings -a "$f" 2> /dev/null | grep -o -F -f <(printf '%s\n' "$pats") | head -2 | tr '\n' ' ')
else
sample=$(grep -m2 -F -f <(printf '%s\n' "$pats") "$f" 2> /dev/null | sed 's/^[[:space:]]*//' | cut -c1-110 | tr '\n' ' ')
fi
printf 'FAIL %s names a build-machine path (%s occurrences): %s\n' "$(basename "$f")" "$n" "$sample"
rc=1
}
done < <(find "$t" -type f -print0)
[ "$rc" = 0 ] && echo "ok no packed ELF names a build-machine path (/home/, the source tree, the workdir, the build tree)"
[ "$rc" = 0 ] && echo "ok no packed ELF or generated text file names a build-machine path (${elfs} ELF, ${text} generated text; /home/, the source tree, the workdir, the build tree)"
return $rc
}

Expand Down
61 changes: 61 additions & 0 deletions tests/pack_check_generated_text_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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.
#
# pack_check_generated_text_test.sh - build_path_strings must red a leaking generated text file, not only a leaking ELF.
#
# Why: the guard walked every packed file with `pack_is_elf ... || continue`, so compiler output was invisible to it. A
# shipped `devicetable-offsets.s` carrying 449 absolute build-tree paths passed the row that exists to stop exactly that
# (engine#1487). The extension is bounded on purpose - `.s`, `.cmd`, `.mod.c`, `Module.symvers`, `modules.order`, `*.d` -
# because a licence or a man page may legitimately name a path and a guard that reds those is a guard people switch off.
set -uo pipefail

here=$(cd "$(dirname "$0")/.." && pwd)
. "$here/scripts/pack-check.sh"

work=$(mktemp -d /tmp/pcheck.XXXXXX) || exit 1
trap 'rm -rf "$work"' EXIT

fails=0; checks=0
check() { checks=$((checks + 1)); if [ "$2" = "$3" ]; then printf 'ok %s\n' "$1"; else printf 'FAIL %s: got %s want %s\n' "$1" "$2" "$3"; fails=$((fails + 1)); fi; }

mkdir -p "$work/red/scripts/mod" "$work/green/scripts/mod" "$work/licence"
# the shape a real one has: `.file "<abs path>"` directives, one per translation unit
printf ' .file "devicetable-offsets.c"\n# 13 "/home/builder/linux-7.4/scripts/mod/devicetable-offsets.c" 1\n# 0 "" 2\n' \
> "$work/red/scripts/mod/devicetable-offsets.s"
printf ' .file "devicetable-offsets.c"\n# 13 "linux/scripts/mod/devicetable-offsets.c" 1\n# 0 "" 2\n' \
> "$work/green/scripts/mod/devicetable-offsets.s"
# a text file OUTSIDE the bounded set: this is the case the list must not grow into, because licences name paths
printf 'This product includes software developed at /home/someone/project.\n' > "$work/licence/LICENSE"

check "a leaking .s is refused" "$(build_path_strings "$work/red" > /dev/null 2>&1; echo $?)" "1"
check "and it is named, with a path" \
"$(build_path_strings "$work/red" 2>&1 | grep -c 'devicetable-offsets.s names a build-machine path')" "1"
check "a clean .s passes" "$(build_path_strings "$work/green" > /dev/null 2>&1; echo $?)" "0"
check "the pass line counts what it looked at" \
"$(build_path_strings "$work/green" 2>&1 | grep -c '1 generated text')" "1"
check "a licence naming a path is NOT refused (the bounded set)" \
"$(build_path_strings "$work/licence" > /dev/null 2>&1; echo $?)" "0"
check "gen_text accepts the six generated shapes" \
"$(for n in a.s b.cmd c.mod.c Module.symvers modules.order d.d; do gen_text "$n" && printf y; done)" "yyyyyy"
# The two shapes a prefix map CANNOT fix are accepted on purpose: a red on them means a build tree was packaged, and the
# remedy is to stop packaging it. This check exists so that distinction is not "tidied away" by someone narrowing the list.
check "the shapes only 'do not package the tree' can fix are accepted, not narrowed out" \
"$(for n in x.cmd y.d; do gen_text "$n" && printf y; done)" "yy"
check "gen_text refuses a licence and a man page" \
"$(for n in LICENSE NOTICE 1bit.1 README.md; do gen_text "$n" && printf y; done)" ""

echo "pack_check_generated_text: $checks checks, $fails failed"
[ "$fails" = 0 ] || exit 1
Loading