Skip to content

Harden the argument checks in three wolfCrypt APIs - #12031

Open
yosuke-wolfssl wants to merge 3 commits into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f-api-guard
Open

yosuke-wolfssl wants to merge 3 commits into
wolfSSL:masterfrom
yosuke-wolfssl:fix/f-api-guard

Conversation

@yosuke-wolfssl

Copy link
Copy Markdown
Contributor

Problem

Three public wolfCrypt APIs lack some of argument checks:

  • wolfAsync_DevOpenThread()
  • wc_AsyncThreadCreate_ex()
  • wc_SHE_ExportKey()

Fix (wolfcrypt/src/async.c, wolfcrypt/src/wc_she.c)

  • wolfAsync_DevOpenThread() returns BAD_FUNC_ARG for a NULL pDevId before opening any device, and always writes the device ID.
  • wc_AsyncThreadCreate_ex() returns BAD_FUNC_ARG for a NULL thread or function, before pthread_attr_init().
  • wc_SHE_ExportKey() returns BAD_FUNC_ARG when a non-NULL Mn buffer is smaller than WC_SHE_Mn_SZ. The EN and JA doxygen list the new case.

NULL SHE buffers are still accepted, although f-12964 recommends rejecting them. The header and doxygen document NULL as "skip that message", and both in-tree test callbacks rely on it.

Closes f-9928, f-12969 and f-12964.

Tests

test_wc_SHE_CryptoCb checks each of M1-M5 one byte short (BAD_FUNC_ARG) and an all-NULL call (succeeds). The async changes have no new tests: they only add NULL checks, and the conditional write can only be reached with Cavium/QAT hardware.

Verification

  • Builds clean with no compiler warnings under --enable-asynccrypt --enable-cryptocb --enable-debug, --enable-she=extended --enable-cryptocb --enable-debug, and with -DNO_WC_SHE_EXPORTKEY.
  • testwolfcrypt passes on the async build; SHE API group 14/14 passes.
  • Negative controls: removing the size check, comparing m2Sz against WC_SHE_M1_SZ, or dropping a mN != NULL guard each fails test_wc_SHE_CryptoCb.

- wolfAsync_DevOpenThread() returns BAD_FUNC_ARG when pDevId is NULL,
  before opening a device.
- It writes the computed device ID to *pDevId unconditionally.

Issue: F-9928
- wc_AsyncThreadCreate_ex() returns BAD_FUNC_ARG for a NULL thread or
  function before initializing the pthread attributes.

Issue: F-12969
- wc_SHE_ExportKey() returns BAD_FUNC_ARG when a non-NULL M1-M5 buffer
  is smaller than WC_SHE_M1_SZ through WC_SHE_M5_SZ.
- The EN and JA dox blocks list the new BAD_FUNC_ARG case.
- tests/api: short M1-M5 sizes are rejected; NULL buffers are
  accepted.

Issue: F-12964
@yosuke-wolfssl yosuke-wolfssl self-assigned this Nov 6, 2026
Copilot AI balanced review requested due to automatic review settings November 6, 2026 02:59

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.

🟢 Approval recommended

No active review issues remain for the argument-validation changes.

No open issues 🎉

What changed in this PR

This PR hardens argument validation in three public wolfCrypt APIs while preserving the documented behavior that NULL SHE output buffers skip their messages.

Changes:

  • Reject NULL arguments in the async device/thread APIs and always write the device ID when pDevId is valid.
  • Reject undersized non-NULL SHE export buffers, with regression tests for M1–M5 and all-NULL outputs.
  • Update English and Japanese API documentation for the new SHE error condition.
File Description
wolfcrypt/​src/​wc_she.c Validate SHE export buffer sizes.
wolfcrypt/​src/​async.c Add NULL checks and make device-ID assignment unconditional.
tests/​api/​test_she.c Test undersized buffers and accepted NULL outputs.
doc/​dox_comments/​header_files/​wc_she.h Document the buffer-size error in English.
doc/​dox_comments/​header_files-ja/​wc_she.h Document the buffer-size error in Japanese.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12031

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-bugs
Not reviewed (no scan target covers them): doc/dox_comments/header_files-ja/wc_she.h, doc/dox_comments/header_files/wc_she.h
Coverage: 3 of 3 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

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