Repository navigation
Validate crypto keygen responses against the received frame length - #465
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the client-side crypto key-generation response handling by validating server-declared payload lengths against the actual received frame length, preventing stale bytes in the comm buffer from being deserialized as key material (notably on short/generic-header-only responses).
Changes:
- Add received-frame-length bounds checks to Curve25519 and Ed25519 keygen response parsing in
src/wh_client_crypto.c. - Introduce a POSIX-only “malformed response” regression test using a fake comm-layer server that sends truncated/oversized-declared frames.
- Register the new POSIX-port-owned test in the POSIX test runner so it runs before the real server thread starts.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/wh_client_crypto.c |
Adds defensive checks ensuring res->len/outSz fits within the received response frame before any response-body reads/deserialization. |
test-refactor/posix/wh_test_malformed_response.c |
New negative-path test that injects malformed response lengths via a fake comm server and asserts WH_ERROR_ABORTED across keygen algorithms. |
test-refactor/posix/wh_test_posix_main.c |
Registers and runs the new malformed-response test in the pre-server “misc” slot to avoid overlapping the real server. |
💡 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 #465
Scan targets checked: wolfhsm-crypto-bugs, wolfhsm-src
No new issues found in the changed files. ✅
yosuke-wolfssl
force-pushed
the
fix/f_5461
branch
from
July 28, 2026 00:36
9668c2d to
df8c9fe
Compare
AlexLanzano
requested changes
Jul 30, 2026
yosuke-wolfssl
force-pushed
the
fix/f_5461
branch
from
July 30, 2026 23:34
df8c9fe to
b5a4e7a
Compare
AlexLanzano
approved these changes
Jul 31, 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.
Problem
_Ed25519MakeKey()validated the server-declaredres->outSzagainstWOLFHSM_CFG_COMM_DATA_LEN— the compile-time size of the comm buffer —rather than against the number of bytes actually received. A malicious or
malfunctioning server could return a short frame (e.g. generic header only)
while declaring a large
outSz; the client then deserialized stalecomm-buffer bytes as Ed25519 key material. The same frame also left
res->keyIdandres->outSzread from beyond the received data.Fix (
src/wh_client_crypto.c)Bound the response against
res_len, the length reported bywh_Client_RecvResponse(), before any field of the response struct is read:res_len < hdr_szrejects frames too short to hold the response struct,and is evaluated first so the subtraction cannot wrap.
res->keyIdis no longer read from aframe that never arrived. The removed check sat inside
if (key != NULL) { if (res->outSz > 0) {, so it never ran on thecache-only path.
This matches the equivalent checks already on
mainin_HkdfMakeKey()and_CmacKdfMakeKey().Closes f-5461.
Verification
main. Builds clean under-Werror -Wall -Wextra.test-refactorsuite: 45 passed, 26 skipped, 0 failed of 71.