Skip to content

Align remaining heap Aes/XtsAes allocations - #12180

Open
danielinux wants to merge 1 commit into
wolfSSL:masterfrom
danielinux:fix-aes-alloc-align-sweep
Open

danielinux wants to merge 1 commit into
wolfSSL:masterfrom
danielinux:fix-aes-alloc-align-sweep

Conversation

@danielinux

Copy link
Copy Markdown
Member

#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.

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.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants