Bound SHE LoadKey auth key read to WH_SHE_KEY_SZ - #495
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 server-side SHE LOAD_KEY handler against oversized/undersized auth-key objects by bounding keystore reads to WH_SHE_KEY_SZ, ensuring consistent error mapping, and adding targeted regression tests in the refactored test suite.
Changes:
- Fix
_LoadKeyto read the auth key with capacityWH_SHE_KEY_SZand reject short reads /WH_ERROR_NOSPACEasWH_SHE_ERC_KEY_INVALID. - Pin the target-slot keystore read size to
WH_SHE_KEY_SZ(instead of inheritingkeySzfrom the auth-key read). - Add a new refactored server test that plants 32/8/16-byte auth-key objects and validates the handler’s return codes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/wh_server_she.c |
Bounds auth-key read size, normalizes error returns for invalid auth-key storage sizes, and pins the subsequent target-slot read size. |
test-refactor/server/wh_test_she_loadkey.c |
Adds a regression test for LOAD_KEY auth-key length handling (oversized/undersized/valid). |
test-refactor/wh_test_list.c |
Registers the new server test in the refactored test suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yosuke-wolfssl
force-pushed
the
fix/f_7155
branch
from
July 27, 2026 05:12
56a9e2b to
9a09486
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #495
Scan targets checked: wolfhsm-core-bugs, wolfhsm-src
No new issues found in the changed files. ✅
yosuke-wolfssl
force-pushed
the
fix/f_7155
branch
from
July 28, 2026 01:52
9a09486 to
6c75ef6
Compare
yosuke-wolfssl
force-pushed
the
fix/f_7155
branch
from
July 29, 2026 22:52
6c75ef6 to
8b61798
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.
Problem
_LoadKeyread the SHE authentication key with the read capacity set to the whole KDF input buffer (keySz = sizeof(kdfInput), 32 bytes) instead of the size of a SHE key.wh_Server_KeystoreReadKeyreturns the actual stored object length in*outSz, sokeySzcould come back as anything up to 32. The handler then appends the 16-byte key-update constant atkdfInput + keySzand runs the Miyaguchi-Preneel KDF overkeySz + 16bytes, writing and reading up to 16 bytes past the end of a 32-byte stack buffer.SHE keys and NVM objects share the 16-bit id space, and
wh_Nvm_CheckPolicygrants by default on an unused id, so an authenticated client can plant an oversized object atWH_MAKE_KEYID(WH_KEYTYPE_SHE, client_id, authId)and reach it viaWH_SHE_LOAD_KEY. The overflowing bytes are a fixed constant, but the overflow length is attacker-selected._LoadKeywas the only SHE handler not pinning the capacity; the other eleven sites already usedWH_SHE_KEY_SZ. RequiresWOLFHSM_CFG_SHE_EXTENSION(non-default).Addressed by f_7155.
Fix (
src/wh_server_she.c)keySz = WH_SHE_KEY_SZbefore the auth-key read, matching every other SHE handler.WH_SHE_ERC_KEY_INVALIDfor both rejection paths —WH_ERROR_NOSPACEfrom the keystore, and a short read._TranslateSheReturnCodehas no case forNOSPACE, so it would otherwise degrade toGENERAL_ERROR;_SecureBootInitalready returnsKEY_INVALIDfor the identical condition.keySzfrom the first.WH_SHE_ERC_KEY_INVALIDWH_SHE_ERC_KEY_INVALIDGENERAL_ERRORTest harness
New
test-refactor/server/wh_test_she_loadkey.c: one registered parent, threestaticsub-tests planting 32/8/16-byte objects at a SHE AuthID slot viawh_Server_KeystoreCacheKey(cache-only, no NVM artifact) and driving the handler directly. Registered inwh_test_list.c.Verification
SHE=1) passes, exit 0.stack-buffer-overflow, WRITE of size 16 at offset 96 ofkdfInput [64, 96)in_LoadKey. Post-fix ASan is clean.-std=c90 -Werror -Wall -Wextra.Not in this PR
The NVM message API is the only client-facing path accepting a raw keyId, and its policy layer is per-object flags rather than a namespace boundary. Restricting it is a design change —
test-refactor/client-server/wh_test_keywrap.casserts flag-stripping is the intended defense — so it is written up separately.