From 8a055d5aa462bf0c021da6484c56c3ed818e0582 Mon Sep 17 00:00:00 2001 From: Yosuke Shimizu Date: Fri, 6 Nov 2026 11:36:08 +0900 Subject: [PATCH 1/3] async: validate and always set the device ID in wolfAsync_DevOpenThread - 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 --- wolfcrypt/src/async.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/async.c b/wolfcrypt/src/async.c index ca02a28750f..c17db396260 100644 --- a/wolfcrypt/src/async.c +++ b/wolfcrypt/src/async.c @@ -342,6 +342,9 @@ int wolfAsync_DevOpenThread(int *pDevId, void* threadId) int ret = 0; int devId = INVALID_DEVID; + if (pDevId == NULL) + return BAD_FUNC_ARG; + #ifdef HAVE_CAVIUM ret = NitroxOpenDeviceDefault(); if (ret >= 0) @@ -363,9 +366,7 @@ int wolfAsync_DevOpenThread(int *pDevId, void* threadId) (void)threadId; - /* return devId if requested */ - if (*pDevId) - *pDevId = devId; + *pDevId = devId; return ret; } From 245c265c2d0ad9d87cab7aec1cbe3ecc4d7692b0 Mon Sep 17 00:00:00 2001 From: Yosuke Shimizu Date: Fri, 6 Nov 2026 11:37:44 +0900 Subject: [PATCH 2/3] async: reject NULL thread and function in wc_AsyncThreadCreate_ex - wc_AsyncThreadCreate_ex() returns BAD_FUNC_ARG for a NULL thread or function before initializing the pthread attributes. Issue: F-12969 --- wolfcrypt/src/async.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wolfcrypt/src/async.c b/wolfcrypt/src/async.c index c17db396260..c25e87fe83d 100644 --- a/wolfcrypt/src/async.c +++ b/wolfcrypt/src/async.c @@ -990,6 +990,9 @@ int wc_AsyncThreadCreate_ex(pthread_t *thread, pthread_attr_t attr; struct sched_param param; + if (thread == NULL || function == NULL) + return BAD_FUNC_ARG; + status = pthread_attr_init(&attr); if (status !=0) { fprintf(stderr, "pthread_attr_init error: %d\n", status); From 8a3559834257780a33c6933b422bdf10cbd87aa0 Mon Sep 17 00:00:00 2001 From: Yosuke Shimizu Date: Fri, 6 Nov 2026 11:48:45 +0900 Subject: [PATCH 3/3] wc_she: check output buffer sizes in wc_SHE_ExportKey - 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 --- doc/dox_comments/header_files-ja/wc_she.h | 2 +- doc/dox_comments/header_files/wc_she.h | 3 ++- tests/api/test_she.c | 30 +++++++++++++++++++++++ wolfcrypt/src/wc_she.c | 7 +++++- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/doc/dox_comments/header_files-ja/wc_she.h b/doc/dox_comments/header_files-ja/wc_she.h index d79a8772e67..e45030f2401 100644 --- a/doc/dox_comments/header_files-ja/wc_she.h +++ b/doc/dox_comments/header_files-ja/wc_she.h @@ -661,7 +661,7 @@ int wc_SHE_LoadKey_Verify_Label( \brief ハードウェアから鍵をSHEのロード可能な形式(M1〜M5)でエクスポートします。一部のHSMでは特定の鍵スロット(例: RAM鍵)のエクスポートが許可されており、後からSHEの鍵更新プロトコルで再ロードできます。WOLF_CRYPTO_CBが有効で、かつNO_WC_SHE_EXPORTKEYが定義されていないことが必要です。出力バッファはいずれもNULLにでき、その場合そのメッセージはスキップされます。 \return 0 成功した場合に返されます - \return BAD_FUNC_ARG sheがNULLの場合に返されます + \return BAD_FUNC_ARG sheがNULLの場合、またはNULLでない出力バッファのサイズがそのメッセージのサイズより小さい場合に返されます \return CRYPTOCB_UNAVAILABLE コールバックが登録されていない場合に返されます \param she 初期化済みのSHEコンテキスト diff --git a/doc/dox_comments/header_files/wc_she.h b/doc/dox_comments/header_files/wc_she.h index 405ae323c58..896b003d2e3 100644 --- a/doc/dox_comments/header_files/wc_she.h +++ b/doc/dox_comments/header_files/wc_she.h @@ -724,7 +724,8 @@ int wc_SHE_LoadKey_Verify_Label( output buffer may be NULL to skip that message. \return 0 on success - \return BAD_FUNC_ARG if she is NULL + \return BAD_FUNC_ARG if she is NULL, or a non-NULL output buffer is + smaller than its message size \return CRYPTOCB_UNAVAILABLE if no callback is registered \param she initialized SHE context diff --git a/tests/api/test_she.c b/tests/api/test_she.c index b20ac93b73f..39c2024adbb 100644 --- a/tests/api/test_she.c +++ b/tests/api/test_she.c @@ -628,6 +628,36 @@ int test_wc_SHE_CryptoCb(void) em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, em5, WC_SHE_M5_SZ, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ - 1, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ - 1, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ - 1, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ - 1, + em5, WC_SHE_M5_SZ, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(wc_SHE_ExportKey(&she, + em1, WC_SHE_M1_SZ, em2, WC_SHE_M2_SZ, + em3, WC_SHE_M3_SZ, em4, WC_SHE_M4_SZ, + em5, WC_SHE_M5_SZ - 1, NULL), + WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + + /* NULL buffers skip that message, so their size is not checked */ + ExpectIntEQ(wc_SHE_ExportKey(&she, + NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL), + 0); } #endif diff --git a/wolfcrypt/src/wc_she.c b/wolfcrypt/src/wc_she.c index 523e65637c8..070e822a4c7 100644 --- a/wolfcrypt/src/wc_she.c +++ b/wolfcrypt/src/wc_she.c @@ -1148,7 +1148,12 @@ int wc_SHE_ExportKey(wc_SHE* she, byte* m5, word32 m5Sz, const void* ctx) { - if (she == NULL) { + if (she == NULL || + (m1 != NULL && m1Sz < WC_SHE_M1_SZ) || + (m2 != NULL && m2Sz < WC_SHE_M2_SZ) || + (m3 != NULL && m3Sz < WC_SHE_M3_SZ) || + (m4 != NULL && m4Sz < WC_SHE_M4_SZ) || + (m5 != NULL && m5Sz < WC_SHE_M5_SZ)) { return BAD_FUNC_ARG; }