Reject NULL metadata in checked NVM add path#462
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the DMA NVM “add object” path against a client-controlled NULL metadata pointer that could previously crash the server, and adds regression coverage for the vulnerable configuration (permit-all DMA with no callback/allowlist).
Changes:
- Add an early
meta == NULLvalidation inwh_Nvm_AddObjectChecked()to avoid dereferencing a NULL metadata pointer. - Add a boundary check in the server’s
ADDOBJECTDMAhandler to reject a NULL transformed metadata pointer before entering the NVM layer. - Extend the DMA NVM refactor test to exercise NULL/zero DMA address behavior and confirm correct error returns.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test-refactor/client-server/wh_test_nvm_ops.c | Adds a DMA regression test for NULL metadata DMA address and NULL data-with-length behavior. |
| src/wh_server_nvm.c | Rejects metadata == NULL in the ADDOBJECTDMA handler as defense-in-depth. |
| src/wh_nvm.c | Adds meta == NULL argument validation in wh_Nvm_AddObjectChecked() to prevent NULL dereference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #462
Scan targets checked: wolfhsm-core-bugs, wolfhsm-src
No new issues found in the changed files. ✅
Frauschi
approved these changes
Jul 23, 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.
Fix NULL metadata dereference in the DMA NVM add path
Fixes F-6789.
Problem
wh_Nvm_AddObjectCheckeddereferenced itsmetaargument twice beforevalidating it: once for
meta->idwhen callingwh_Nvm_CheckPolicy, andagain for the
sanitized = *metacopy that strips server-only flags.That pointer is client-controlled on the DMA path. The
ADDOBJECTDMAhandler in
wh_Server_HandleNvmRequestobtains it fromwh_Server_DmaProcessClientAddress, which defaults the transformedaddress to the raw client address and returns it unchanged when no DMA
callback and no DMA allowlist are registered. That permit-all setup is a
supported configuration, and 0 is a valid DMA address, so a client that
sends
metadata_hostaddr == 0crashed the server with a NULL dereference.The client API does not prevent this either:
wh_Client_NvmAddObjectDmaaccepts a NULL metadata pointer and forwards a zero
metadata_hostaddr.The other two callers of
wh_Nvm_AddObjectCheckedpass stack addresses,so only the DMA path was affected.
Fix
Two layers:
wh_Nvm_AddObjectCheckedreturnsWH_ERROR_BADARGSwhenmetaisNULL, matching the validation
wh_NvmFlash_AddObjectandwh_NvmFlashLog_AddObjectalready perform.ADDOBJECTDMAhandler rejects a NULL transformed metadata pointerat the boundary. This is defense in depth: it short-circuits before
taking the NVM lock and before the LMS/XMSS stateful-blob scan, and it
makes the handler's contract explicit. The check sits after both DMA
pre-operations so the matching post-operation cleanup still runs on the
rejection path.
The data pointer is deliberately not checked at the boundary. Both NVM
backends already reject
data == NULLwith a non-zero length, andwh_Crypto_IsStatefulSigPrivBlobNULL-checks its buffer, so a boundarycheck there could never change the outcome and would be unreachable by
any test.
Testing
_whTest_NvmDmaNullAddrsis added to the existingwhTest_NvmDmaentrypoint in
test-refactor/client-server/wh_test_nvm_ops.c. It sends a zerometadata DMA address and expects
WH_ERROR_BADARGS, and also sends avalid metadata pointer with a zero data address and a non-zero length to
pin the backend rejection. The POSIX test port registers neither a DMA
callback nor an allowlist, so it reproduces the vulnerable permit-all
configuration directly.
Before the fix the suite died with SIGSEGV inside
whTest_NvmDma. After:cd test-refactor && make check DMA=1— 41 passed, 21 skipped, 0 failedcd test-refactor && make check— 41 passed, 21 skipped, 0 failedcd test && make DMA=1 && make run— exit 0