aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / scripts / qemu_ck_artifact_test.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Boot the AIENOS C kernel with the P2 sealed-artifact loader |
| 18 | # (native/kernel/core/artifact_loader.c) in QEMU AArch64 + UEFI (AAVMF) and |
| 19 | # check the serial console against the same expectations as the Rust gate |
| 20 | # scripts/qemu_artifact_test.sh (SEED-0B / P2-5). QEMU is not hardware: a |
| 21 | # PASS here qualifies nothing physical. |
| 22 | # |
| 23 | # The candidates come from the boot disk: at image build time the host tool |
| 24 | # native/kernel/tools/ck_store_image.c writes the signed artifacts into the |
| 25 | # sealed C Store (TEST identity, TEST keys) on a raw NVMe image; at boot the |
| 26 | # store stage reads them back over the SMMU-confined NVMe driver before the |
| 27 | # NVMe DMA revoke, and the loader verifies them as untrusted bytes. |
| 28 | # |
| 29 | # Three boots of the full image (devices, security, Store stages), each with |
| 30 | # QEMU iommu=smmuv3 and the NVMe image: |
| 31 | # 1. qualification build (make full CK_SEED0B_TEST_ANCHOR=1): trusts the RFC |
| 32 | # 8032 TEST 1 public key only (TEST ONLY); P26SEED, P25EXEC/WX/SPIN/TAMP, |
| 33 | # the hostile set H01..H29 with their expected stage and reason, and |
| 34 | # D01-DISK-MISSING (named in the disk index, no bytes on disk: refused |
| 35 | # at "received", FirmwareRead); |
| 36 | # 2. ordinary build (make full): empty production trust, every candidate refused; |
| 37 | # 3. qualification build on a copy of the disk with one byte of a sealed |
| 38 | # artifact envelope flipped: the Store is refused, no artifact byte is |
| 39 | # used, nothing is admitted. |
| 40 | # Every candidate's receipt is decoded, bound to the supplied artifact, |
| 41 | # digest-recomputed, TEST-signed and verified by the in-tree C tool. Every |
| 42 | # artifact the kernel read is checked against the host's SHA-256 of the file. |
| 43 | # Static check: no default image (core or full, production or qualification) |
| 44 | # contains fw_cfg artifact code; a CK_TEST_FWCFG_ARTIFACTS=1 image is built only |
| 45 | # to prove that check sees it, and is never booted here. |
| 46 | # |
| 47 | # Differences from qemu_artifact_test.sh, all deliberate (native/kernel/GATES.md): |
| 48 | # - builds with make (gcc), the artifacts with the in-tree C tool |
| 49 | # (native/kernel/tools/ck_artifact_tool.c), not cargo / the Rust tool; the |
| 50 | # probe programs are the committed fixtures, packed by the same pack.sh; |
| 51 | # - candidates are read from the sealed Store on the NVMe boot disk instead of |
| 52 | # ESP files read by a UEFI loader: the C boot stub reads no files; |
| 53 | # - no Machine 1 captured-log mode (SEED-0B Machine 1 stays with the Rust gate); |
| 54 | # - before building, prints NOT_RUN while the machine quiet flag or the QEMU |
| 55 | # gate lock is held, as in qemu_ck_boot_test.sh (scripts/lib_gate_hold.sh); |
| 56 | # - stricter: any QEMU exit status other than 0 fails. |
| 57 | # Last line: AIENOS_CK_P2_ARTIFACT: PASS|FAIL|NOT_RUN. |
| 58 | # Needs qemu-system-aarch64 and AAVMF (Ubuntu: qemu-system-arm qemu-efi-aarch64). |
| 59 | set -euo pipefail |
| 60 | |
| 61 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 62 | cd "${repo_root}" |
| 63 | verdict=AIENOS_CK_P2_ARTIFACT |
| 64 | |
| 65 | code_fd="${AAVMF_CODE:-/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd}" |
| 66 | vars_fd="${AAVMF_VARS:-/usr/share/AAVMF/AAVMF_VARS.fd}" |
| 67 | command -v qemu-system-aarch64 >/dev/null || { echo "qemu-system-aarch64 not installed"; echo "${verdict}: NOT_RUN"; exit 2; } |
| 68 | [[ -r "${code_fd}" && -r "${vars_fd}" ]] || { echo "AAVMF firmware not found"; echo "${verdict}: NOT_RUN"; exit 2; } |
| 69 | |
| 70 | # Machine quiet flag: one heavy run (builds included) at a time on the Spark. |
| 71 | # Machine quiet flag (read only) and the QEMU gate lock (one gate at a time): |
| 72 | # scripts/lib_gate_hold.sh (aienos#278). |
| 73 | . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib_gate_hold.sh" |
| 74 | if ! gh_quiet_check || ! gh_lock_take "qemu_ck_artifact_test" "${AIENOS_GATE_MINUTES:-60}"; then |
| 75 | echo "NOT_RUN ${gh_why}" |
| 76 | echo "${verdict}: NOT_RUN" |
| 77 | exit 3 |
| 78 | fi |
| 79 | # Release only this run's own gate lock record, at most once. |
| 80 | release_flag() { gh_lock_release; } |
| 81 | work="$(mktemp -d)" |
| 82 | cleanup() { |
| 83 | rm -rf "${work}" |
| 84 | release_flag |
| 85 | } |
| 86 | trap cleanup EXIT |
| 87 | failed=0 |
| 88 | pass() { echo "PASS $1"; } |
| 89 | fail() { echo "FAIL $1"; failed=1; } |
| 90 | |
| 91 | cross="" |
| 92 | if [ "$(uname -m)" != "aarch64" ]; then cross="aarch64-linux-gnu-"; fi |
| 93 | commit="$(git rev-parse HEAD 2>/dev/null || echo unknown)" |
| 94 | out_prod="${repo_root}/target/native-kernel" |
| 95 | out_qual="${repo_root}/target/native-kernel-seed0b-test" |
| 96 | out_fwcfg="${repo_root}/target/native-kernel-test-fwcfg" |
| 97 | mk() { make -s -C native/kernel CROSS="${cross}" AIENOS_COMMIT="${commit}" "$@" >/dev/null; } |
| 98 | mk OUT="${out_prod}" |
| 99 | mk OUT="${out_prod}" full |
| 100 | mk OUT="${out_qual}" CK_SEED0B_TEST_ANCHOR=1 |
| 101 | mk OUT="${out_qual}" CK_SEED0B_TEST_ANCHOR=1 full |
| 102 | mk OUT="${out_fwcfg}" CK_TEST_FWCFG_ARTIFACTS=1 |
| 103 | make -s -C native/kernel OUT="${out_prod}" tool store-image gpt-image >/dev/null |
| 104 | tool="${out_prod}/host/ck_artifact_tool" |
| 105 | simg="${out_prod}/host/ck_store_image" |
| 106 | |
| 107 | # ---- static: the fw_cfg side channel is compiled out of every default image ---- |
| 108 | fwcfg_pat='opt/aienos/artifacts|fw_cfg|QEMU0002' |
| 109 | fwcfg_syms=' (fw_select|fw_read|fw_skip|fw_find|fwcfg_from_dsdt|fwcfg_source|fwcfg)$' |
| 110 | for d in "${out_prod}" "${out_prod}/full" "${out_qual}" "${out_qual}/full"; do |
| 111 | s=$(grep -aoE "${fwcfg_pat}" "${d}/BOOTAA64.EFI" | sort -u | tr '\n' ' ' || true) |
| 112 | y=$("${cross}nm" "${d}/aienos-ck.elf" | grep -E "${fwcfg_syms}" | tr '\n' ' ' || true) |
| 113 | if [[ -z "${s}${y}" ]]; then pass "default image ${d#"${repo_root}"/}: no fw_cfg artifact strings or symbols" |
| 114 | else fail "default image ${d#"${repo_root}"/} carries fw_cfg artifact code: ${s}${y}"; fi |
| 115 | done |
| 116 | if grep -aqF "opt/aienos/artifacts" "${out_fwcfg}/BOOTAA64.EFI" \ |
| 117 | && grep -aqF "TEST-ONLY QEMU fw_cfg side channel" "${out_fwcfg}/BOOTAA64.EFI"; then |
| 118 | pass "the check sees fw_cfg code in a CK_TEST_FWCFG_ARTIFACTS=1 image, which announces TEST-ONLY (not booted, never counted)" |
| 119 | else |
| 120 | fail "CK_TEST_FWCFG_ARTIFACTS=1 image lacks the fw_cfg source or its TEST-ONLY announcement" |
| 121 | fi |
| 122 | |
| 123 | # ---- inputs ----------------------------------------------------------------- |
| 124 | fixtures="crates/aienos-artifact-tool/fixtures/p2_5" |
| 125 | seed_fixtures="crates/aienos-artifact-tool/fixtures/p2_6" |
| 126 | art="${work}/artifacts" |
| 127 | mkdir -p "${art}" |
| 128 | "${fixtures}/pack.sh" "${tool}" "${art}" >/dev/null |
| 129 | "${seed_fixtures}/pack.sh" "${tool}" "${art}" >/dev/null |
| 130 | mv "${art}/ids.txt" "${work}/ids.txt" |
| 131 | "${tool}" negative-corpus "${art}" >/dev/null |
| 132 | mv "${art}/expected.txt" "${work}/expected.txt" |
| 133 | for f in "${art}"/H*.AIEN; do |
| 134 | n=$(basename "${f}") |
| 135 | awk -v n="${n}" '$1 == n { found = 1 } END { exit !found }' "${work}/ids.txt" \ |
| 136 | || echo "${n} $("${tool}" id "${f}" 2>/dev/null || echo none)" >>"${work}/ids.txt" |
| 137 | done |
| 138 | mapfile -t files < <(find "${art}" -maxdepth 1 -name '*.AIEN' | LC_ALL=C sort) |
| 139 | missing=D01-DISK-MISSING.AIEN |
| 140 | missing_len=4096 |
| 141 | candidate_count=$(( ${#files[@]} + 1 )) |
| 142 | id_prefix() { awk -v n="$1" '$1 == n { print substr($2, 1, 16) }' "${work}/ids.txt"; } |
| 143 | |
| 144 | # ---- boot disk: signed artifacts into the sealed Store (image build time) ---- |
| 145 | disk="${work}/nvme.img" |
| 146 | # GPT boot disk: the Store lives only inside its AIENOS partition (dev/disk_part.h). |
| 147 | "${out_prod}/host/ck_gpt_image" create "${disk}" 512 64 aienos-middle >/dev/null || fail "GPT boot disk image created" |
| 148 | if "${simg}" build "${disk}" 512 "${files[@]}" "missing:${missing}:${missing_len}" >"${work}/build.txt" 2>&1; then |
| 149 | pass "boot disk built: $(head -1 "${work}/build.txt")" |
| 150 | else |
| 151 | fail "boot disk build: $(head -3 "${work}/build.txt" | tr '\n' ' ')" |
| 152 | fi |
| 153 | # The empty file stands for the absent artifact in the host receipt checks. |
| 154 | : >"${art}/${missing}" |
| 155 | "${simg}" list "${disk}" 512 >"${work}/list.txt" 2>&1 || fail "host read-back of the boot disk Store" |
| 156 | rb_ok=1 |
| 157 | for f in "${files[@]}"; do |
| 158 | n=$(basename "${f}") |
| 159 | grep -qxF "${n} bytes=$(stat -c %s "${f}") sha256=$(sha256sum "${f}" | cut -d' ' -f1)" "${work}/list.txt" || rb_ok=0 |
| 160 | done |
| 161 | grep -qxF "${missing} bytes=${missing_len} missing" "${work}/list.txt" || rb_ok=0 |
| 162 | if [[ "${rb_ok}" == 1 ]]; then pass "host read-back: all ${#files[@]} artifacts byte-identical in the Store, ${missing} absent" |
| 163 | else fail "host read-back of the boot disk Store differs from the files"; fi |
| 164 | |
| 165 | boot() { # image, serial text output, disk image |
| 166 | local esp="${work}/esp" log="${work}/serial.log" started status |
| 167 | rm -rf "${esp}" |
| 168 | mkdir -p "${esp}/EFI/BOOT" "${esp}/EFI/AIENOS" |
| 169 | touch "${esp}/EFI/AIENOS/BOOTREPORT.TXT" |
| 170 | cp "$1" "${esp}/EFI/BOOT/BOOTAA64.EFI" |
| 171 | cp "${vars_fd}" "${work}/vars.fd" |
| 172 | started=$(date +%s) |
| 173 | set +e |
| 174 | # Issue #61: single-threaded TCG; MTTCG hung in 1/40 soak boots. |
| 175 | nice -n 10 timeout "${AIENOS_QEMU_TIMEOUT:-300}" qemu-system-aarch64 \ |
| 176 | -M virt,virtualization=on,gic-version=3,iommu=smmuv3 -accel tcg,thread=single -cpu max -smp 4 -m 2048 \ |
| 177 | -drive if=pflash,format=raw,readonly=on,file="${code_fd}" \ |
| 178 | -drive if=pflash,format=raw,file="${work}/vars.fd" \ |
| 179 | -drive if=none,id=esp,format=raw,file=fat:rw:"${esp}" \ |
| 180 | -device virtio-blk-pci,drive=esp \ |
| 181 | -drive if=none,id=nvme0,format=raw,file="$3" \ |
| 182 | -device nvme,drive=nvme0,serial=aienos-nvme-test \ |
| 183 | -device ramfb -display none -nic none \ |
| 184 | -serial file:"${log}" -no-reboot |
| 185 | status=$? |
| 186 | set -e |
| 187 | tr -d '\r' <"${log}" >"$2" |
| 188 | echo "qemu exit ${status} after $(( $(date +%s) - started )) s (commit ${commit:0:12})" |
| 189 | [[ "${status}" == 0 ]] || fail "QEMU exit status ${status} (124 = timeout)" |
| 190 | } |
| 191 | |
| 192 | has() { grep -qE -- "$2" "$1"; } |
| 193 | check() { if has "$1" "$3"; then pass "$2"; else fail "$2"; fi; } |
| 194 | check_absent() { if has "$1" "$3"; then fail "$2"; else pass "$2"; fi; } |
| 195 | common_checks() { # serial [candidate count] |
| 196 | local want="${2:-${candidate_count}}" |
| 197 | check "$1" "left firmware and entered the kernel" "kernel: alive" |
| 198 | check "$1" "M3 cooperative threads unchanged" "threads: ok" |
| 199 | check "$1" "M3 EL0 isolation proof unchanged" "el0: ok write=granted forged=denied fault=contained exit=0" |
| 200 | check "$1" "M3 typed IPC proof unchanged" "ipc: ok message=delivered cap=delegated rights=attenuated forged=denied revoked=denied" |
| 201 | check "$1" "kernel read all ${want} artifact candidates" "^artifact_candidates: ${want}$" |
| 202 | if grep -q "^report-truncated:" "$1"; then fail "kernel report lines were truncated"; else pass "no kernel report line was truncated"; fi |
| 203 | check "$1" "final report reached the console" "report_kind: final" |
| 204 | if has "$1" "report_kind: (panic|fault)"; then fail "panic or fault reported"; fi |
| 205 | if has "$1" "^receipt: [^ ]+ seq=[0-9]+ invalid$"; then fail "a candidate produced no valid receipt"; fi |
| 206 | if has "$1" "^artifact_bundle: malformed"; then fail "kernel found the candidate list malformed"; fi |
| 207 | check_absent "$1" "no TEST-ONLY fw_cfg source in a counted boot" "TEST-ONLY QEMU fw_cfg|^artifact_source: fw_cfg" |
| 208 | local before after |
| 209 | before=$(grep -oE "artifact_frames_free_before: [0-9]+" "$1" | awk '{print $2}' | tail -1) |
| 210 | after=$(grep -oE "artifact_frames_free_after: [0-9]+" "$1" | awk '{print $2}' | tail -1) |
| 211 | if [[ -n "${before}" && "${before}" == "${after}" ]]; then |
| 212 | pass "every frame returned after all candidates (${before} free before and after)" |
| 213 | else |
| 214 | fail "frame accounting across candidates (before=${before:-?} after=${after:-?})" |
| 215 | fi |
| 216 | } |
| 217 | disk_checks() { # serial: the candidates came from the boot disk, as read by the kernel |
| 218 | check "$1" "SMMUv3 enabled; NVMe confined" "smmu: enabled" |
| 219 | check "$1" "store stage committed this boot" "^store: committed generation=[0-9]+ boot_count=[0-9]+" |
| 220 | check "$1" "artifact index read from the boot disk Store" \ |
| 221 | "^artifact_disk: index generation=[0-9]+ entries=${candidate_count} chunks_used=[0-9]+ chunks_ignored=0 sha256=[0-9a-f]{64}$" |
| 222 | check "$1" "artifact_source=nvme_store with every candidate" \ |
| 223 | "^artifact_source: nvme_store generation=[0-9]+ candidates=${candidate_count} " |
| 224 | local ok=1 f n |
| 225 | for f in "${files[@]}"; do |
| 226 | n=$(basename "${f}") |
| 227 | has "$1" "^artifact_disk: ${n//./\\.} bytes=$(stat -c %s "${f}") sha256=$(sha256sum "${f}" | cut -d' ' -f1)$" || { ok=0; echo " missing or different on the kernel side: ${n}"; } |
| 228 | done |
| 229 | if [[ "${ok}" == 1 ]]; then pass "kernel read all ${#files[@]} artifacts from NVMe, each SHA-256 equal to the host file" |
| 230 | else fail "kernel-side SHA-256 of the disk artifacts"; fi |
| 231 | check "$1" "${missing} named on disk without bytes: reported missing, not used" \ |
| 232 | "^artifact_disk: ${missing//./\\.} bytes=${missing_len} missing chunks=0/1; not used$" |
| 233 | check "$1" "${missing} refused cleanly at received (FirmwareRead), reclaimed" \ |
| 234 | "^artifact: ${missing//./\\.} rejected stage=received reason=FirmwareRead reclaimed=yes$" |
| 235 | local total=0 |
| 236 | for f in "${files[@]}"; do total=$(( total + $(stat -c %s "${f}") )); done |
| 237 | check "$1" "kernel heap copies of the disk artifacts released after the loader" \ |
| 238 | "^artifact_disk: released heap copies artifacts=${#files[@]} bytes=${total}$" |
| 239 | local ld lr ls |
| 240 | ld=$(grep -n '^artifact_disk: ' "$1" | grep -v ':artifact_disk: released ' | tail -1 | cut -d: -f1) |
| 241 | lr=$(grep -n 'dma_gate: nvme bus master revoked' "$1" | head -1 | cut -d: -f1) |
| 242 | ls=$(grep -n '^artifact_source: ' "$1" | head -1 | cut -d: -f1) |
| 243 | if [[ -n "${ld}" && -n "${lr}" && -n "${ls}" && "${ld}" -lt "${lr}" && "${lr}" -lt "${ls}" ]]; then |
| 244 | pass "disk read finished before the NVMe DMA revoke; verification ran after it" |
| 245 | else |
| 246 | fail "order: disk read (${ld:-?}) < NVMe revoke (${lr:-?}) < loader (${ls:-?})" |
| 247 | fi |
| 248 | } |
| 249 | rtag="" |
| 250 | receipt_check() { # serial name pattern |
| 251 | local serial="$1" name="$2" want="$3" line record kdigest out |
| 252 | line=$(grep -E "^receipt: ${name//./\\.} seq=[0-9]+ digest=[0-9a-f]{64} record=[0-9a-f]{1024}$" "${serial}" | tail -1 || true) |
| 253 | if [[ -z "${line}" ]]; then fail "${name} receipt emitted"; return; fi |
| 254 | record=${line##*record=} |
| 255 | kdigest=$(sed -E 's/.* digest=([0-9a-f]{64}) .*/\1/' <<<"${line}") |
| 256 | local file="${work}/${rtag}-${name}.receipt" |
| 257 | if ! "${tool}" receipt from-hex "${record}" "${file}" >/dev/null 2>&1; then fail "${name} receipt record decodes on the host"; return; fi |
| 258 | if ! out=$("${tool}" receipt check "${file}" "${art}/${name}" 2>&1); then |
| 259 | fail "${name} receipt binds the supplied artifact (${out})"; return |
| 260 | fi |
| 261 | if [[ "${out}" != *"digest=${kdigest} "* ]]; then fail "${name} receipt digest recomputed by the host"; return; fi |
| 262 | if ! grep -qE -- "${want}" <<<"${out}"; then fail "${name} receipt records the observed outcome (${out})"; return; fi |
| 263 | if ! "${tool}" receipt sign-test "${file}" "${file}.signed" >/dev/null 2>&1; then fail "${name} receipt TEST ONLY signing"; return; fi |
| 264 | if "${tool}" receipt verify "${file}.signed" | grep -q "RECEIPT_VERIFY: PASS digest=${kdigest} "; then |
| 265 | pass "${name} receipt: bound, host digest match, observed outcome, TEST ONLY signature verifies" |
| 266 | else |
| 267 | fail "${name} signed receipt verifies" |
| 268 | fi |
| 269 | } |
| 270 | stage_code() { case "$1" in received) echo 1;; staged) echo 2;; verified) echo 3;; authorized) echo 4;; |
| 271 | reserved) echo 5;; mapped) echo 6;; hashed) echo 7;; sealed) echo 8;; caps) echo 9;; *) echo x;; esac; } |
| 272 | status_of() { case "$1" in exited:*) echo Exited;; timeout) echo Timeout;; fault:*) echo Fault;; |
| 273 | bad-syscall:*) echo BadSyscall;; resource-overrun) echo ResourceOverrun;; *) echo NotRun;; esac; } |
| 274 | admitted_line() { # name, exec regex, caps |
| 275 | echo "^artifact: ${1//./\\.} admitted id=$(id_prefix "$1") tier=seed0b-test exec=$2 bytes=identified=verified=admitted=mapped=executed wx=enforced caps=$3 revoked=yes reclaimed=yes frames=[0-9]+ " |
| 276 | } |
| 277 | |
| 278 | # ---- boot 1: qualification build ------------------------------------------- |
| 279 | qual="${work}/qualification.txt" |
| 280 | rtag=qual |
| 281 | cp "${disk}" "${work}/disk-qual.img" |
| 282 | boot "${out_qual}/full/BOOTAA64.EFI" "${qual}" "${work}/disk-qual.img" |
| 283 | common_checks "${qual}" |
| 284 | disk_checks "${qual}" |
| 285 | receipt_check "${qual}" "${missing}" "decision=Rejected .* stage=1 reason=0x10a status=NotRun exit=0 syscalls=0 reads_ok=0 denials=0 flags=0x04\$" |
| 286 | check "${qual}" "qualification build is labelled TEST ONLY" \ |
| 287 | "artifact_trust: seed0b-test qualification build — TEST ONLY" |
| 288 | check "${qual}" "receipts carry the SEED-0B-QEMU tier" "^artifact_receipt_tier: SEED-0B-QEMU$" |
| 289 | check "${qual}" "P26SEED read through its grant, WRITE and forged authority denied, exit 0, reclaimed" \ |
| 290 | "$(admitted_line P26SEED.AIEN exited:0x0 1)syscalls=9 reads=3 denials=5$" |
| 291 | check "${qual}" "P26SEED granted exactly its READ request" \ |
| 292 | "^grant: P26SEED\.AIEN\[0\] kind=object id=1 rights=0x1 bounds=0\+32 max_ops=4 max_bytes=32$" |
| 293 | if [[ $(grep -c "^grant: P26SEED\.AIEN\[" "${qual}") == 1 ]]; then pass "P26SEED holds exactly one capability"; else fail "P26SEED holds exactly one capability"; fi |
| 294 | receipt_check "${qual}" P26SEED.AIEN "decision=Admitted tier=SEED-0B-QEMU stage=0 reason=0x0 status=Exited exit=0 syscalls=9 reads_ok=3 denials=5 flags=0xff$" |
| 295 | check "${qual}" "P25EXEC executed its exact authenticated bytes, exit 0, caps revoked, reclaimed" \ |
| 296 | "$(admitted_line P25EXEC.AIEN exited:0x0 1)syscalls=3 reads=1 denials=1$" |
| 297 | check "${qual}" "P25WX killed by a W^X fault on its code page, reclaimed" \ |
| 298 | "$(admitted_line P25WX.AIEN fault:code-write 0)syscalls=0 reads=0 denials=0$" |
| 299 | check "${qual}" "P25SPIN killed at its time budget, reclaimed" \ |
| 300 | "$(admitted_line P25SPIN.AIEN timeout 0)syscalls=0 reads=0 denials=0$" |
| 301 | check "${qual}" "P25TAMP (payload byte flipped after signing) rejected BadSignature, reclaimed" \ |
| 302 | "^artifact: P25TAMP\.AIEN rejected stage=verified reason=BadSignature reclaimed=yes$" |
| 303 | receipt_check "${qual}" P25EXEC.AIEN "decision=Admitted .* status=Exited exit=0 syscalls=3 reads_ok=1 denials=1 flags=0xfd$" |
| 304 | receipt_check "${qual}" P25WX.AIEN "decision=Admitted .* status=Fault exit=0 syscalls=0 reads_ok=0 denials=0 flags=0xe4$" |
| 305 | receipt_check "${qual}" P25SPIN.AIEN "decision=Admitted .* status=Timeout exit=0 syscalls=0 reads_ok=0 denials=0 flags=0xe4$" |
| 306 | receipt_check "${qual}" P25TAMP.AIEN "decision=Rejected .* stage=3 reason=0x12 status=NotRun exit=0 syscalls=0 reads_ok=0 denials=0 flags=0x04$" |
| 307 | |
| 308 | matrix_total=0 matrix_admitted=0 |
| 309 | while read -r name decision a b c _; do |
| 310 | [[ -n "${name}" ]] || continue |
| 311 | matrix_total=$((matrix_total + 1)) |
| 312 | if [[ "${decision}" == rejected ]]; then |
| 313 | check "${qual}" "${name} refused at ${a} (${b}), never ran, reclaimed" \ |
| 314 | "^artifact: ${name//./\\.} rejected stage=${a} reason=${b} reclaimed=yes$" |
| 315 | receipt_check "${qual}" "${name}" "decision=Rejected .* stage=$(stage_code "${a}") reason=${c} status=NotRun exit=0 syscalls=0 reads_ok=0 denials=0 flags=0x04$" |
| 316 | else |
| 317 | matrix_admitted=$((matrix_admitted + 1)) |
| 318 | check "${qual}" "${name} admitted and contained (${a}), reclaimed" "$(admitted_line "${name}" "${a}" "${b}")" |
| 319 | receipt_check "${qual}" "${name}" "decision=Admitted .* status=$(status_of "${a}") " |
| 320 | fi |
| 321 | done < <(sed 's/ #.*//' "${work}/expected.txt") |
| 322 | [[ "${matrix_total}" -ge 29 ]] && pass "hostile matrix has ${matrix_total} cases" || fail "hostile matrix has only ${matrix_total} cases" |
| 323 | check "${qual}" "H29 requested READ|WRITE and was granted READ only" \ |
| 324 | "^grant: H29-READ-WRITE-REQUEST\.AIEN\[0\] kind=object id=1 rights=0x1 " |
| 325 | if has "${qual}" "^grant: H28-"; then fail "H28 (WRITE-only request) received a capability"; else pass "H28 requested only WRITE and received no capability"; fi |
| 326 | check "${qual}" "final report summarises every admission decision" \ |
| 327 | "^artifacts: candidates=${candidate_count} admitted=$((4 + matrix_admitted)) rejected=$((2 + matrix_total - matrix_admitted))$" |
| 328 | |
| 329 | # ---- boot 2: ordinary build, empty production trust ------------------------- |
| 330 | prod="${work}/production.txt" |
| 331 | rtag=prod |
| 332 | cp "${disk}" "${work}/disk-prod.img" |
| 333 | boot "${out_prod}/full/BOOTAA64.EFI" "${prod}" "${work}/disk-prod.img" |
| 334 | common_checks "${prod}" |
| 335 | disk_checks "${prod}" |
| 336 | if has "${prod}" "seed0b-test qualification build"; then fail "ordinary build must not carry the qualification label"; fi |
| 337 | if has "${prod}" "^artifact: [^ ]+ admitted"; then fail "ordinary build admitted an artifact"; else pass "ordinary build admitted nothing"; fi |
| 338 | prod_expect() { # name -> "stage reason code" in the ordinary build |
| 339 | local line |
| 340 | if [[ "$1" == "${missing}" ]]; then echo "received FirmwareRead 0x10a"; return; fi |
| 341 | line=$(sed 's/ #.*//' "${work}/expected.txt" | awk -v n="$1" '$1 == n') |
| 342 | if [[ -n "${line}" ]] && read -r _ d s r c <<<"${line}" && [[ "${d}" == rejected && "${s}" == verified \ |
| 343 | && "${r}" != BadSignature && "${r}" != UntrustedSigner ]]; then |
| 344 | echo "${s} ${r} ${c}" |
| 345 | else |
| 346 | echo "verified UntrustedSigner 0x11" |
| 347 | fi |
| 348 | } |
| 349 | for f in "${files[@]}" "${art}/${missing}"; do |
| 350 | name=$(basename "${f}") |
| 351 | read -r s r c <<<"$(prod_expect "${name}")" |
| 352 | check "${prod}" "ordinary build refuses ${name} (${r}), reclaimed" \ |
| 353 | "^artifact: ${name//./\\.} rejected stage=${s} reason=${r} reclaimed=yes$" |
| 354 | receipt_check "${prod}" "${name}" "decision=Rejected .* stage=$(stage_code "${s}") reason=${c} status=NotRun .* flags=0x04$" |
| 355 | done |
| 356 | check "${prod}" "final report summarises zero admitted" \ |
| 357 | "^artifacts: candidates=${candidate_count} admitted=0 rejected=${candidate_count}$" |
| 358 | |
| 359 | |
| 360 | # ---- boot 3: qualification build, one byte of the boot disk Store flipped ---- |
| 361 | corrupt="${work}/corrupt.txt" |
| 362 | cp "${disk}" "${work}/disk-corrupt.img" |
| 363 | loc=$("${simg}" locate "${work}/disk-corrupt.img" 512 P26SEED.AIEN 2>/dev/null || true) |
| 364 | c_off=$(sed -nE 's/^offset=([0-9]+) length=([0-9]+)$/\1/p' <<<"${loc}") |
| 365 | c_len=$(sed -nE 's/^offset=([0-9]+) length=([0-9]+)$/\2/p' <<<"${loc}") |
| 366 | if [[ -n "${c_off}" && -n "${c_len}" ]]; then |
| 367 | c_at=$(( c_off + c_len / 2 )) |
| 368 | c_old=$(od -An -tu1 -j "${c_at}" -N1 "${work}/disk-corrupt.img" | tr -d ' ') |
| 369 | printf "$(printf '\\%03o' $(( c_old ^ 0xa5 )))" \ |
| 370 | | dd of="${work}/disk-corrupt.img" bs=1 seek="${c_at}" count=1 conv=notrunc status=none |
| 371 | pass "corrupted one byte of P26SEED's sealed envelope on the disk copy (offset ${c_at})" |
| 372 | else |
| 373 | fail "locate P26SEED's envelope on the disk image (${loc})" |
| 374 | fi |
| 375 | if "${simg}" list "${work}/disk-corrupt.img" 512 >/dev/null 2>&1; then |
| 376 | fail "host Store open accepted the corrupted disk" |
| 377 | else |
| 378 | pass "host Store open refuses the corrupted disk" |
| 379 | fi |
| 380 | boot "${out_qual}/full/BOOTAA64.EFI" "${corrupt}" "${work}/disk-corrupt.img" |
| 381 | release_flag |
| 382 | common_checks "${corrupt}" 0 |
| 383 | check "${corrupt}" "kernel refuses the corrupted boot disk Store" "^store: REFUSED " |
| 384 | check "${corrupt}" "no artifact byte read from a refused Store" "^artifact_disk: none \(Store refused: " |
| 385 | check "${corrupt}" "loader reports no source, clean refusal" "^artifact_source: none \(" |
| 386 | check_absent "${corrupt}" "no artifact named or loaded from the corrupted disk" "^artifact(_disk)?: [A-Z][^ ]*\.AIEN " |
| 387 | check "${corrupt}" "final report: zero candidates, nothing admitted" "^artifacts: candidates=0 admitted=0 rejected=0$" |
| 388 | if [[ -n "${AIENOS_LOG_DIR:-}" ]]; then |
| 389 | cp "${qual}" "${AIENOS_LOG_DIR}/qemu_ck_artifact_qualification_serial.log" |
| 390 | cp "${prod}" "${AIENOS_LOG_DIR}/qemu_ck_artifact_production_serial.log" |
| 391 | cp "${corrupt}" "${AIENOS_LOG_DIR}/qemu_ck_artifact_corrupt_disk_serial.log" |
| 392 | fi |
| 393 | if [[ "${failed}" != 0 || -n "${AIENOS_QEMU_VERBOSE:-}" ]]; then |
| 394 | echo "---- qualification serial (artifact lines) ----" |
| 395 | grep -E "^(artifact|grant|kernel|report_kind|panic|fault|exception|esr|far)" "${qual}" | head -120 || true |
| 396 | fi |
| 397 | if [[ "${failed}" == 0 ]]; then echo "${verdict}: PASS"; else echo "${verdict}: FAIL"; exit 1; fi |