From: sashiko-bot@kernel.org
To: "Alex Ousherovitch" <aousherovitch@rambus.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v5 05/19] crypto: cmh - add HMAC ahash
Date: Thu, 17 Sep 2026 23:14:35 +0000 [thread overview]
Message-ID: <20260917231436.1F3061F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917225929.2494111-6-aousherovitch@rambus.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] crypto: cmh: missing bounds check in cmh_hmac_import allows unbounded memory allocation
- [High] crypto: cmh: under-accounting of chunk struct overhead allows extreme memory exhaustion
- [Medium] crypto: cmh: freeing millions of chunks under spin_lock_bh can trigger a softlockup
- [Medium] crypto: cmh: DMA buffer shares a cache line with CPU-modified variables
--
commit e7307bc7cf1e65f0adb503e546d45a39b86900bd
Author: Alex Ousherovitch <aousherovitch@rambus.com>
crypto: cmh - add HMAC ahash
This commit registers HMAC ahash algorithms (HMAC-SHA-2 and HMAC-SHA-3) using
the CMH hash core. It implements a self-contained transaction model using
accumulated inputs, with a generic software fallback for payloads above 64KB.
> diff --git a/drivers/crypto/cmh/cmh_hmac.c b/drivers/crypto/cmh/cmh_hmac.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_hmac.c
[ ... ]
> @@ -136,7 +136,7 @@
> +/* Per-Request State */
> +
> +struct cmh_hmac_chunk {
> + struct list_head list;
> + struct list_head tfm_node; /* per-tfm orphan tracking */
> + u32 len;
> + u8 data[];
> +};
[Severity: Medium]
Does this structure layout place the data buffer on the same cache line as
the list heads?
Since the data buffer is mapped for DMA, could concurrent list
modifications in cmh_hmac_update() dirty the cache line while a transfer
is in progress, potentially violating mapping rules on non-coherent
architectures?
[ ... ]
> +static int cmh_hmac_update(struct ahash_request *req)
> +{
[ ... ]
> + chunk = kmalloc(sizeof(*chunk) + req->nbytes,
> + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
> + GFP_KERNEL : GFP_ATOMIC);
> + if (!chunk) {
> + rctx->error = -ENOMEM;
> + goto err_free_chunks;
> + }
> +
> + chunk->len = req->nbytes;
[ ... ]
> + spin_lock_bh(&tctx->chunk_lock);
> + if (tctx->tfm_buffered + chunk->len > CMH_HMAC_TFM_MAX_BUFFERED) {
> + spin_unlock_bh(&tctx->chunk_lock);
> + kfree_sensitive(chunk);
> + rctx->error = -ENOMEM;
> + goto err_free_chunks;
> + }
> + list_add_tail(&chunk->list, &rctx->chunks);
> + list_add_tail(&chunk->tfm_node, &tctx->all_chunks);
> + tctx->tfm_buffered += chunk->len;
> + spin_unlock_bh(&tctx->chunk_lock);
[Severity: High]
Are we only accounting for the payload length here, instead of the full
size of the allocated struct?
Since the chunk header is 36 bytes (often rounded up to 64 bytes by the
slab allocator), could repeated 1-byte updates allow pinning roughly 1GB
of kernel memory per transform socket without exceeding the 16MB budget?
[ ... ]
> +static int cmh_hmac_import(struct ahash_request *req, const void *in)
> +{
[ ... ]
> + if (state->total_len) {
> + chunk = kmalloc(sizeof(*chunk) + state->total_len,
> + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
> + GFP_KERNEL : GFP_ATOMIC);
> + if (!chunk)
> + return -ENOMEM;
> + chunk->len = state->total_len;
> + memcpy(chunk->data, state->data, state->total_len);
> + spin_lock_bh(&tctx->chunk_lock);
> + list_add_tail(&chunk->list, &rctx->chunks);
> + list_add_tail(&chunk->tfm_node, &tctx->all_chunks);
> + tctx->tfm_buffered += chunk->len;
> + spin_unlock_bh(&tctx->chunk_lock);
[Severity: High]
Should we verify if the budget is exceeded before appending the imported
chunk and adding to tctx->tfm_buffered?
Without a check against CMH_HMAC_TFM_MAX_BUFFERED, could an unprivileged
user repeatedly call accept() on a socket to clone its state and cause
unbounded kernel memory allocation?
[ ... ]
> +static void cmh_hmac_cra_exit(struct crypto_tfm *tfm)
> +{
> + struct cmh_hmac_tfm_ctx *tctx = crypto_tfm_ctx(tfm);
> + struct cmh_hmac_chunk *chunk, *tmp;
> +
> + /* Free any orphaned chunks (e.g. testmgr export/reimport poison) */
> + spin_lock_bh(&tctx->chunk_lock);
> + list_for_each_entry_safe(chunk, tmp, &tctx->all_chunks, tfm_node) {
> + list_del(&chunk->tfm_node);
> + tctx->tfm_buffered -= chunk->len;
> + kfree_sensitive(chunk);
> + }
> + spin_unlock_bh(&tctx->chunk_lock);
[Severity: Medium]
Is it safe to free potentially large numbers of chunks while holding the
spinlock with softirqs disabled?
If the 16MB budget contains millions of small chunks (due to the accounting
size issue mentioned earlier), could this loop take significant CPU time
and risk triggering a soft or hard lockup panic?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917225929.2494111-1-aousherovitch@rambus.com?part=5
next prev parent reply other threads:[~2026-09-17 23:14 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 22:59 [PATCH v5 00/19] crypto: cmh - add Rambus CryptoManager Hub driver Alex Ousherovitch
2026-09-17 22:59 ` [PATCH v5 01/19] dt-bindings: crypto: add Rambus CryptoManager Hub Alex Ousherovitch
2026-09-17 23:08 ` sashiko-bot
2026-09-28 18:18 ` Rob Herring
2026-10-03 0:01 ` Ousherovitch, Alex
2026-09-17 22:59 ` [PATCH v5 02/19] crypto: cmh - add core platform driver Alex Ousherovitch
2026-09-17 23:17 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 03/19] crypto: cmh - add key provisioning and management Alex Ousherovitch
2026-09-17 23:15 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 04/19] crypto: cmh - add SHA-2/SHA-3/SHAKE ahash Alex Ousherovitch
2026-09-17 23:11 ` sashiko-bot
2026-09-23 5:47 ` Herbert Xu
2026-09-23 20:50 ` Ousherovitch, Alex
2026-09-28 5:17 ` Herbert Xu
2026-10-05 17:04 ` Ousherovitch, Alex
2026-10-05 22:31 ` Ousherovitch, Alex
2026-10-08 8:20 ` Herbert Xu
2026-10-08 18:19 ` Ousherovitch, Alex
2026-09-17 22:59 ` [PATCH v5 05/19] crypto: cmh - add HMAC ahash Alex Ousherovitch
2026-09-17 23:14 ` sashiko-bot [this message]
2026-09-17 22:59 ` [PATCH v5 06/19] crypto: cmh - add CSHAKE/KMAC ahash Alex Ousherovitch
2026-09-17 23:16 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 07/19] crypto: cmh - add SM3 ahash Alex Ousherovitch
2026-09-17 23:12 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 08/19] crypto: cmh - add AES skcipher/aead/cmac Alex Ousherovitch
2026-09-17 23:11 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 09/19] crypto: cmh - add SM4 skcipher/aead/cmac/xcbc Alex Ousherovitch
2026-09-17 23:10 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 10/19] crypto: cmh - add ChaCha20-Poly1305 Alex Ousherovitch
2026-09-17 23:11 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 11/19] crypto: cmh - add DRBG hwrng Alex Ousherovitch
2026-09-17 23:14 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 12/19] crypto: cmh - add RSA akcipher Alex Ousherovitch
2026-09-17 23:10 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 13/19] crypto: cmh - add ECDSA/SM2 sig Alex Ousherovitch
2026-09-17 22:59 ` [PATCH v5 14/19] crypto: cmh - add ECDH/X25519 kpp Alex Ousherovitch
2026-09-17 22:59 ` [PATCH v5 15/19] crypto: cmh - add ML-KEM/ML-DSA (QSE) Alex Ousherovitch
2026-09-17 22:59 ` [PATCH v5 16/19] crypto: cmh - add SLH-DSA/LMS/XMSS (HCQ) Alex Ousherovitch
2026-09-17 22:59 ` [PATCH v5 17/19] Documentation: ioctl: add CMH ioctl documentation and register 'J' Alex Ousherovitch
2026-09-17 23:17 ` sashiko-bot
2026-09-17 22:59 ` [PATCH v5 18/19] selftests: crypto: cmh - add kselftest for management ioctl Alex Ousherovitch
2026-09-17 22:59 ` [PATCH v5 19/19] MAINTAINERS: add Rambus CryptoManager Hub (CMH) Alex Ousherovitch
2026-09-23 5:48 ` [PATCH v5 00/19] crypto: cmh - add Rambus CryptoManager Hub driver Herbert Xu
2026-09-23 17:42 ` Ousherovitch, Alex
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260917231436.1F3061F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aousherovitch@rambus.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox