Skip to content

fix: force-zero key cache on server cleanup#443

Open
MarkAtwood wants to merge 1 commit into
wolfSSL:mainfrom
MarkAtwood:fix/force-zero-server-cleanup
Open

fix: force-zero key cache on server cleanup#443
MarkAtwood wants to merge 1 commit into
wolfSSL:mainfrom
MarkAtwood:fix/force-zero-server-cleanup

Conversation

@MarkAtwood

Copy link
Copy Markdown

wh_Server_Cleanup() ends by wiping the whole server context with plain memset(server, 0, sizeof(*server)). whServerContext embeds the key cache (whKeyCacheContext localCache -> whCacheSlot/whBigCacheSlot, each holding a plaintext uint8_t buffer[] of cached key material), so this store clears sensitive key bytes. wolfHSM already uses wh_Utils_ForceZero for exactly this purpose across wh_server_she.c and wh_server_keystore.c; using plain memset here is inconsistent with that convention and is a store the compiler is permitted to reason about.

Fix: include wolfhsm/wh_utils.h and replace the memset in wh_Server_Cleanup with wh_Utils_ForceZero(server, sizeof(*server)). The matching memset in wh_Server_Init is left untouched (it zeroes an incoming, not-yet-populated context; no key material).

Verified: compiled src/wh_server.c under the POSIX test config (server enabled, crypto on) with -Werror; objdump -dr of wh_Server_Cleanup shows the call now relocates to wh_Utils_ForceZero and the memset is gone from that function.

Reported by static analysis (Fenrir finding 131).

Copilot AI review requested due to automatic review settings July 9, 2026 23:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens server cleanup by ensuring the whServerContext (which can contain plaintext cached key material) is wiped using the project’s secure zeroization helper rather than a plain memset that compilers may optimize away.

Changes:

  • Include wolfhsm/wh_utils.h in src/wh_server.c to access secure wipe utilities.
  • Replace memset(server, 0, sizeof(*server)) with wh_Utils_ForceZero(server, sizeof(*server)) in wh_Server_Cleanup().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants