Repository navigation
Conversation
…n't start a skcipher_walk that is never finished.
skcipher_walk_aead_{en,de}crypt() return with the first data segment
mapped, and these one-shot paths never call skcipher_walk_done(), so the
mapping is stranded -- consequential on 32-bit HIGHMEM kernels (a leaked
kmap_atomic() with its preempt/pagefault-disable pair through 5.15, a
leaked kmap_local slot thereafter) and under
CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP. The walk was only used to read the
IV, and with aead alignmask 0, walk.iv is req->iv itself, so read the IV
directly from the request.
…(), replace skcipher_walk_abort() with skcipher_walk_done(&walk, -ECANCELED). skcipher_walk_abort() was added in kernel 5.4 (commit 0ba3c026e685) and has only ever been that one-line expansion; skcipher_walk_done() with a negative err has performed the abort (unmap and free, no copy-back) since the walk API's debut in 4.10. The direct call builds on all walk-capable kernels and is immune to vendor backports.
…key lengths. The filter suppresses warnings for the invalid key lengths that testmgr deliberately probes, but was cloned from a single-key setkey: valid XTS key lengths are 32/48/64 (two concatenated keys), not 16/24/32.
…tion ordering around the default stdrng. Call crypto_del_default_rng() before unregistering our low level drivers: when the kernel's native DRBG is instantiated as the default stdrng it lazily instantiates atop the highest-priority HMAC-SHA-2, SHA-2, or AES driver, and crypto_put_default_rng() never frees the instance, so if that driver is ours the instance pins it. When the default stdrng instance is our own direct driver, skip the release -- its tfm context owns the default bank and must stay instantiated until wc_linuxkm_drbg_cleanup(), which uninstalls the notifiers and get_random_bytes handlers that depend on that bank. Also document why wc_linuxkm_drbg_cleanup() stays after SHA/HMAC unregistration: our stdrng must remain registered with top priority until those handlers are gone, lest the kernel instantiate an stdrng atop one of them.
…) messages. The sites print through printk in kernel builds, where a missing trailing newline runs consecutive messages together.
WC_VERBOSE_RNG now covers only the DRBG internals in wolfcrypt/src/random.c, whose messages include codes that in-tree tests deliberately provoke; WC_VERBOSE_RNG_BANK covers the rng_bank lifecycle, recovery, and entropy daemon diagnostics, which stay on by default in kernel builds. * wolfssl/wolfcrypt/settings.h: linuxkm default-on verbosity is now WC_VERBOSE_RNG_BANK (opt out with WC_NO_VERBOSE_RNG_BANK) rather than WC_VERBOSE_RNG, and WC_RNG_WANT_DEBUG_STATS no longer depends on WC_VERBOSE_RNG. * wolfcrypt/src/rng_bank.c, linuxkm/lkcapi_sha_glue.c: verbosity gates accept either macro; missing newlines added to messages on touched lines in rng_bank.c. * .wolfssl_known_macro_extras: register WC_NO_VERBOSE_RNG_BANK.
…ctual type of its argument. refcount_t exists from kernel 4.11, but crypto_alg.cra_refcnt only became refcount_t in 4.16 (commit ce8614a312ef), and vendor kernels backport unpredictably, so header-presence and version tests both misfire (e.g. 4.14, where linux/refcount.h exists but cra_refcnt is still atomic_t). Keep both accessors defined and select with __builtin_choose_expr() on __builtin_types_compatible_p(typeof(arg)).
…nd AES-XTS on kernels back to 4.4.
Pre-4.10 kernels lack the skcipher_walk interface (added by commit
b286d8b1a690), and pre-4.8 kernels additionally lack struct skcipher_alg
and crypto_register_skcipher() (commit 4e6c3df4d729).
* linuxkm/lkcapi_aes_glue.c: on pre-4.10 kernels, register cbc(aes) via
the legacy synchronous blkcipher interface (removed in kernel 5.5), to
which the crypto_skcipher consumer API (4.3+) binds transparently:
km_AesCbc{Init,SetKey,Crypt,Encrypt,Decrypt}_blk, traversing with
blkcipher_walk, with the chained IV written back to desc->info, the
wolfCrypt context allocated before the walk starts (the walk holds an
atomic mapping from blkcipher_walk_virt() to the final
blkcipher_walk_done()), and wolfCrypt failures latched and drained
rather than aborted (a negative err to blkcipher_walk_done() strands
the segment mapping and, pre-0868def3e410, miscomputes the flush page).
Register xts(aes) the same way on pre-4.11 kernels (the modern XTS glue
sets skcipher_alg.walksize, which debuted in 4.11), as a one-shot
bounce-buffer implementation: one request is one tweak unit, and
wolfCrypt's one-shot XTS handles ciphertext stealing natively; the
bounce is allocated GFP_NOIO/GFP_ATOMIC to keep reclaim out of the
encrypted device's own I/O path. Register gcm(aes) and
rfc4106(gcm(aes)) through the one-shot AesGcmCrypt_1() path, which
needs no walk; gate the streaming arm on skcipher_walk availability,
and gate the aead_alg.chunksize initializers (member added in 4.8).
Other AES modes get a #error on pre-4.10 kernels.
* linuxkm/lkcapi_glue.c: lower the LINUXKM_LKCAPI_REGISTER version floor
from 5.4 to 4.4; gate the PK glue includes on kernel >= 5.2
(crypto_register_kpp() is 4.8, and akcipher didn't have its modern
verify request layout until 5.2), with a #error roster for PK
registrations requested on older kernels; select the wc_blkcipher
class token at the CBC and XTS REGISTER_ALG()/UNREGISTER_ALG() sites
when the corresponding shim is in effect. The shim's registration
functions are real functions with a .base-bearing wrapper struct
because the REGISTER_ALG() parenthesized-callee pattern inhibits
function-like macro expansion, and carry the wc_blkcipher token so
they can't collide with the native 4.8+ skcipher symbols.
* linuxkm/linuxkm_wc_port.h: define a __has_include() fallback for
pre-5.1 gcc, and gate the crypto/internal/kpp.h (4.8) and
crypto/internal/sig.h (6.13) includes on version-or-__has_include so
vendor backports still get the headers.
…rnels back to 4.4. The SHA-1/SHA-2 glue doesn't use shash_alg.init_tfm/.exit_tfm (added in kernel 5.6), so it only needed a HASH_MAX_DESCSIZE fallback: HASH_MAX_DESCSIZE debuted in 4.20 (Kees Cook's VLA-removal series) as a plain 360 and was corrected in 5.2 to sizeof(struct shash_desc) + 360; use the 5.2 definition, which is strictly tighter than the pre-4.20 registration ceiling (PAGE_SIZE / 8 in shash_prepare_alg()). Gate the HMAC implementations, which do use .init_tfm/.exit_tfm, to >= 5.6, and document that member dependency at the existing SHA-3/HMAC #error.
|
There was a problem hiding this comment.
🟡 Changes recommended
CBC cipher-copy allocation ignores request sleep permissions, allowing non-sleepable requests to sleep and dm-crypt reclaim to recurse into the same device’s I/O; one-shot GCM and CCM cipher-copy and bounce allocations also fail to honor request flags. Separately, on pre-4.10 HIGHMEM kernels, streaming-enabled GCM now uses a one-shot fast path that can access beyond its single-page mapping for valid multi-page scatterlist entries.
2 open issues
What changed in this PR
Extends wolfSSL’s Linux kernel crypto registration support back to Linux 4.4 and updates RNG diagnostics.
Changes:
- Adds legacy AES compatibility paths and enables SHA-1/SHA-2 registration on older kernels.
- Fixes cipher-walk cleanup, RNG teardown ordering, and reference-count handling.
- Separates RNG-bank logging controls and corrects diagnostic newlines.
| File | Description |
|---|---|
| wolfssl/wolfcrypt/settings.h | Separates RNG-bank logging defaults. |
| wolfcrypt/src/rng_bank.c | Applies bank-specific logging controls and newline fixes. |
| wolfcrypt/src/random.c | Adds missing diagnostic newlines. |
| linuxkm/lkcapi_sha_glue.c | Adds legacy hash compatibility and updates RNG logging. |
| linuxkm/lkcapi_glue.c | Supports legacy registration and adjusts RNG teardown. |
| linuxkm/lkcapi_aes_glue.c | Adds legacy AES paths and fixes walk cleanup. |
| linuxkm/linuxkm_wc_port.h | Adapts kernel headers and reference-count type dispatch. |
| .wolfssl_known_macro_extras | Registers the RNG-bank logging opt-out macro. |
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12410
Scan targets checked: linuxkm-src, linuxkm-bugs, wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .wolfssl_known_macro_extras
Coverage: 7 of 7 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
…path allocations. Add wc_linuxkm_alloc_for_req(), allocating GFP_ATOMIC when the request lacks CRYPTO_TFM_REQ_MAY_SLEEP and GFP_NOIO (not GFP_KERNEL) when it has it -- under kcryptd these paths are the encrypted device's own I/O path, where GFP_KERNEL reclaim can recurse into writeback to that same device. Give km_AesGet() a req_flags parameter and route its cipher-copy allocation and all callers (skcipher and aead paths via req->base.flags, the blkcipher shim via desc->flags) through the helper, along with the one-shot AesGcmCrypt_1()/AesCcmCrypt_1() scatterlist bounce buffers and the XTS shim bounce. The helper uses kmalloc rather than kvmalloc so its results remain freeable by free() in every linuxkm allocator shape.
…quire the request span to be coverable by a single scatterwalk_map(). AesGcmCrypt_1() and AesCcmCrypt_1() gate their zero-copy fast path on scatterlist-entry lengths, but a single entry can span several physically contiguous pages while scatterwalk_map() maps only the page under the entry's offset -- an overread when that page is highmem, or under CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP. Add wc_linuxkm_sg_span_is_mappable(): the span must fit in the first page's remainder, or the span's pages must be lowmem (the mapped address is then in the linear map, contiguous across the segment) with forced single-page mappings off -- which preserves the fast path everywhere it is currently correct, ordinary 64-bit kernels included. Requests that fail the test take the existing bounce path. nth_page(), used for the page arithmetic, gets a plain-pointer-arithmetic fallback definition: it was removed in kernel 6.18, whose contiguous-memmap guarantees make that expansion correct.
The clean recipe began with the kernel-tree sub-make, so with KERNEL_ROOT unset or the sub-make failing, make aborted the recipe before any of the $(RM) lines ran. A top Makefile configured for the user library cannot recurse here at all, so stale module artifacts could survive every reset in a mixed battery. Guard the kernel sub-make on KERNEL_ROOT being set, tolerate its failure, and remove the artifacts the Kbuild recursive clean would have removed explicitly, so cleaning this directory never depends on the kernel tree being present, cooperative, or the one that built the artifacts.
…kernels, it duplicates logic in the wrapper Makefile, and on kernels <5.9, it emits harmless annoying errors of the form "rm: cannot remove '.../wolfssl/linuxkm/linuxkm': Is a directory".
There was a problem hiding this comment.
🟡 Changes recommended
When a request permits sleeping, walk-based AES callers can select GFP_NOIO after starting a skcipher walk, which may retain a kmap_atomic() mapping on older supported kernels. Without also checking wc_linuxkm_can_block(), this risks sleeping-in-atomic warnings or deadlocks. Separately, AES-XTS-only registration builds on Linux 4.4–4.10 call wc_linuxkm_alloc_for_req() while its definition is excluded by the common-functions guard, preventing that configuration from building.
2 open issues
2 resolved since last review
Review effort: Balanced
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12410
Scan targets checked: linuxkm-src, linuxkm-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .wolfssl_known_macro_extras, linuxkm/Kbuild, linuxkm/Makefile
Coverage: 1 of 1 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: Lite
|
retest this please |
…S setup to include LINUXKM_LKCAPI_REGISTER_AESXTS, and add WC_MAYBE_UNUSED where needed; in wc_linuxkm_alloc_for_req(), check wc_linuxkm_can_block().
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #12410
Scan targets checked: linuxkm-src, linuxkm-bugs
Unchanged since last review (not re-run): wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .wolfssl_known_macro_extras, linuxkm/Kbuild, linuxkm/Makefile
Coverage: 1 of 1 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: Lite
There was a problem hiding this comment.
🟡 Changes recommended
One-shot AEAD requests in NMI context should be rejected before allocation, but this path calls kmalloc() with GFP_ATOMIC, which is not NMI-safe and can deadlock on interrupted allocator state. If allocation succeeds, the existing free wrappers skip freeing in NMI context, leaking the allocation.
1 open issue
2 resolved since last review
Review effort: Balanced

