Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/patches/44e7cb9a6cacd03d # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## fix: restrict clean-user cleanup to accounts created by this run merged `44e7cb9a6cacd03d` #130 · opened 2026-10-27 05:34 UTC · closed 2026-10-29 01:33 UTC · merged 2026-10-29 01:33 UTC Imported from GitHub aien-dev/CUDApp#130, by drakestapleton Labels: ready-to-merge Base `67f3135ef88d8f520dfc15a2b2bc3264f53f0d6a` · Head `274de4b41b737016dd3ec7d6187909425b2d077c` Merged on GitHub as `eab71f898045db3842a6ceef8d5decaf3503a570`; reachable from main `21d8de285f713adf09e0d6ba6db2b37139d0674e` (observed 2026-11-18T16:38:28Z) drakestapleton wrote on 2026-10-27 05:34 UTC ## Evidence Head `274de4b41b737016dd3ec7d6187909425b2d077c`, based on main `67f3135ef88d8f520dfc15a2b2bc3264f53f0d6a`. The published Git tree exactly matches the locally verified, independently reviewed tree. - `bash tests/dx/clean_user_cleanup_test.sh`: 23 passed, 0 failed, exit 0. All privilege, network and GPU-entry commands are nondelegating mocks. - The same final test against the original #118 script: 19 passed, 4 failed, exit 1. - Mutation controls reject early ownership, missing ownership, clock-only names, ignored temporary-directory failure, and unexpected privileged commands. - Bash syntax and whitespace checks pass. Independent review found no outstanding findings. - Local `make test` and `make -j2` both exit 2 because the x86_64 assembler rejects unchanged AArch64 barrier instructions: `omega_blackwell_engine.c:393,558`; parallel build also reaches `omega_blackwell_submit.c:284,377,541,622`. This remains a local architecture limitation; the ARM64 CI results below are measured separately. ## Exact-head CI All workflows completed successfully for head `274de4b41b737016dd3ec7d6187909425b2d077c`. The synthetic PR test-merge tree matches the reviewed head tree exactly. - ARM64 host tests and SBOM : raw job log ends with `CUDA++ HOST TESTS PASS (39 targets)`. - hello-sim : raw log confirms 23 cleanup checks passed, 0 failed and 12 hello simulator checks passed, 0 failed. - Library build , runtime API , drift , and CodeQL : SUCCESS. ## Fix The #118 harness installs its exit trap before account creation. If `useradd` fails because the candidate name already exists, the old cleanup still attempts to kill that account's processes and remove its home. - Record ownership only after successful account creation. - Clean up the account only when this invocation owns it. - Derive the candidate from the random temporary-directory suffix rather than UTC seconds alone. - Abort before account setup if temporary-directory creation fails. - Retain mocked regressions in the existing `test-hello-sim` target, exercised by ARM64 hello-sim CI. Refs #118. Three files only. No runtime, driver, C, encoder, API, README, historical receipt, or gate weakening. ## Limits No real account creation/deletion, privileged command, GPU/device run, installation, service change, merge, or deployment was performed for this repair. Real-account and GB10/GPU validation are NOT_RUN; ARM64 host-only CI completed as recorded above. The change is ready for maintainer review; this does not claim completed qualification or authorize merging. ### Apply it ``` git checkout -b patch-44e7cb9a6cacd03d 67f3135ef88d8f520dfc15a2b2bc3264f53f0d6a curl -fsSL https://interplane.io/drakestapleton/CUDApp/patches/44e7cb9a6cacd03d.patch | git am ``` Raw patch (mbox) · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/CUDApp 130 274de4b41b737016dd3ec7d6187909425b2d077c ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"CUDApp","number":130,"url":"https://github.com/aien-dev/CUDApp/pull/130","export_sha256":"0aafd51b77ff5776d6baaf9b88b48c8b36a6e27c8d829ae8ded561b71712b17a","imported_utc":"2026-11-18T16:38:28Z"} ``` ### Changes ``` diff --git a/mk/dx-sim.mk b/mk/dx-sim.mk index ece28b29..f03e13f1 100644 --- a/mk/dx-sim.mk +++ b/mk/dx-sim.mk @@ -4,4 +4,5 @@ # line and that two runs give the same bits. Host only: --sim never opens a device. .PHONY: test-hello-sim test-hello-sim: $(OUT_DIR)/hello_gpu $(OUT_DIR)/hello_gpu_control + bash tests/dx/clean_user_cleanup_test.sh sh tests/dx/hello_sim_test.sh $(OUT_DIR)/hello_gpu $(OUT_DIR)/hello_gpu_control diff --git a/tests/dx/clean_user_cleanup_test.sh b/tests/dx/clean_user_cleanup_test.sh new file mode 100644 index 00000000..236b91d1 --- /dev/null +++ b/tests/dx/clean_user_cleanup_test.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# Host-only orchestration tests. All privilege, network and GPU-entry commands +# are mocked; no real user account, sudo, network request or device is used. +set -euo pipefail +root=$(cd "$(dirname "$0")/../.." && pwd) +script=${1:-$root/tools/runtime/clean-user-hello.sh} +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +mkdir "$work/bin" +cat > "$work/bin/sudo" <<'MOCK' +#!/usr/bin/env bash +set -eu +printf '%s\n' "$*" >> "$MOCK_CALLS" +case "$1" in + useradd) exit "$MOCK_USERADD_RC" ;; + -u) exit 0 ;; # Never execute the requested login shell. + test) exit 1 ;; # No real trace was produced. + pkill|userdel|rm) exit 0 ;; # Record only; never execute. + *) echo UNEXPECTED_PRIVILEGE >> "$MOCK_CALLS"; echo "unexpected privileged command: $1" >&2; exit 99 ;; +esac +MOCK +cat > "$work/bin/curl" <<'MOCK' +#!/usr/bin/env bash +echo curl >> "$MOCK_CALLS" +exit 7 # Stop after account creation, before README/GPU execution. +MOCK +cat > "$work/bin/flock" <<'MOCK' +#!/usr/bin/env bash +echo UNEXPECTED_GPU_ENTRY >> "$MOCK_CALLS" +exit 99 +MOCK +cat > "$work/bin/getent" <<'MOCK' +#!/usr/bin/env bash +exit 2 # The mock account is absent after successful mock deletion. +MOCK +cat > "$work/bin/date" <<'MOCK' +#!/usr/bin/env bash +printf '%s\n' 010203 # Make clock-based names collide deterministically. +MOCK +real_mktemp=$(command -v mktemp) +cat > "$work/bin/mktemp" <<'MOCK' +#!/usr/bin/env bash +if [ "${MOCK_MKTEMP_FAIL:-0}" = 1 ]; then exit 1; fi +exec "$REAL_MKTEMP" "$@" +MOCK +chmod +x "$work/bin/"* +pass=0; fail=0 +check() { + local name=$1; shift + if "$@"; then echo "PASS $name"; pass=$((pass + 1)) + else echo "FAIL $name"; fail=$((fail + 1)); fi +} +no_account_cleanup() { ! grep -Eq '^(pkill|userdel) ' "$1"; } +no_privilege() { [ ! -s "$1" ]; } +run_case() { + local name=$1 add_rc=$2 temp_fail=${3:-0} + mkdir -p "$work/$name/tmp" + : > "$work/$name/calls" + set +e + env PATH="$work/bin:/usr/bin:/bin" \ + REAL_MKTEMP="$real_mktemp" MOCK_CALLS="$work/$name/calls" \ + MOCK_USERADD_RC="$add_rc" MOCK_MKTEMP_FAIL="$temp_fail" \ + TMPDIR="$work/$name/tmp" CUDAPP_BOARD= \ + bash "$script" main "$work/$name/run.log" > "$work/$name/output" 2>&1 + rc=$? + set -e + check "$name-exit-3" test "$rc" -eq 3 + check "$name-never-enters-gpu" test "$(grep -c UNEXPECTED_GPU_ENTRY "$work/$name/calls" || true)" -eq 0 + check "$name-only-expected-privilege" test "$(grep -c UNEXPECTED_PRIVILEGE "$work/$name/calls" || true)" -eq 0 +} + +# useradd exit 9 means the candidate account already exists. Its processes and +# home belong to someone else; the cleanup must never issue deletion commands. +run_case collision 9 +check existing-account-untouched no_account_cleanup "$work/collision/calls" +run_case failure 1 +check failed-creation-untouched no_account_cleanup "$work/failure/calls" + +# Successful creation followed by a network/setup failure must still remove +# precisely the owned temporary account, not leak it or use a different name. +run_case created 0 +created=$(sed -n 's/^useradd -m -s \/bin\/bash //p' "$work/created/calls") +check created-name-nonempty test -n "$created" +check owned-process-cleanup grep -Fxq "pkill -u $created" "$work/created/calls" +check owned-account-cleanup grep -Fxq "userdel -r $created" "$work/created/calls" +check one-owned-account-deletion test "$(grep -c '^userdel ' "$work/created/calls" || true)" -eq 1 + +# Even with the same UTC clock value, simultaneous/repeated candidates differ. +run_case created_again 0 +again=$(sed -n 's/^useradd -m -s \/bin\/bash //p' "$work/created_again/calls") +check distinct-candidate-names test "$created" != "$again" + +# A missing temporary directory must abort before creating any account. +run_case temp_failure 0 1 +check temp-failure-no-privilege no_privilege "$work/temp_failure/calls" + +echo "clean-user cleanup tests: $pass passed, $fail failed (mocked commands only)" +[ "$fail" -eq 0 ] diff --git a/tools/runtime/clean-user-hello.sh b/tools/runtime/clean-user-hello.sh index 85d087d4..5915ac00 100755 --- a/tools/runtime/clean-user-hello.sh +++ b/tools/runtime/clean-user-hello.sh @@ -17,26 +17,34 @@ log=${2:?usage: clean-user-hello.sh BRANCH LOG [URL]} url=${3:-https://github.com/aien-dev/CUDApp} lock=${CUDAPP_GPU_LOCK:-/tmp/aien-gb10.lock} board=${CUDAPP_BOARD:-} -U=c2stranger$(date -u +%H%M%S) +user_created=0 cd / || exit 3 run() { echo "+ $*"; "$@"; } note() { [ -n "$board" ] && echo "$(date -u +%FT%TZ) $*" >> "$board"; return 0; } -tr_dir=$(mktemp -d "${TMPDIR:-/tmp}/clean-user-trace.XXXXXX") +tr_dir=$(mktemp -d "${TMPDIR:-/tmp}/clean-user-trace.XXXXXX") || exit 3 +# Reuse the unique temporary-directory suffix instead of a clock-only name. +# useradd is the atomic ownership check: an existing account is never ours. +U=c2stranger${tr_dir##*.} exec > >(tee "$log") 2>&1 echo "# clean-user-hello: branch=$branch url=$url user=$U" echo "# date: $(date -u +%FT%TZ) host: $(uname -srm) loadavg: $(cut -d' ' -f1-3 /proc/loadavg)" echo "# operator: $(id -un) nvidia module: $(cat /sys/module/nvidia/version 2>/dev/null || echo none)" cleanup() { if sudo test -s "$tr_dir/readme.trace"; then sudo gzip -9c "$tr_dir/readme.trace" > "$log.strace.gz" && echo "# full trace of the README block kept: $log.strace.gz"; fi - echo "# --- delete the temporary user ---" - run sudo pkill -u "$U" || true - run sudo userdel -r "$U" 2>&1 | grep -v 'mail spool' || true + if [ "$user_created" -eq 1 ]; then + echo "# --- delete the temporary user ---" + run sudo pkill -u "$U" || true + run sudo userdel -r "$U" 2>&1 | grep -v 'mail spool' || true + if getent passwd "$U" >/dev/null || [ -e "/home/$U" ]; then echo "# CLEANUP FAILED: $U still present"; else echo "# user $U and /home/$U removed"; fi + else + echo "# no account created by this run; account cleanup skipped" + fi sudo rm -rf "$tr_dir" - if getent passwd "$U" >/dev/null || [ -e "/home/$U" ]; then echo "# CLEANUP FAILED: $U still present"; else echo "# user $U and /home/$U removed"; fi } trap cleanup EXIT echo "# --- create a brand-new user ---" run sudo useradd -m -s /bin/bash "$U" || exit 3 +user_created=1 # the stranger's shell: an empty environment except what login(1) sets, then the distribution's login profile S() { sudo -u "$U" env -i HOME="/home/$U" USER="$U" LOGNAME="$U" SHELL=/bin/bash TERM=dumb LANG=C.UTF-8 PATH=/usr/local/bin:/usr/bin:/bin bash -lc "cd ~; $1"; } echo "# new user:" ```