From: sashiko-bot@kernel.org
To: "Saravanakrishnan Krishnamoorthy" <skrishnamoorthy@rambus.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 06/19] crypto: cmh - add CSHAKE/KMAC ahash
Date: Thu, 06 Aug 2026 20:10:37 +0000 [thread overview]
Message-ID: <20260806201037.CD0181F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806195519.2703224-7-skrishnamoorthy@rambus.com>
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [Critical] Unbounded memory allocation in `cmh_cshake_update` allows trivial kernel memory exhaustion (OOM).
- [High] Accumulated dynamically allocated chunks leak when ahash requests are re-initialized, imported, or abandoned.
- [High] `cmh_cshake_export` sleeps in atomic context by using `GFP_KERNEL` and performing a synchronous hardware submission.
- [High] Direct DMA mapping of a stack-allocated request context variable.
- [High] Lack of synchronization in `setkey` allows concurrent hardware access to freed key memory via DMA.
- [High] Integer overflow vulnerability during chunk allocation leads to heap buffer overflow.
- [Medium] Unaligned structure members are directly mapped for DMA, breaking cacheline coherency.
--
--- Patch [6]: [PATCH v3 06/19] crypto: cmh - add CSHAKE/KMAC ahash ---
commit 6138eb846ff49a783a8916ba0affae21d8744139
Author: Alex Ousherovitch <aousherovitch@rambus.com>
crypto: cmh - add CSHAKE/KMAC ahash
This commit registers ahash algorithms for cSHAKE128, cSHAKE256, KMAC128,
and KMAC256 using the CMH hash core. It adds support for incremental
updates and export/import for cSHAKE, and imposes a 64KB data cap for
KMAC.
> diff --git a/drivers/crypto/cmh/cmh_cshake.c b/drivers/crypto/cmh/cmh_cshake.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_cshake.c
> @@ -0,0 +1,814 @@
[ ... ]
> +struct cmh_cshake_chunk {
> + struct list_head list;
> + struct list_head tfm_node; /* per-tfm orphan tracking */
> + u32 len;
> + u8 data[];
> +};
[Severity: Medium]
Will this structure layout cause data corruption on cache-incoherent
architectures? The data array follows list pointers and a u32 length field,
placing it at an unaligned offset. When this flexible array member is
directly mapped for DMA, it violates the requirement that dynamically mapped
buffers must be aligned to ARCH_DMA_MINALIGN to prevent cacheline sharing.
[ ... ]
> +static int cmh_cshake_setkey(struct crypto_ahash *tfm, const u8 *key,
> + unsigned int keylen)
> +{
[ ... ]
> + /* Free previous N and S */
> + kfree(tctx->func_name);
> + kfree(tctx->custom);
[Severity: High]
Could this lockless memory free race with an ongoing final() operation?
If user space calls setsockopt() to set a new key concurrently with
socket I/O, the active custom string's memory might be unmapped and freed
while the hardware is actively accessing it via DMA, leading to a
use-after-free and potential memory corruption.
[ ... ]
> +static int cmh_cshake_init(struct ahash_request *req)
> +{
> + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> + struct cmh_cshake_reqctx *rctx = ahash_request_ctx(req);
> +
> + rctx->info = cmh_cshake_get_info(tfm);
> + rctx->error = 0;
> + INIT_LIST_HEAD(&rctx->chunks);
> + rctx->num_chunks = 0;
[Severity: High]
Does this cause a memory leak when a request is re-initialized or abandoned?
If a caller issues crypto_ahash_init() on an existing request that already
accumulated data chunks, the chunk list is reset via INIT_LIST_HEAD()
without freeing the existing chunks. The chunks remain indefinitely tracked
in the transform context list, which could allow unbounded memory growth
over the lifetime of a long-lived transform.
[ ... ]
> +static int cmh_cshake_update(struct ahash_request *req)
> +{
[ ... ]
> + if (!req->nbytes)
> + return 0;
> +
> + chunk = kmalloc(sizeof(*chunk) + req->nbytes,
> + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
> + GFP_KERNEL : GFP_ATOMIC);
[Severity: Critical]
Can the arithmetic operation here wrap around on 32-bit platforms?
Since req->nbytes is an unsigned int controlled by the caller, providing
an extremely large value could overflow the addition, allocating a tiny
buffer. The subsequent data copy would then overwrite kernel heap memory.
[Severity: Critical]
Does this allow an unprivileged attacker to exhaust kernel memory?
Unlike the KMAC implementation which enforces a 64KB maximum limit, the
cSHAKE implementation unconditionally buffers all incoming data chunks
without any bounds check on the total length or number of chunks.
[ ... ]
> +static int cmh_cshake_final(struct ahash_request *req)
> +{
[ ... ]
> + /* Map checkpoint buffer if present (CMH eSW reads it) */
> + if (rctx->has_checkpoint) {
> + ckpt_dma = cmh_dma_map_single(rctx->checkpoint,
> + HC_CONTEXT_SIZE, DMA_TO_DEVICE);
[Severity: High]
Is it safe to map this request context variable directly for DMA?
The driver maps rctx->checkpoint via cmh_dma_map_single(), but the ahash
request context is frequently placed on the kernel stack by callers.
DMA mapping stack memory causes cacheline sharing corruption on non-coherent
architectures and immediately panics if DMA API debugging is enabled.
[ ... ]
> +static int cmh_cshake_export(struct ahash_request *req, void *out)
> +{
[ ... ]
> + if (rctx->num_chunks > 0) {
> + sgm = cmh_cshake_build_sg(rctx, GFP_KERNEL);
> + if (!sgm)
> + return -ENOMEM;
> + }
> +
> + save_buf = kzalloc(HC_CONTEXT_SIZE, GFP_KERNEL);
> + if (!save_buf) {
[ ... ]
> + ret = cmh_vcq_pack_and_submit(cmds, idx, rctx->packed, CMH_CSHAKE_MAX_PACKED,
> + d.mbx_idx);
[Severity: High]
Will this sequence sleep in atomic context?
The crypto_ahash_export() API must be non-blocking because it is called
from atomic contexts like IPsec softirq. Allocating memory with GFP_KERNEL
and performing a synchronous, blocking hardware submission will trigger a
bug or deadlock when called from these contexts.
[ ... ]
> +static int cmh_cshake_import(struct ahash_request *req, const void *in)
> +{
[ ... ]
> + rctx->error = 0;
> + INIT_LIST_HEAD(&rctx->chunks);
> + rctx->num_chunks = 0;
[Severity: High]
Does this cause a memory leak when a request is imported?
Similar to cmh_cshake_init(), this resets the chunk list without freeing
the previously accumulated chunks.
> diff --git a/drivers/crypto/cmh/cmh_kmac.c b/drivers/crypto/cmh/cmh_kmac.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_kmac.c
> @@ -0,0 +1,630 @@
[ ... ]
> +struct cmh_kmac_chunk {
> + struct list_head list;
> + struct list_head tfm_node; /* per-tfm orphan tracking */
> + u32 len;
> + u8 data[];
> +};
[Severity: Medium]
Will this structure layout cause data corruption on cache-incoherent
architectures? Similar to the cSHAKE implementation, placing the flexible
array member at an unaligned offset and mapping it directly for DMA breaks
cacheline coherency.
[ ... ]
> +static int cmh_kmac_setkey(struct crypto_ahash *tfm, const u8 *key,
> + unsigned int keylen)
> +{
[ ... ]
> + /* Store raw key */
> + {
> + int ret = cmh_key_setkey_raw(&tctx->key, ptr,
> + raw_keylen, CORE_ID_HC);
> + if (ret)
> + return ret;
> + }
[Severity: High]
Could this lockless memory replacement race with an ongoing final() function?
The cmh_key_setkey_raw() function destroys the active key and unmaps its DMA
address. If this happens concurrently with hardware accessing the key memory
via DMA during a request, it could lead to a use-after-free and memory
corruption.
[ ... ]
> +static int cmh_kmac_init(struct ahash_request *req)
> +{
[ ... ]
> + rctx->error = 0;
> + INIT_LIST_HEAD(&rctx->chunks);
> + rctx->num_chunks = 0;
[Severity: High]
Does this cause a memory leak when a request is re-initialized?
Like in the cSHAKE driver, the chunk list is reset without freeing the
previously accumulated chunks, leaking kernel memory.
[ ... ]
> +static int cmh_kmac_update(struct ahash_request *req)
> +{
[ ... ]
> + chunk = kmalloc(sizeof(*chunk) + req->nbytes,
> + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
> + GFP_KERNEL : GFP_ATOMIC);
[Severity: Critical]
Can the arithmetic operation here wrap around on 32-bit platforms?
Since req->nbytes is controlled by the caller, providing an extremely large
value could overflow the addition and allocate a tiny buffer. The subsequent
data copy would then overwrite kernel heap memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806195519.2703224-1-skrishnamoorthy@rambus.com?part=6
next prev parent reply other threads:[~2026-08-06 20:10 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 19:54 [PATCH v3 00/19] crypto: cmh - add Rambus CryptoManager Hub driver Saravanakrishnan Krishnamoorthy
2026-08-06 19:55 ` [PATCH v3 01/19] dt-bindings: crypto: add Rambus CryptoManager Hub Saravanakrishnan Krishnamoorthy
2026-08-06 20:01 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 02/19] crypto: cmh - add core platform driver Saravanakrishnan Krishnamoorthy
2026-08-06 20:11 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 03/19] crypto: cmh - add key provisioning and management Saravanakrishnan Krishnamoorthy
2026-08-06 20:17 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 04/19] crypto: cmh - add SHA-2/SHA-3/SHAKE ahash Saravanakrishnan Krishnamoorthy
2026-08-06 20:12 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 05/19] crypto: cmh - add HMAC ahash Saravanakrishnan Krishnamoorthy
2026-08-06 20:09 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 06/19] crypto: cmh - add CSHAKE/KMAC ahash Saravanakrishnan Krishnamoorthy
2026-08-06 20:10 ` sashiko-bot [this message]
2026-08-06 19:55 ` [PATCH v3 07/19] crypto: cmh - add SM3 ahash Saravanakrishnan Krishnamoorthy
2026-08-06 20:07 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 08/19] crypto: cmh - add AES skcipher/aead/cmac Saravanakrishnan Krishnamoorthy
2026-08-06 20:10 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 09/19] crypto: cmh - add SM4 skcipher/aead/cmac/xcbc Saravanakrishnan Krishnamoorthy
2026-08-06 20:09 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 10/19] crypto: cmh - add ChaCha20-Poly1305 Saravanakrishnan Krishnamoorthy
2026-08-06 20:12 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 11/19] crypto: cmh - add DRBG hwrng Saravanakrishnan Krishnamoorthy
2026-08-06 20:17 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 12/19] crypto: cmh - add RSA akcipher Saravanakrishnan Krishnamoorthy
2026-08-06 20:18 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 13/19] crypto: cmh - add ECDSA/SM2 sig Saravanakrishnan Krishnamoorthy
2026-08-06 20:24 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 14/19] crypto: cmh - add ECDH/X25519 kpp Saravanakrishnan Krishnamoorthy
2026-08-06 20:34 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 15/19] crypto: cmh - add ML-KEM/ML-DSA (QSE) Saravanakrishnan Krishnamoorthy
2026-08-06 20:24 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 16/19] crypto: cmh - add SLH-DSA/LMS/XMSS (HCQ) Saravanakrishnan Krishnamoorthy
2026-08-06 20:43 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 17/19] Documentation: ioctl: add CMH ioctl documentation and register 'J' Saravanakrishnan Krishnamoorthy
2026-08-06 20:25 ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 18/19] selftests: crypto: cmh - add kselftest for management ioctl Saravanakrishnan Krishnamoorthy
2026-08-06 19:55 ` [PATCH v3 19/19] MAINTAINERS: add Rambus CryptoManager Hub (CMH) Saravanakrishnan Krishnamoorthy
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=20260806201037.CD0181F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=skrishnamoorthy@rambus.com \
/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