Enforce NONMODIFIABLE and TRUSTED NVM policy on keystore key commit - #492
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Enforce NONMODIFIABLE and TRUSTED NVM policy on keystore key commit#492yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request closes a defense-in-depth gap in the server keystore “gate” by ensuring WH_KEY_COMMIT cannot overwrite existing NVM objects that are marked NONMODIFIABLE or TRUSTED. The policy enforcement is implemented centrally in the keystore policy checker (rather than in the lower-level commit function), and is validated via a new server-side test suite.
Changes:
- Add a
WH_KS_OP_COMMITpolicy branch that consults the stored NVM object’s flags and denies overwrite whenNONMODIFIABLEorTRUSTED. - Register and add a new server test (
whTest_KeystoreCommitPolicy) covering overwrite-denial, first-commit allowance, normal commit round-trip, and the “uncached commit returns NOTFOUND” guard. - Extend the server test registry to include the new test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/wh_server_keystore.c |
Enforces NONMODIFIABLE/TRUSTED overwrite denial for commit by checking stored NVM metadata when a cache slot is being committed. |
test-refactor/server/wh_test_keystore_policy.c |
Adds targeted server-side tests validating commit policy behavior and ensuring stored bytes/flags remain unchanged on denied overwrite. |
test-refactor/wh_test_list.c |
Registers the new keystore commit policy test in the server test group. |
💡 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 #492
Scan targets checked: wolfhsm-core-bugs, wolfhsm-src
No new issues found in the changed files. ✅
yosuke-wolfssl
force-pushed
the
fix/f_4225
branch
from
July 28, 2026 02:48
6041613 to
0a5c6c1
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
WH_KEY_COMMITpersisted a cached key to NVM with no NONMODIFIABLE/TRUSTEDpolicy check, addressed by f_4225. A cache slot whose id names an immutable NVM
object could be committed over it. The obvious cache route is already blocked
(
WH_KS_OP_CACHEchecks both flags), so this is a defense-in-depth hole in thecentral keystore gate, not a demonstrated bypass — see Tests.
Fix (
src/wh_server_keystore.c)Added a
WH_KS_OP_COMMITbranch to_KeystoreCheckPolicythat reads thestored object's flags (not the cache-first copy a client controls) and
returns
WH_ERROR_ACCESSwhen the target is NONMODIFIABLE or TRUSTED.reports
WH_ERROR_NOTFOUND, so there is no client-visible protocol change.flag, then commit once) is unaffected; only overwriting an existing immutable
object is refused.
wh_Server_KeystoreCommitKeykeeps its unchecked
wh_Nvm_AddObjectWithReclaim, preserving the repo'sX()/XChecked()layering.Closes f_4225.
wh_Server_KeystoreRevokeKeyshares the same cache-to-NVM writeshape and is left as a separate item.
Tests
None, deliberately. The scenario — unwrap-and-cache fills a slot, then
KeyCommitoverwrites a protected object — is not reachable from the clientAPI, so any test would only be driving a harness. The previous server-internal
test (
test-refactor/server/wh_test_keystore_policy.c, 232 lines callingwh_Server_Keystore*directly) is dropped rather than kept.Two pre-existing gates leave the key-type sets disjoint:
KeyCommit(wh_KeyId_TranslateFromClient,src/wh_keyid.c:27)CRYPTO,WRAPPED,HW— no client flag maps toSHE, andreqIdis masked to the ID fieldsrc/wh_server_keystore.c:2274)WRAPPED,SHEWRAPPED— rejected bywh_Server_KeystoreCommitKeywithWH_ERROR_ABORTED(src/wh_server_keystore.c:1227)That
WRAPPEDrejection is already asserted from the client intest-refactor/misc/wh_test_hwkeystore.c. The only client route to aCRYPTOcache slot is
WH_KS_OP_CACHE, which already refuses both flags; the remainingunchecked cache paths are the SHE handlers, whose
SHE-typed idsKeyCommitcannot address.
Verification
237bfbc: 45/26/0 default, 49/22/0DMA=1, 51/20/0SHE=1,16/55/0
NOCRYPTO=1— matches the untouched baseline for this base.-std=c90 -Werror -Wall -Wextra.test/has a pre-existingwhTest_CertClientAcertfailure on thisbase; it reproduces with the fix reverted, so it is unrelated to this PR.