Devicetree
 help / color / mirror / Atom feed
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 06/19] crypto: cmh - add CSHAKE/KMAC ahash
Date: Thu, 17 Sep 2026 23:16:32 +0000	[thread overview]
Message-ID: <20260917231632.DC5881F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917225929.2494111-7-aousherovitch@rambus.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] crypto: cmh: cshake arbitrary length kmalloc causes ENOMEM/EMSGSIZE
- [High] crypto: cmh: kmac init on active request leaks chunks causing TFM DoS
- [High] crypto: cmh: kmac finup duplicates data on EAGAIN retry
- [Medium] crypto: cmh: kmac final error path allows empty MAC generation on retry
--

commit c5367ee10d2ec6e4de159d32bb1d2e8f203ad0f6
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. CSHAKE supports incremental update and
export/import, while KMAC accumulates the input for a single finalize-time
submission.

> diff --git a/drivers/crypto/cmh/cmh_cshake.c b/drivers/crypto/cmh/cmh_cshake.c
> new file mode 100644
> index 0000000000000..56a6453a0e4fe
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_cshake.c
> @@ -0,0 +1,873 @@

[ ... ]

> +static int cmh_cshake_update(struct ahash_request *req)
> +{

[ ... ]

> +	/*
> +	 * Reject a single update whose linearisation would exceed the largest
> +	 * kmalloc: return a permanent -EMSGSIZE ("message too long") rather
> +	 * than a transient -ENOMEM the client would keep retrying.
> +	 */
> +	if (full_len > KMALLOC_MAX_SIZE)
> +		return -EMSGSIZE;
> +
> +	rctx->data_buf = kmalloc(full_len, gfp | __GFP_NOWARN);
> +	if (!rctx->data_buf)
> +		return -ENOMEM;

[Severity: High]
Does this code artificially limit standard ahash capabilities? The ahash API
requires drivers to support arbitrary-length inputs provided as scatterlists.

By linearizing the entire input scatterlist into a single contiguous kmalloc
buffer, inputs larger than KMALLOC_MAX_SIZE are rejected with -EMSGSIZE.

Even for large inputs below this limit, relying on high-order contiguous
allocations is prone to -ENOMEM failures under memory fragmentation.

[ ... ]

> +static int cmh_cshake_finup(struct ahash_request *req)
> +{

[ ... ]

> +	/* Reject an oversized linearisation with a permanent -EMSGSIZE. */
> +	if (data_len > KMALLOC_MAX_SIZE)
> +		return -EMSGSIZE;
> +
> +	gfp = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
> +	      GFP_KERNEL : GFP_ATOMIC;
> +
> +	data_buf = kmalloc(data_len, gfp | __GFP_NOWARN);

[Severity: High]
Is this the same single-buffer allocation pattern repeated here?

This appears to also break standard API usage by failing on large inputs.

> diff --git a/drivers/crypto/cmh/cmh_kmac.c b/drivers/crypto/cmh/cmh_kmac.c
> new file mode 100644
> index 0000000000000..97ff36af13a07
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_kmac.c
> @@ -0,0 +1,690 @@

[ ... ]

> +static int cmh_kmac_init(struct ahash_request *req)
> +{
> +	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> +	struct cmh_kmac_reqctx *rctx = ahash_request_ctx(req);
> +
> +	rctx->info = cmh_kmac_get_info(tfm);
> +	rctx->error = 0;
> +	INIT_LIST_HEAD(&rctx->chunks);
> +	rctx->num_chunks = 0;
> +	rctx->total_len = 0;
> +
> +	return 0;
> +}

[Severity: High]
Could this leak previously accumulated chunks on an active request?

Re-initializing an active request is permitted by the kernel crypto API to
abort a stream and restart. This code resets the list with INIT_LIST_HEAD
without calling cmh_kmac_free_chunks() to free any existing data.

The chunks would remain orphaned on tctx->all_chunks, permanently consuming
the per-TFM memory cap. Repeated aborts/re-inits will exhaust
CMH_KMAC_TFM_MAX_BUFFERED, breaking all subsequent operations on the TFM
with -ENOMEM.

[ ... ]

> +static int cmh_kmac_final(struct ahash_request *req)
> +{

[ ... ]

> +out_free:
> +	cmh_kmac_free_chunks(rctx, tctx);
> +	return ret;
> +}

[Severity: Medium]
Will this error path fail to prevent subsequent calls from silently hashing
an empty buffer?

If a synchronous failure occurs and the code jumps to out_free, it destroys
the accumulated input state but doesn't set rctx->error = ret.

If the caller retries the failed operation, the driver will see 0 chunks
and no error, and compute a MAC for an empty string instead of returning
the failure.

[ ... ]

> +static int cmh_kmac_finup(struct ahash_request *req)
> +{
> +	int ret;
> +
> +	ret = cmh_kmac_update(req);
> +	if (ret)
> +		return ret;
> +
> +	return cmh_kmac_final(req);
> +}

[Severity: High]
Does this logic duplicate data if the operation is retried?

If cmh_kmac_final() fails with -EAGAIN or -EBUSY, it intentionally retains
accumulated chunks so the caller can retry the submission. However, if the
original operation was crypto_ahash_finup(), the caller will retry finup.

This will call cmh_kmac_update() again, unconditionally allocating and
appending the input data to rctx->chunks, which duplicates the input data
and causes the retried operation to output an incorrect MAC.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260917225929.2494111-1-aousherovitch@rambus.com?part=6

  reply	other threads:[~2026-09-17 23:16 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
2026-09-17 22:59 ` [PATCH v5 06/19] crypto: cmh - add CSHAKE/KMAC ahash Alex Ousherovitch
2026-09-17 23:16   ` sashiko-bot [this message]
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=20260917231632.DC5881F000FF@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