Zero DMA destination buffer on server WRITE_PRE#486
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR closes a DMA bounce-buffer disclosure class in server-side DMA READ handlers by ensuring client destination buffers are either never mapped on refusal paths or are fully zero-filled before any partial writes, and it documents the resulting client-visible buffer contract.
Changes:
- Reorders READDMA / READTRUSTED_DMA logic to deny-before-map and adds destination-buffer zero-fill on successful WRITE_PRE mappings.
- Updates client and server header documentation to describe the destination-buffer contract and DMA callback locking constraints.
- Adds focused regression tests for zero-fill behavior (NVM + cert) and an AES DMA in-place aliasing guard test.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| wolfhsm/wh_server.h | Documents that DMA callbacks may run while the server NVM lock is held. |
| wolfhsm/wh_client.h | Documents the “write all bytes (data + zero tail), or untouched if refused” destination-buffer contract for DMA reads. |
| src/wh_server_cert.c | Implements deny-before-map, bounds cert_len, zero-fills mapped destination, and moves WRITE_POST outside the NVM lock for READTRUSTED_DMA. |
| src/wh_server_nvm.c | Implements deny-before-map and zero-fills mapped destination for NVM READDMA. |
| test-refactor/wh_test_list.c | Registers the new server DMA zero-fill test. |
| test-refactor/server/wh_test_dma_zerofill.c | New regression test suite covering refusal paths, short reads, carry-over, oversized lengths, and null mapping/address cases. |
| test-refactor/client-server/wh_test_crypto_aes.c | Adds AES DMA in-place aliasing test to guard against centralizing zero-fill in generic DMA address processing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yosuke-wolfssl
force-pushed
the
fix/f_4238
branch
from
July 24, 2026 05:28
8949da0 to
9b926c8
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #486
Scan targets checked: wolfhsm-core-bugs, wolfhsm-crypto-bugs, wolfhsm-src
No new issues found in the changed files. ✅
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.
Problem
WH_MESSAGE_CERT_ACTION_READTRUSTED_DMApassedreq.cert_lentoWRITE_POSTregardless of bytes written. On a port whose callback transfers in
WRITE_POST,an authenticated client received up to
cert_lenbytes of uninitialised servermemory when the read was denied (
WH_ERROR_ACCESS), when the id was absent, or —on success — past the end of a short certificate. NVM
READDMAhad the identicaldefect, unmentioned by the report. Addressed by F-4238.
Fix (
src/wh_server_cert.c)WRITE_PRE, so a refused request never maps client memory.wh_Server_CertReadTrusted()calls the uncheckedwh_Nvm_Read(), so this isthe only gate.
WRITE_PRE— the full mapped length is zeroed before theread, so the tail past a short object is zeros, not residue.
WH_ERROR_BADARGSwith no paired POST; a zero-length request stays a no-op.cert_lenbounded byWOLFHSM_CFG_MAX_CERT_SIZE. NVM objects have no sizecap, so the DMA allowlist bounds that handler's write extent — stated in
wolfhsm/wh_client.h.src/wh_server_nvm.cgets the same deny-before-map and zero-fill. Both handlerskeep
main's per-handler lock layout: NVM brackets its POST inside the lock,cert's POST stays outside (only cert's PRE had to move in for the deny check).
cert_lenof server heapClient-visible behavior changes:
WH_ERROR_ACCESS(wasBADARGS), closing alength oracle on protected objects.
read zeros the tail rather than leaving prior contents.
Tests
New
test-refactor/server/wh_test_dma_zerofill.c, 13 sub-tests across bothhandlers and both port shapes (bounce-buffer and direct-mapped): denied/absent
id, out-of-range offset, short read, no-carry, oversized length, null address,
null mapping, zero-length no-op, allowlist accept/reject, and cert
buffer-too-small. Registered in
whTestsServer[], run by 9DMA=1CI configson Linux and macOS.
whTest_CryptoAesDmaInPlaceguards against re-centralisingthe zero-fill, which corrupts in-place AES.
Verification
DMA=1), 43/27/0 (plain), 49/21/0 (THREADSAFE=1 DMA=1); legacysuite exits 0 both ways.