Add and activate LKCAPI registration (kernel crypto replacement) support on Linux 4.4-5.5 for AES-CBC, AES-GCM, AES-GCM-RFC4106, AES-XTS, SHA-1, and SHA-2.
Also has tweaks re
WC_VERBOSE_RNGin kernel module builds, to accommodate recent changes inmasteraddingENTROPY_RT_PERMANENT_EandENTROPY_APT_PERMANENT_E(see cedb457), plus related fixes for debug message flubs (missing linefeeds).Commit summaries:
linuxkm/lkcapi_aes_glue.c: inAesGcmCrypt_1()andAesCcmCrypt_1(), don't start askcipher_walkthat is never finished.linuxkm/lkcapi_aes_glue.c: inkm_AesXtsEncrypt()andkm_AesXtsDecrypt(), replaceskcipher_walk_abort()withskcipher_walk_done(&walk, -ECANCELED).linuxkm/lkcapi_aes_glue.c: inkm_AesXtsSetKey(), fix the warn-filter key lengths.linuxkm/lkcapi_glue.c: inlinuxkm_lkcapi_unregister(), fix deinstallation ordering around the defaultstdrng.wolfcrypt/src/random.c: add missing newlines toWOLFSSL_DEBUG_PRINTF()messages.Add
WC_VERBOSE_RNG_BANK, split out fromWC_VERBOSE_RNG.linuxkm/linuxkm_wc_port.h: dispatchWC_LKM_REFCOUNT_TO_INT()on the actual type of its argument.linuxkm: support LKCAPI registration of AES-CBC, AES-GCM[-RFC4106], and AES-XTS on kernels back to 4.4.
linuxkm/lkcapi_sha_glue.c: support SHA-1 and SHA-2 registration on kernels back to 4.4.tested with