diff --git a/src/foundation/sha256.c b/src/foundation/sha256.c index 1f1b39391..47fc56000 100644 --- a/src/foundation/sha256.c +++ b/src/foundation/sha256.c @@ -66,7 +66,30 @@ 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)) -static void sha256_transform(cbm_sha256_ctx *c, const uint8_t *data) { +/* 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. 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__) +#define SHA256_NO_SANITIZE __attribute__((no_sanitize("address", "undefined"))) +#else +#define SHA256_NO_SANITIZE +#endif + +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 diff --git a/tests/test_daemon_runtime.c b/tests/test_daemon_runtime.c index c34c45f5b..666bb0d72 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 4b3716c50..51c78a7e1 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