Skip to content

20260720-linuxkm-CMAC-native#10980

Open
douzzer wants to merge 16 commits into
wolfSSL:masterfrom
douzzer:20260720-linuxkm-CMAC-native
Open

20260720-linuxkm-CMAC-native#10980
douzzer wants to merge 16 commits into
wolfSSL:masterfrom
douzzer:20260720-linuxkm-CMAC-native

Conversation

@douzzer

@douzzer douzzer commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Implement glue logic for Linux kernel registration of native cmac(aes) implementation, and fix gaps in several other struct shash_alg glue implementations:

linuxkm/lkcapi_aes_glue.c, linuxkm/lkcapi_glue.c, configure.ac: implement linuxkm cmac(aes) glue.

linuxkm/lkcapi_sha_glue.c: fix sha.W lifecycle management to prevent leaks:

  • separate WC_LINUXKM_SHA_IMPLEMENT() into WC_LINUXKM_SHA1_IMPLEMENT() (no fixes
    needed) and WC_LINUXKM_SHA2_IMPLEMENT() (with associated new helpers
    WC_LINUXKM_SHA2_FREE_W(), WC_LINUXKM_SHA2_DECL_W(), WC_LINUXKM_SHA2_PUSH_W(),
    and WC_LINUXKM_SHA2_POP_W(), that move .W to a stack buffer).

  • Reimplement SHA-2 one-shot digest callback to use only direct wolfCrypt calls
    rather than proxy to other callbacks.

linuxkm/linuxkm_wc_port.h, linuxkm/module_hooks.c: implement magic checks on kernel struct wolfSSL_Mutex in WOLFSSL_LINUXKM_VERBOSE_DEBUG builds.

linuxkm/lkcapi_sha_glue.c: refactor SHA-3 state around struct km_Sha3TfmCtx,
adding km_sha3_init_tfm(), km_sha3_exit_tfm(), km_sha3_alloc_tstate(), and
km_sha3_free_tstate(), implementing garbage collection of abandoned shash_desc
objects at .exit_tfm.

linuxkm/lkcapi_sha_glue.c: add struct km_sha3_export_state, and implement km_sha3_export() and per-alg _import() methods, and km_sha3_test_export_import().

linuxkm/lkcapi_sha_glue.c: fix export/import for HMAC:

  • add to struct km_sha_hmac_pstate members desc_list_lock, desc_list, export_list, and export_list_len;
  • add struct km_sha_hmac_export_state;
  • add km_hmac_alloc_tstate(), km_hmac_export(), km_hmac_import(), km_hmac_test_export_import();
  • and update km_hmac_*() and WC_LINUXKM_HMAC_IMPLEMENT() to implement.

test/:

  • fixes for NO_DH;
  • fixes in test_wc_ed448_import_public() and test_wc_Ed448DecisionCoverage() for FIPS v6;
  • fixes in tests/api/test_sha3.c for KMAC keysize in FIPS builds.

tested with

wolfssl-multi-test.sh ...
check-source-text-fips-dev
quantum-safe-wolfssl-all-crypto-only-noasm-fips-dev-linuxkm-next-clang-tidy
'.*insmod.*'
all-crypto-openssl-extra-coexist-fips-dev

@github-actions

github-actions Bot commented Jul 23, 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 #10980

Scan targets checked: linuxkm-bugs, linuxkm-src, wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 5
5 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread linuxkm/lkcapi_sha_glue.c
Comment thread linuxkm/lkcapi_sha_glue.c Outdated
Comment thread wolfcrypt/src/sha256.c
Comment thread wolfcrypt/src/sha256.c
Comment thread linuxkm/lkcapi_sha_glue.c
@philljj

philljj commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Retest this please.

FATAL: [ssh-agent] Unable to start agent
java.io.IOException: Unexpected EOF

@philljj philljj assigned douzzer and unassigned wolfSSL-Bot Jul 23, 2026
Comment thread linuxkm/lkcapi_sha_glue.c
douzzer added 16 commits July 23, 2026 19:03
…leaks:

