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
2 times, most recently
from
July 29, 2026 22:52
6c75ef6 to
8b61798
Compare
Contributor
|
@yosuke-wolfssl merge conflicts |
yosuke-wolfssl
force-pushed
the
fix/f_7155
branch
from
August 4, 2026 01:20
8b61798 to
1276a04
Compare
Contributor
Author
|
Hi @bigbrett , |
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
_LoadKeyin the SHE extension read the key-update authorization key with the capacity set to the whole kdf input buffer (keySz = sizeof(kdfInput), 32) rather than the SHE key size (16).wh_Server_KeystoreReadKeyreports the stored object's actual length, and the kdf then appends a 16-byte constant at that offset, so a slot holding more thanWH_SHE_KEY_SZbytes overruns the 32-byte stack buffer by up to 16 bytes on twomemcpycalls and the subsequent_AesMp16read.The SHE and NVM id spaces overlap, so an authenticated client can plant an oversized object directly in a SHE slot with
WH_MESSAGE_NVM_ACTION_ADDOBJECTand then reach the overflow through a normalCMD_LOAD_KEY. RequiresWOLFHSM_CFG_SHE_EXTENSION.The target-key read had a second, independent flaw:
wh_Server_KeystoreReadKeyreturnsWH_ERROR_NOSPACEbefore populating the caller's metadata, so an oversized target slot leftmetazeroed.wh_She_Label2Metathen read all-zero flags, theWH_SHE_FLAG_WRITE_PROTECTbit appeared clear, and a write-protected slot was silently overwritten.Fix (
src/wh_server_she.c)Both reads are pinned to
WH_SHE_KEY_SZand a slot of any other length is rejected, matching every other SHE handler.WH_SHE_KEY_SZ;WH_ERROR_NOSPACEor size mismatch →WH_SHE_ERC_KEY_INVALIDmetaunset onNOSPACEWH_SHE_KEY_SZ; rejected before the label is consulted, closing the write-protect bypasswh_Client_ShePreProgramKeyalso rejects akeySzother thanWH_SHE_KEY_SZwithWH_ERROR_BADARGS, so an ordinary client cannot create such a slot in the first place; the header documents the new precondition.Closes 7155.
Tests (
test-refactor/client-server/wh_test_she.c)Three cases appended to
whTest_She, driven only throughwh_Client_*:WH_ERROR_BADARGS, leaving no NVM object behindwh_Client_NvmAddObject, used as the LoadKey AUTH id →WH_SHE_ERC_KEY_INVALIDWH_SHE_ERC_KEY_INVALIDVerification
-Werror -Wall -Wextra, C90.make SHE=1). ASan clean.stack-buffer-overflowpastkdfInputin_LoadKey; without the target-key bound,wh_Client_SheLoadKeyreturns success against a write-protected slot.