Repository navigation
Align remaining heap Aes/XtsAes allocations - #12180
Conversation
PR 12110 aligned heap Aes allocations via WC_ALLOC_AES, but several consumers still allocate Aes (and XtsAes) with plain XMALLOC, which only guarantees 8-byte alignment on 32-bit Arm. The NEON/asm AES paths issue 16-byte-aligned loads, so a misaligned context faults at runtime whenever the heap happens to place it 8-byte aligned (layout-dependent SIGBUS seen in the arm32 MC/DC lane's PKCS7 KAT). Convert the remaining heap allocation sites to WC_ALLOC_AES/WC_FREE_AES and add WC_ALLOC_XTS/WC_FREE_XTS for XtsAes contexts: - wolfcrypt/src/pkcs7.c: PKCS7 EncryptContent/DecryptContent Aes - src/keys.c: TLS cipher enc/dec Aes (freed in FreeCiphersSide) - src/internal.c: TicketEncDec Aes + FreeCiphersSide free - src/dtls13.c: DTLS 1.3 record-number Aes cipher - wolfcrypt/src/kdf.c: SRTP/SRTCP KDF Aes contexts - wolfcrypt/test/test.c: test Aes/XtsAes contexts SMALL_STACK stack-array paths keep their dual-mode frees; heap frees are guarded to match the heap allocations.
|
FIPS bundle builds (v5/v6 and selftest) overlay the frozen module files, whose aes.h predates the aligned Aes allocator: the WC_ALLOC_AES/WC_FREE_AES/WC_ALLOC_XTS/WC_FREE_XTS macros from the non-frozen aes.h are missing there, so the new allocation sites in src/keys.c, src/internal.c, wolfcrypt/test/test.c and friends fail to compile with -Wimplicit-function-declaration under -Werror (PRB 140-3-tests, fips-v6-tests, CAVP-selftest, known-configs-A-applem1, generic-config-parser on PR 12180). Provide the plain-allocator fallback definitions in settings.h for frozen-module builds only, gated like the WC_FIPS_186_4/5 selection: (defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) && !FIPS_VERSION3_GE(7,0,0). The v7 boundary matches master (its aes.h carries the real definitions) and non-FIPS/FIPS Ready builds take them from aes.h, so there is no redefinition. Call sites stay untouched.
The settings.h FIPS fallback defines WC_ALLOC_AES in frozen bundle builds, which lit up cmac.h's aligned branch (guarded on defined(WC_ALLOC_AES)): WC_ALLOC_CMAC then called wc_alloc_aligned/wc_free_aligned, which the frozen aes.c does not provide (PRB-CAVP-selftest-v2 #22796, -Wimplicit-function-declaration). Introduce WC_ALIGNED_ALLOC in the non-frozen aes.h aligned branch to mark that the aligned allocator is declared and defined, and guard cmac.h on it. Frozen builds keep the plain-allocator fallbacks for both Aes and Cmac contexts.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12180
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Coverage: 11 of 11 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
|
jenkins retest this please |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12180
Scan targets checked: bsdkm-src, bsdkm-bugs, linuxkm-src, linuxkm-bugs, wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): wolfcrypt/benchmark/benchmark.c
Coverage: 9 of 11 in-scope changed file(s) opened by the reviewer; not opened: wolfcrypt/src/hpke.c, wolfcrypt/src/wc_encrypt.c
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12180
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): bsdkm-src, bsdkm-bugs, linuxkm-src, linuxkm-bugs
Not reviewed (no scan target covers them): wolfcrypt/benchmark/benchmark.c
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Lite
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12180
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfcrypt-port-bugs, wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): bsdkm-src, bsdkm-bugs, linuxkm-src, linuxkm-bugs
Not reviewed (no scan target covers them): wolfcrypt/benchmark/benchmark.c
Coverage: 3 of 4 in-scope changed file(s) opened by the reviewer; not opened: wolfssl/wolfcrypt/settings.h
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
#12110 aligned heap Aes allocations via WC_ALLOC_AES, but several consumers still allocate Aes (and XtsAes) with plain XMALLOC, which only guarantees 8-byte alignment on 32-bit Arm. The NEON/asm AES paths issue 16-byte-aligned loads, so a misaligned context faults at runtime whenever the heap happens to place it 8-byte aligned (layout-dependent SIGBUS seen in the arm32 MC/DC lane's PKCS7 KAT).
Convert the remaining heap allocation sites to WC_ALLOC_AES/WC_FREE_AES and add WC_ALLOC_XTS/WC_FREE_XTS for XtsAes contexts:
SMALL_STACK stack-array paths keep their dual-mode frees; heap frees are guarded to match the heap allocations.