fix: zero-init RNG DMA response struct#446
Open
MarkAtwood wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Fixes an information disclosure bug in the RNG-DMA handler by ensuring the response struct is initialized before being serialized back to the client.
Changes:
- Zero-initialize
whMessageCrypto_RngDmaResponse resin_HandleRngDmato prevent leaking uninitialized stack data in responses.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| int ret = 0; | ||
| whMessageCrypto_RngDmaRequest req; | ||
| whMessageCrypto_RngDmaResponse res; | ||
| whMessageCrypto_RngDmaResponse res = {0}; |
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.
Bug
_HandleRngDmainsrc/wh_server_crypto.cdeclares its response structwhMessageCrypto_RngDmaResponse res;without initialization. That type is composed entirely of a 16-bytedmaAddrStatus.badAddrfield, which is written only on the twoWH_ERROR_ACCESSDMA-bounds-check branches. On the success path (and on any non-ACCESS error fromwc_RNG_GenerateBlock) nothing inresis written, yet the full struct is unconditionally translated viawh_MessageCrypto_TranslateRngDmaResponseand*outSize = sizeof(res)(16 bytes) is returned to the client. Result: 16 bytes of indeterminate server stack are disclosed to the client on every successful RNG-DMA call.Fix
Zero-initialize the response struct at declaration:
whMessageCrypto_RngDmaResponse res = {0};. One line, self-contained; eliminates the indeterminate-stack disclosure on the success and non-ACCESS-error paths.Verification
Reproduced against master HEAD. Compiled the translation unit with the live config (
-DWOLFHSM_CFG -DWOLFHSM_CFG_DMA, WC_NO_RNG undefined) against a wolfSSL--enable-allinstall — clean before and after the fix (gcc -Wall -Wextra, exit 0). The handler is live: guarded by#ifdef WOLFHSM_CFG_DMA+#ifndef WC_NO_RNG, which is the config a real posix server build uses.Reported by static analysis (Fenrir finding 464).