Skip to content

Align remaining heap Aes/XtsAes allocations - #12180

Merged
JacobBarthelmeh merged 9 commits into
wolfSSL:masterfrom
danielinux:fix-aes-alloc-align-sweep
Nov 20, 2026
Merged

JacobBarthelmeh merged 9 commits 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.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m3

  • FLASH: .text +88 B (+0.1%, 133,774 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4

  • FLASH: .text +128 B (+0.1%, 211,117 B / 262,144 B, total: 81% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +64 B (+0.1%, 74,996 B / 262,144 B, total: 29% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 198,820 B / 1,048,576 B, total: 19% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +128 B (+0.0%, 808,332 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +64 B (+0.0%, 225,105 B / 262,144 B, total: 86% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 316,976 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +128 B (+0.0%, 347,560 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +128 B (+0.1%, 134,542 B / 262,144 B, total: 51% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +64 B (+0.0%, 253,703 B / 262,144 B, total: 97% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 211,117 B / 262,144 B, total: 81% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +64 B (+0.0%, 317,808 B / 1,048,576 B, total: 30% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +64 B (+0.0%, 253,703 B / 262,144 B, total: 97% used)

zephyr-frdm_rw612

  • FLASH: text -40 B (-0.0%, 296,076 B / 67,108,864 B, total: 0% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@danielinux danielinux self-assigned this Nov 19, 2026
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 wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@danielinux danielinux assigned wolfSSL-Bot and unassigned danielinux Nov 19, 2026
Comment thread wolfcrypt/test/test.c Resolved
@danielinux

Copy link
Copy Markdown
Member Author

jenkins retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread wolfcrypt/src/wc_she.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread wolfcrypt/src/wc_she.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@wolfSSL-Fenrir-bot
wolfSSL-Fenrir-bot dismissed stale reviews from themself November 20, 2026 12:56

Fenrir's latest completed scan found no issues; clearing the prior automated change request.

@JacobBarthelmeh
JacobBarthelmeh merged commit 733ae84 into wolfSSL:master Nov 20, 2026
453 of 455 checks passed
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.

5 participants