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. ✅
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,
overwriting a key the policy layer declares unmodifiable. The obvious cache
route is already blocked (
WH_KS_OP_CACHEchecks NONMODIFIABLE), so this is adefense-in-depth hole in the central keystore gate, not a demonstrated bypass.
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; the client path reaches the gate throughwh_Server_KeystoreCommitKeyChecked.Closes f_4225.
wh_Server_KeystoreRevokeKeyshares the same cache-to-NVM writeshape and is left as a separate item (see below).
Tests
New
whTest_KeystoreCommitPolicy(test-refactor, server group), 4 sub-tests:overwrite of a NONMODIFIABLE object, of a TRUSTED object, first-commit of an
immutable key succeeds, normal commit round-trips through NVM. Includes the
uncached-commit
NOTFOUNDguard.Verification
SHE=1, 48/22/0DMA=1, 16/54/0NOCRYPTO=1(skips cleanly); legacytest/exit 0.-std=c90 -Werror -Wall -Wextra.