Skip to content

[Renesas RA6M4] Fix Renesas RA6M4 SCE session-key generation issues#10903

Merged
JacobBarthelmeh merged 3 commits into
wolfSSL:masterfrom
miyazakh:f_issues_SCE
Jul 16, 2026
Merged

[Renesas RA6M4] Fix Renesas RA6M4 SCE session-key generation issues#10903
JacobBarthelmeh merged 3 commits into
wolfSSL:masterfrom
miyazakh:f_issues_SCE

Conversation

@miyazakh

Copy link
Copy Markdown
Contributor

Summary

Three fixes to the Renesas FSPSM (RA6M4 Secure Cryptography Engine) port, driven by cases
found in wolfSSL's internal issue tracker:

  • renesas_fspsm_util.cwc_fspsm_generateSessionKey():
    • Fix a NULL-pointer dereference when the AES-GCM deferred-key-generation path leaves the
      session key buffers NULL.
    • Fix a hardware mutex leak on out-of-memory during session-key setup.
  • renesas_fspsm_aes.cwc_fspsm_AesGcmDecrypt():
    • Fix a copy-paste error in an error message.

Details

NULL-pointer dereference in wc_fspsm_generateSessionKey (issue f5408)

When AES-GCM session-key generation takes the deferred path, key_client_aes and
key_server_aes are left NULL (the real per-record key is generated later, inside
wc_fspsm_AesGcmEncrypt/Decrypt). The subsequent XMEMCPY into
enc/dec->aes->ctx.wrapped_key did not check for this and copied from the NULL pointers
unconditionally, crashing — remotely triggerable via cipher suite choice.

Fix: guard the copy with if (key_client_aes != NULL && key_server_aes != NULL).

Hardware mutex leak on allocation failure (issues f5417, f5409 — duplicate)

Five return MEMORY_E; exit paths inside the wc_fspsm_hw_lock()'d block of
wc_fspsm_generateSessionKey (client/server AES key alloc, encrypt-side Aes/wrapped-key
alloc, decrypt-side Aes/wrapped-key alloc) returned without calling
wc_fspsm_hw_unlock(), leaving the hardware mutex permanently locked after an allocation
failure.

Fix: add wc_fspsm_hw_unlock(); before each of the 5 early returns.

(f5409 reported the same root cause under a different description; no additional change was
needed beyond the f5417 fix.)

Copy-paste error in wc_fspsm_AesGcmDecrypt error message (issue 1537)

The authTagSz-too-small error message read "GcmEncrypt authTagSz too small error" inside
the decrypt function — copy-pasted from the encrypt path. Message-only fix, no functional
impact: now reads "GcmDecrypt authTagSz too small error".

Testing

Run crypt and benchmark test on the board

Checklist

  • [n/a] added tests
  • [n/a] updated/added doxygen
  • [n/a] updated appropriate READMEs
  • [n/a] Updated manual and documentation

Copilot AI review requested due to automatic review settings July 14, 2026 21:05
@miyazakh miyazakh self-assigned this Jul 14, 2026

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 fixes correctness issues in the Renesas RA6M4 FSPSM (SCE) TLS port related to session-key generation, specifically addressing a NULL-dereference in the AES-GCM deferred-key path, ensuring the hardware mutex is always released on allocation failures, and correcting a misleading decrypt-side log message.

Changes:

  • Prevent NULL-pointer dereference by skipping session-key buffer copies when AES-GCM session-key generation is deferred.
  • Fix multiple early-return out-of-memory paths to free partial allocations and always release the FSPSM hardware mutex.
  • Correct a copy-paste error in the AES-GCM decrypt error message.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
wolfcrypt/src/port/Renesas/renesas_fspsm_util.c Adds NULL-guarded key copy and ensures cleanup + hw unlock on allocation failures during session-key setup.
wolfcrypt/src/port/Renesas/renesas_fspsm_aes.c Fixes an incorrect decrypt-side log message string.

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

@miyazakh

Copy link
Copy Markdown
Contributor Author

retest this please

@miyazakh miyazakh assigned wolfSSL-Bot and unassigned miyazakh Jul 15, 2026
@JacobBarthelmeh
JacobBarthelmeh merged commit 08539e4 into wolfSSL:master Jul 16, 2026
339 checks passed
@miyazakh
miyazakh deleted the f_issues_SCE branch July 17, 2026 06:19
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.

4 participants