Repository navigation
Aligned allocators - #11949
Aligned allocators#11949aidankeefe2022 wants to merge 7 commits into
Conversation
New set of tests and clean up
39dea99 to
9e875ab
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Memory-callback-disabled builds omit required allocator implementations, causing undefined references, while the new 4096-byte allocation test incorrectly fails valid low-resource static-memory configurations.
2 open issues
What changed in this PR
This PR adds aligned allocation and scrubbed reallocation APIs to wolfSSL’s memory layer, using existing allocator backends to preserve heap and allocation-type handling.
Changes:
- Adds aligned allocation APIs, override macros, and stack/heap declaration helpers.
- Uses scrubbed reallocation for big-integer storage and plaintext private-key buffers.
- Adds allocator tests and documents the new APIs and macros.
| File | Description |
|---|---|
wolfssl/wolfcrypt/types.h |
Adds allocator macros and aligned stack/heap helpers. |
wolfssl/wolfcrypt/memory.h |
Declares new APIs and exposes the zeroization test hook. |
wolfcrypt/test/test.c |
Adds alignment, reallocation, and scrubbing tests; adopts aligned AES allocation. |
wolfcrypt/src/memory.c |
Implements aligned allocation and scrubbed reallocation. |
wolfcrypt/src/integer.c |
Scrubs old digit storage when growing big integers. |
src/pk.c |
Scrubs old private-key DER storage during buffer growth. |
doc/dox_comments/header_files/types.h |
Documents allocator macros and their contracts. |
doc/dox_comments/header_files/memory.h |
Documents the five new public memory APIs. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11949
Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files/memory.h, doc/dox_comments/header_files/types.h
Coverage: 6 of 6 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: Lite
|
retest this please |
|
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11949
Scan targets checked: linuxkm-src, linuxkm-bugs, wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): cmake/functions.cmake, doc/dox_comments/header_files/memory.h, doc/dox_comments/header_files/types.h, src/include.am
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer
Findings: 2
2 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
added tons of tests fixed wolfSSL_Malloc to size check
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11949
Scan targets checked: linuxkm-src, linuxkm-bugs, wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): cmake/functions.cmake, doc/dox_comments/header_files/memory.h, doc/dox_comments/header_files/types.h, src/include.am
Coverage: 5 of 5 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: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.


Description
This is a set of allocators that manually align the allocation to what ever alignment is passed in.
There is also a new XREALLOC_SCRUBBED that is introduced.
This PR also changes the configurations to always compile memory.c this adds 1.9 KB to the binary size in --disable-memory builds. Let me know if we want to find a fix for this
Align Allocators
The purpose of these allocators is to enforce proper alignment when it is not handled for us https://fenrir.wolfssl.com/finding/11986 is an example.
This comes with 4 new public APIs
Each has a matching macro like XMALLOC etc.
These can be overridden by users same as XMALLOC but they have to be done as a group no mixing and matching implementations.
The alignment metadata is keep track of via a hidden header allocated before the start of the requested memory.
This allows for the use of XMALLOC and XFREE as our allocation backend meaning we automatically inherit any configuration such as static memory.
Scrubbed Realloc
This is somewhat not related to the first change. The scrubbed realloc wipes any chunk lost during reallocation.
Downside is that there is never an inplace reallocation. This is also true for ReallocAlign.
This is also another new API and Macro
Testing
A new battery of test was added along with this change to make sure every corner is covered
Checklist