Fix unaligned memory access in ML-DSA#10816
Open
kojiws wants to merge 1 commit into
Open
Conversation
7f61577 to
93bdf07
Compare
|
retest this please |
|
93bdf07 to
e1b394a
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #10816
Scan targets checked: wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src
No new issues found in the changed files. ✅
Frauschi
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix unaligned memory access in ML-DSA (Dilithium) encoding and decoding functions in
wc_mldsa.c. Direct casts betweenbyte*and(s)word32*/word16*are replaced withwriteUnalignedWord32,readUnalignedWord32,writeUnalignedWord16andreadUnalignedWord16, which are safe on strict-alignment platforms such as ARM and AArch64.readUnalignedWord16/writeUnalignedWord16are newly added tomisc.c/misc.h, following the existing patterns of the word32/word64 helpers.L2292 (
WOLFSSL_MLDSA_ALIGNMENT <=4) and L2378 (<=8) are the cases that matter on real hardware: thise blocks are compiled on ARM 32-bit and AArch64 respectively, so the unaligned cast can cause a fault there.The parts guarded by
WOLFSSL_MLDSA_ALIGNMENT == 0or<=2don't cause faults, because those values are only used on x86/x64 and Apple AArch64 platforms that handle unaligned access in hardware. They are still fixed here to remove the undefined behavior and keep-Werror=cast-alignclean across all configurations.All cast-align compilation errors in
wc_mldsa.creproduced with the procedure below are fixed by this PR.(An error also comes up in the misc.c, it's out of scope in this PR.)
./configurewith the patterns of the options belowmake wolfcrypt/src/wc_mldsa.oHere is the solved error list.
(The locations are shifted by rebasing to master.)
Testing
./configurewith the patterns of the options belowmake clean && make && ./wolfcrypt/test/testwolfcryptChecklist