Validate SHE client response payload size before use#457
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 SHE client response parsing by validating that the received payload is large enough before overlaying/reading response structs, preventing stale-buffer data from being interpreted as valid output on truncated replies.
Changes:
- Added a shared
_CheckRespSz()guard and applied it at all SHE client receive sites to reject undersized responses before reading fixed fields. - For variable-length ECB/CBC crypt responses, additionally verify the declared
resp->szfits within the bytes actually received before copying. - Added a new
resp_sizeregression test that drives the client against a raw comm server and injects malformed/truncated responses.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/wh_client_she.c | Adds response-size gates before accessing fixed/variable-length response fields and bounds copies to received data. |
| test/wh_test_she.c | Adds a new test that validates client-side rejection of truncated/mis-sized SHE responses. |
💡 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 #457
Scan targets checked: wolfhsm-core-bugs, wolfhsm-src
No new issues found in the changed files. ✅
yosuke-wolfssl
force-pushed
the
fix/f_5466
branch
from
July 17, 2026 07:49
93c01f8 to
862ff9c
Compare
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.
Summary
The SHE client response helpers overlaid a response struct on the comm buffer and
read its fields without checking the received payload was large enough to contain
them. The comm layer validates magic, kind and sequence and bounds the payload to
the MTU, but nothing checked a payload against the size of the message being
parsed.
The comm client reuses one buffer for the outgoing request and the incoming
response, so a short reply leaves the tail holding the client's own request
bytes. A truncated Generate MAC response therefore returned success with a
MAC assembled partly from those stale bytes. Confirmed against the unfixed code:
the call returned
0with a final MAC byte of0xA5, the filler from theoutbound buffer.
The ECB and CBC helpers also validated the declared
szagainst the caller'soutput buffer rather than the data actually received, so a reply could claim more
payload than arrived. The wrappers cap this, but the response helpers are public
API, so calling one directly with a large buffer reads past the comm buffer.
Addressed by f_5466.
Changes
src/wh_client_she.creceived before copying.
dataSz;wh_Client_RecvResponseonly writes it on successand the new checks read it by value on failure paths.
test-refactor/misc/wh_test_she_client.c,test-refactor/wh_test_list.cwhTest_SheCliententry point covering client-side response sizevalidation: a fixed-size reply one byte short of its struct, each of the four
variable-length helpers at the exact bound, and a reply too short for its fixed
fields.
server, so a reply can carry the expected kind and sequence but a malformed
size. The client-server group supplies a live server, which gives no way to
inject a malformed reply.
Notes
The bound sums in a wider type instead of subtracting the fixed size from the
received size. The subtracting form is only safe given a precondition established
lines earlier and repeated four times; an edit that dropped it would wrap the
subtraction and silently make the bound a no-op. The minimum size check is kept
alongside it: it guards the
rcread, the only check that runs when the serverreports an error, while the bound guards the copy. The payload check stays after
the
rcbranch, since error replies carry only the fixed struct and checkingfirst would mask real SHE error codes.
Testing
Runs on stock POSIX hosts with the in-memory transport; no SHE hardware needed.
Both CI workflows already build
SHE=1 ASAN=1, so the new test runs there.-Werror -Wall -Wextra -std=c90; both suites pass.the checks do not reject valid traffic.
caught, as is removing a minimum size check.