From 3c6b393c5f45c59293b5286b8ab009f9b451e202 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Sat, 14 Nov 2026 11:09:12 +0100 Subject: [PATCH 1/2] test: keep copied-image daemon tests CPU-independent under sanitizers Hosted x86 runners without SHA-NI hash with sha256.c's portable transform. The daemon fingerprints each copied-image peer (the ~785 MB sanitized test runner) before answering, and with ASan + UBSan instrumentation that took ~72-92 s per fingerprint on such runners, past the probes' 60 s exchange budget: daemon_runtime's identical-copy HELLO and foreign activation tests went red (exit 26 / 29) and the cli suite hit its 3600 s ceiling, depending only on which CPU the job drew. - sha256_transform (the portable block transform only) is compiled with no_sanitize("address", "undefined"). Measured per full hash, same input: GCC 13 x86-64 15.6 s -> 3.0 s, GCC 13 arm64 5.33 s -> 2.18 s, Apple clang arm64 2.2x; release builds and the hardware backends are unchanged, and cbm_sha256_update/final plus the block loop stay instrumented. - The copied-image probes now exit 30 (HELLO) / 31 (activation) when the daemon never answered inside the budget, so 26 / 29 mean only an answered refusal. A slow fingerprint now fails as itself and can no longer satisfy the changed-copy rejection assertion by timing out. Signed-off-by: Martin Vogel --- src/foundation/sha256.c | 16 ++++++++++++++++ tests/test_daemon_runtime.c | 4 ++++ tests/test_main.c | 11 +++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/foundation/sha256.c b/src/foundation/sha256.c index 1f1b393917..c43c186852 100644 --- a/src/foundation/sha256.c +++ b/src/foundation/sha256.c @@ -66,6 +66,22 @@ static const uint32_t K[64] = { #define SIG0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ ((x) >> 3)) #define SIG1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ ((x) >> 10)) +/* WHY no_sanitize: sanitized test runners fingerprint their own ~800 MB image + * (and copies of it) through this transform whenever the CPU has no SHA + * instructions. ASan + UBSan checks on these fixed-size rounds made one such + * hash 5.3x slower with GCC 13 on x86-64 (15.6 s vs 3.0 s measured; ~72-92 s + * on hosted runners without SHA-NI, past the 60 s copied-image exchange + * budget) and 2.4x slower on arm64, so a test verdict depended on which CPU + * the runner drew. Every access here is a compile-time-bounded index into the + * context or into one 64-byte block whose bounds the callers establish; + * cbm_sha256_update/final, the block loop and the hardware backends stay + * fully instrumented. Equality with the hardware backends is proven by + * cli_sha256_hardware_matches_portable_issue2441 and the NIST vectors. + * Release (unsanitized) builds are unaffected: the attribute only withholds + * instrumentation that -fsanitize would add. */ +#if defined(__clang__) || defined(__GNUC__) +__attribute__((no_sanitize("address", "undefined"))) +#endif static void sha256_transform(cbm_sha256_ctx *c, const uint8_t *data) { /* Scratch comes from the context, not this frame: a 256-byte local here * is fake-stacked by ASan's use-after-return mode on every 64-byte block diff --git a/tests/test_daemon_runtime.c b/tests/test_daemon_runtime.c index c34c45f5b2..666bb0d72f 100644 --- a/tests/test_daemon_runtime.c +++ b/tests/test_daemon_runtime.c @@ -5019,6 +5019,8 @@ TEST(daemon_runtime_mac_fast_path_rejects_foreign_main_image_mapping_active) { ASSERT_TRUE(fingerprint_differs); ASSERT_TRUE(started); ASSERT_TRUE(foreign_ran); + /* 26 = the daemon answered with a rejection. A probe that got no answer + * inside the exchange budget exits 30 and must not pass here. */ ASSERT_EQ(foreign_exit, 26); PASS(); } @@ -5092,6 +5094,8 @@ TEST(daemon_runtime_copied_image_fallback_accepts_identical_and_rejects_changed) ASSERT_TRUE(changed_copied); ASSERT_TRUE(changed_bytes); ASSERT_TRUE(changed_ran); + /* 26 = the daemon answered with a rejection; no answer inside the + * exchange budget exits 30 and fails here instead of passing. */ ASSERT_EQ(changed_exit, 26); #endif PASS(); diff --git a/tests/test_main.c b/tests/test_main.c index 4b3716c50c..51c78a7e1d 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -711,7 +711,11 @@ static int tf_maybe_run_runtime_hello_client(int argc, char **argv) { !client || cbm_daemon_runtime_client_close(client, TF_RUNTIME_IMAGE_EXCHANGE_TIMEOUT_MS); cbm_daemon_ipc_endpoint_free(endpoint); if (!accepted) { - return 26; + /* 26 only when the daemon ANSWERED and refused. No answer inside the + * exchange budget (the daemon still hashing this copy, or I/O) is 30: + * a slow peer-image hash must fail loudly as itself, never satisfy a + * rejection assertion by timing out. */ + return result.status == CBM_DAEMON_RUNTIME_CONNECT_ERROR ? 30 : 26; } return closed ? 0 : 27; } @@ -741,7 +745,10 @@ static int tf_maybe_run_runtime_activation_client(int argc, char **argv) { endpoint, &identity, (cbm_daemon_runtime_activation_action_t)action_value, TF_RUNTIME_IMAGE_EXCHANGE_TIMEOUT_MS, &result); cbm_daemon_ipc_endpoint_free(endpoint); - return exchanged && result.accepted ? 0 : 29; + if (!exchanged) { + return 31; /* no answer inside the exchange budget; see the HELLO probe */ + } + return result.accepted ? 0 : 29; } /* macOS adversarial HELLO probe: execute this mode from a foreign process From 871d9f07a23484beda09bf1f1709f93af44997a6 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Sat, 14 Nov 2026 12:22:45 +0100 Subject: [PATCH 2/2] style(sha256): spell the transform's no_sanitize attribute through a macro CI's clang-format 20 lays out an attribute on its own line between preprocessor guards differently from Homebrew's newer release, so the lint job failed on sha256.c:85 while the local format check passed. SHA256_NO_SANITIZE keeps the attribute on the signature line, as NO_BUILTIN_MEM does in mem_override_libc.c. No behaviour change: the macro expands to the same attribute (and to nothing on other compilers). Signed-off-by: Martin Vogel --- src/foundation/sha256.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/foundation/sha256.c b/src/foundation/sha256.c index c43c186852..47fc560003 100644 --- a/src/foundation/sha256.c +++ b/src/foundation/sha256.c @@ -78,11 +78,18 @@ static const uint32_t K[64] = { * fully instrumented. Equality with the hardware backends is proven by * cli_sha256_hardware_matches_portable_issue2441 and the NIST vectors. * Release (unsanitized) builds are unaffected: the attribute only withholds - * instrumentation that -fsanitize would add. */ + * instrumentation that -fsanitize would add. Spelled through a macro so the + * attribute sits on the signature line: an attribute on its own line between + * preprocessor guards is laid out differently by clang-format 20 (CI) and + * Homebrew's newer release (same reason as NO_BUILTIN_MEM in + * mem_override_libc.c). */ #if defined(__clang__) || defined(__GNUC__) -__attribute__((no_sanitize("address", "undefined"))) +#define SHA256_NO_SANITIZE __attribute__((no_sanitize("address", "undefined"))) +#else +#define SHA256_NO_SANITIZE #endif -static void sha256_transform(cbm_sha256_ctx *c, const uint8_t *data) { + +SHA256_NO_SANITIZE static void sha256_transform(cbm_sha256_ctx *c, const uint8_t *data) { /* Scratch comes from the context, not this frame: a 256-byte local here * is fake-stacked by ASan's use-after-return mode on every 64-byte block * (see the note on cbm_sha256_ctx::sched). Identical values, allocated