* separate WC_LINUXKM_SHA_IMPLEMENT() into WC_LINUXKM_SHA1_IMPLEMENT() (no fixes
  needed) and WC_LINUXKM_SHA2_IMPLEMENT() (with associated new helpers
  WC_LINUXKM_SHA2_FREE_W(), WC_LINUXKM_SHA2_DECL_W(), WC_LINUXKM_SHA2_PUSH_W(),
  and WC_LINUXKM_SHA2_POP_W(), that move .W to a stack buffer).

* Reimplement SHA-2 one-shot digest callback to use only direct wolfCrypt calls
  rather than proxy to other callbacks.
…ecks on kernel struct wolfSSL_Mutex in WOLFSSL_LINUXKM_VERBOSE_DEBUG builds.
…TfmCtx,

  adding km_sha3_init_tfm(), km_sha3_exit_tfm(), km_sha3_alloc_tstate(), and
  km_sha3_free_tstate(), implementing garbage collection of abandoned shash_desc
  objects at .exit_tfm.
…ment km_sha3_export() and per-alg _import() methods, and km_sha3_test_export_import().
* add to struct km_sha_hmac_pstate members desc_list_lock, desc_list, export_list, and export_list_len;
* add struct km_sha_hmac_export_state;
* add km_hmac_alloc_tstate(), km_hmac_export(), km_hmac_import(), km_hmac_test_export_import();
* and update km_hmac_*() and WC_LINUXKM_HMAC_IMPLEMENT(() to implement.
* fixes for NO_DH;
* fixes in test_wc_ed448_import_public() and test_wc_Ed448DecisionCoverage() for FIPS v6;
* fixes in tests/api/test_sha3.c for KMAC keysize in FIPS builds.
… conjunctions to fix constant-folding-provoked compiler warnings around fips_enabled;

for clarity, rename internal macros WC_LINUXKM_HAVE_SELFTEST and WC_LINUXKM_HAVE_SELFTEST_FULL to WC_LINUX_CONFIG_SELFTESTS and WC_LINUX_CONFIG_SELFTESTS_FULL respectively.
…hten up SHA-3 allocations, avoiding frivolous struct km_sha_state (with inline wc_Sha512) for SHA-3.
* Eliminate pointer from export blob, replacing it with a TFM-specific random cookie and per-desc serial ID.
* Fixes kernel address disclosure risk, handle forgery risk, cross-TFM confusion risk, and heap pointer reuse risk.
…sl/wolfcrypt/settings.h:

* Revert earlier changes adding WC_SHA256_W_SIZE and WC_SHA512_W_SIZE.

* Add WC_SHA2_NO_SMALL_STACK to allow the W work buffer to move back onto the
  stack.

* In wolfssl/wolfcrypt/settings.h, define WC_SHA2_NO_SMALL_STACK by default when
  WOLFSSL_KERNEL_MODE, and add a clause to #undef WOLFSSL_SMALL_STACK when
  building the SHA-2 implementations.

linuxkm/lkcapi_sha_glue.c:

* Refactor out superfluous struct km_sha_state.

* Clean up some macro dynamics.

* Add static asserts on HASH_MAX_STATESIZE to WC_LINUXKM_SHA1_IMPLEMENT() and
  WC_LINUXKM_SHA2_IMPLEMENT().
@douzzer
douzzer force-pushed the 20260720-linuxkm-CMAC-native branch from 3e6a2f1 to d4c3410 Compare July 24, 2026 00:13
Comment thread wolfcrypt/src/sha256.c
Comment thread wolfcrypt/src/sha256.c
Comment thread linuxkm/lkcapi_sha_glue.c Outdated
@douzzer douzzer assigned wolfSSL-Bot and unassigned douzzer Jul 24, 2026
Comment thread linuxkm/lkcapi_sha_glue.c

@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 #10980

Scan targets checked: linuxkm-bugs, linuxkm-src, wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread linuxkm/lkcapi_sha_glue.c

@Frauschi Frauschi 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.

🐺 Skoll Code Review

Overall recommendation: REQUEST_CHANGES
Findings: 4 total — 2 posted, 2 skipped

Posted findings

  • [Medium] enabled_fips declaration/use guard mismatch can break -Werror kernel buildslinuxkm/lkcapi_glue.c:227
  • [Medium] configure.ac lean-aesgcm-dev SHA512 logic inverted from disable to force-enableconfigure.ac:7377-7379
Skipped findings
  • [Medium] km_hmac_import() calls allocating wc_HmacCopy() while holding spinlock (sleep-in-atomic)
  • [Low] cpuid_flag: reg[num] = 0 is dead code (overwritten by cpuid())

Review generated by Skoll via Claude/Codex

Comment thread linuxkm/lkcapi_glue.c
static int linuxkm_lkcapi_unregister(void);

#if defined(HAVE_FIPS) && defined(WC_LINUXKM_HAVE_SELFTEST)
#if defined(HAVE_FIPS) && defined(WC_LINUX_CONFIG_SELFTESTS)

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.

🟡 [Medium] enabled_fips declaration/use guard mismatch can break -Werror kernel builds
🚫 BLOCK bug

This PR renamed WC_LINUXKM_HAVE_SELFTEST to WC_LINUX_CONFIG_SELFTESTS and, at the two use sites of enabled_fips (lines 270 and 348/357), additionally added defined(CONFIG_CRYPTO_FIPS) to the preprocessor guard. However, the declaration of enabled_fips at line 227 was only renamed and did NOT get the CONFIG_CRYPTO_FIPS guard. As a result, when a target is built with HAVE_FIPS && WC_LINUX_CONFIG_SELFTESTS but WITHOUT CONFIG_CRYPTO_FIPS (a valid combination: wolfCrypt FIPS build on a kernel that has CONFIG_CRYPTO_MANAGER selftests but not CONFIG_CRYPTO_FIPS), static int enabled_fips is declared but never referenced. That yields a -Wunused-variable warning, which is fatal in the typical -Werror linuxkm build. Before this PR the declaration and use guards matched exactly, so this is a regression introduced by the diff.

Suggestion:

Suggested change
#if defined(HAVE_FIPS) && defined(WC_LINUX_CONFIG_SELFTESTS)
#if defined(HAVE_FIPS) && defined(CONFIG_CRYPTO_FIPS) && \
defined(WC_LINUX_CONFIG_SELFTESTS)
static int enabled_fips = 0;
#endif

Comment thread configure.ac
AS_IF([test "$ENABLED_SHA512" != "no" &&
(test "$FIPS_VERSION" != "lean-aesgcm-dev" || test "$enable_sha512" != "yes")],
[enable_sha512="no"; ENABLED_SHA512="no"; ENABLED_SHA512_DRBG="no"; AM_CFLAGS="$AM_CFLAGS -UWOLFSSL_SHA512 -UWOLFSSL_SHA384"])
AS_IF([test "$ENABLED_SHA512" = "no" &&

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.

🟡 [Medium] configure.ac lean-aesgcm-dev SHA512 logic inverted from disable to force-enable
💡 SUGGEST question

The SHA512 block was inverted: the condition changed from test "$ENABLED_SHA512" != "no" (with the action DISABLING SHA512: -UWOLFSSL_SHA512) to test "$ENABLED_SHA512" = "no" (with the action force-ENABLING it: enable_sha512="yes"; ... -DWOLFSSL_SHA512 -DWOLFSSL_SHA384). This now mirrors the SHA256 block just above (line 7353), so SHA512 becomes mandatory in the lean-aesgcm-dev FIPS variant (presumably required by the SHA512-based DRBG). The surrounding SHA3/SHAKE/SHA224/SHA384 blocks still use the old disable pattern, so SHA512 is now the odd one out. The PR description does not mention this configure change. It looks intentional and consistent with SHA256, but it is a meaningful behavior flip in FIPS config selection worth an explicit confirmation.

Recommendation: Confirm SHA512 is meant to be force-enabled (not disabled) in the lean-aesgcm-dev FIPS variant, and consider noting it in the PR description since it is not part of the stated linuxkm CMAC scope.

@Frauschi Frauschi assigned douzzer and unassigned wolfSSL-Bot Jul 24, 2026
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.

5 participants