All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Saravanakrishnan Krishnamoorthy" <skrishnamoorthy@rambus.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 04/19] crypto: cmh - add SHA-2/SHA-3/SHAKE ahash
Date: Thu, 06 Aug 2026 20:12:05 +0000	[thread overview]
Message-ID: <20260806201206.160F11F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260806195519.2703224-5-skrishnamoorthy@rambus.com>

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:

New issues:
- [Critical] Integer overflow in `cmh_hash_finup()` leads to undersized allocation and heap buffer overflow.
- [High] Driver attempts to linearize entire scatterlists with `kmalloc()`, breaking the crypto API for large payloads.
- [High] Unaligned DMA mapping of an embedded structure member causes cacheline tearing.
- [High] SHAKE algorithms incorrectly use a `block_size` of 1, bypassing the hardware holdback logic.
- [High] Algorithm registration unconditionally assumes HC cores are present, leading to a fatal divide-by-zero.
- [Medium] Transient errors in `cmh_hash_update()` silently corrupt the request's holdback state.

Pre-existing issues:
- [High] Transaction manager thread is started before its 'running' flag is set, potentially causing immediate exit.
--

--- Patch [4]: [PATCH v3 04/19] crypto: cmh - add SHA-2/SHA-3/SHAKE ahash ---
commit cd0a896498edd93a15534bfd2d7287f9465b9b18
Author: Alex Ousherovitch <aousherovitch@rambus.com>

crypto: cmh - add SHA-2/SHA-3/SHAKE ahash

This commit registers ahash algorithms for SHA-2, SHA-3, and SHAKE families
using the CMH hash core. It implements incremental hardware updates, hardware
state save/restore across requests, and zero-copy from virtual buffers.

> diff --git a/drivers/crypto/cmh/cmh_hash.c b/drivers/crypto/cmh/cmh_hash.c
> new file mode 100644
> index 0000000000000..2a9a3c6a69855
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_hash.c
> @@ -0,0 +1,888 @@
[ ... ]
> +	{
> +		.hc_algo     = HC_ALGO_SHAKE128,
> +		.digest_size = CMH_SHAKE128_DIGEST_SIZE,
> +		.block_size  = 1,    /* XOF: no meaningful block for crypto API */

[Severity: High]
Does setting the block size to 1 here cause the hardware holdback logic to be
bypassed?

In cmh_hash_update(), the holdback checks:
    if (total_avail < block_size) { ... }

Since the block size is 1, this condition fails for any non-empty input. Could
this force the hardware to process unaligned byte counts instead of buffering
them to the required rate alignment?

> +		.alg_name    = "shake128",
> +		.drv_name    = "rambus-cmh-shake128",
> +	},
[ ... ]
> +struct cmh_hash_reqctx {
> +	const struct cmh_hash_alg_info *info;
> +	int    error;
> +	u32    hw_started;      /* non-zero after first HW submission */
> +	u32    buf_len;         /* bytes in holdback buf[] */
> +	u32    has_checkpoint;  /* non-zero if checkpoint[] valid */
> +	/* DMA state for current async operation */
> +	dma_addr_t ckpt_dma;   /* RESTORE input */
> +	dma_addr_t save_dma;   /* SAVE output (update only) */
> +	dma_addr_t data_dma;   /* UPDATE input */
> +	dma_addr_t digest_dma; /* FINAL output (final/digest only) */
> +	u8    *save_buf;       /* SAVE output buffer */
> +	u8    *data_buf;       /* linearised data for DMA */
> +	u32    data_len;       /* bytes in data_buf */
> +	u8    *digest_buf;     /* digest output buffer */
> +	u8     buf[CMH_HASH_MAX_BLOCK]; /* holdback for partial block */
> +	u8     checkpoint[HC_CONTEXT_SIZE]; /* HC context from last SAVE */

[Severity: High]
Is there a risk of cacheline tearing during DMA mapping here?

The checkpoint array is embedded within struct cmh_hash_reqctx without explicit
alignment constraints. When cmh_hash_update() invokes cmh_dma_map_single() on
this member, could flushing or invalidating the buffer corrupt adjacent fields
that share the same cacheline?

> +	struct vcq_cmd packed[CMH_HASH_MAX_PACKED];
> +};
[ ... ]
> +static int cmh_hash_update(struct ahash_request *req)
> +{
[ ... ]
> +	/*
> +	 * Linearise: holdback prefix + full blocks from scatterlist.
> +	 * full_len is user-controlled and can exceed KMALLOC_MAX_SIZE for a
> +	 * single large update; __GFP_NOWARN avoids splatting the page
> +	 * allocator on an oversized request.
> +	 */
> +	rctx->data_buf = kmalloc(full_len, gfp | __GFP_NOWARN);
> +	if (!rctx->data_buf)
> +		return -ENOMEM;

[Severity: High]
Can this memory allocation fail deterministically for valid large payloads?

The kernel crypto ahash API is expected to handle arbitrarily large
scatterlists. By attempting to linearize the entire operation into a single
physically contiguous buffer, could this fail for payloads exceeding the
maximum kmalloc size and break subsystems that rely on large streams?

> +
> +	if (rctx->buf_len > 0)
> +		memcpy(rctx->data_buf, rctx->buf, rctx->buf_len);
[ ... ]
> +	/* Move tail to holdback */
> +	if (tail_len > 0) {
> +		if (req->base.flags & CRYPTO_AHASH_REQ_VIRT)
> +			memcpy(rctx->buf, req->svirt + from_src,
> +			       tail_len);
> +		else
> +			scatterwalk_map_and_copy(rctx->buf, req->src,
> +						 from_src, tail_len,
> +						 0);
> +	}
> +	rctx->buf_len = tail_len;
> +	rctx->data_len = full_len;
> +
> +	/* Allocate SAVE output buffer */
> +	rctx->save_buf = kzalloc(HC_CONTEXT_SIZE, gfp);
> +	if (!rctx->save_buf) {
> +		ret = -ENOMEM;
> +		goto err_free;
> +	}

[Severity: Medium]
Could a memory allocation failure here permanently corrupt the internal hash
holdback state?

The tail data is copied to rctx->buf and rctx->buf_len is updated prior to
allocating save_buf. If this allocation or the subsequent DMA mapping fails,
the function returns early with an error, discarding the previous holdback
prefix data. Should the internal state mutation be deferred until all
allocations succeed?

[ ... ]
> +static int cmh_hash_finup(struct ahash_request *req)
> +{
[ ... ]
> +	data_len = rctx->buf_len + req->nbytes;

[Severity: Critical]
Can this integer addition wrap around for extremely large payloads?

Unlike cmh_hash_update(), which explicitly checks for overflow, this function
lacks validation. If data_len overflows, it would result in a small memory
allocation followed by a massive out-of-bounds copy operation below.

> +
> +	if (data_len == 0)
> +		return cmh_hash_submit_final(req, NULL, 0);
> +
> +	gfp = req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP ?
> +	      GFP_KERNEL : GFP_ATOMIC;
> +
> +	data_buf = kmalloc(data_len, gfp | __GFP_NOWARN);
> +	if (!data_buf)
> +		return -ENOMEM;

[Severity: High]
Similar to cmh_hash_update(), does linearizing the entire buffer with
kmalloc() break the crypto API contract for large scatterlists?

> +
> +	if (rctx->buf_len > 0)
> +		memcpy(data_buf, rctx->buf, rctx->buf_len);
> +
> +	if (req->nbytes > 0) {
> +		if (req->base.flags & CRYPTO_AHASH_REQ_VIRT)
> +			memcpy(data_buf + rctx->buf_len,
> +			       req->svirt, req->nbytes);
[ ... ]
> +int cmh_hash_register(void)
> +{
> +	unsigned int i;
> +	int ret;
> +
> +	for (i = 0; i < CMH_HASH_ALG_COUNT; i++) {
[ ... ]
> +		ret = crypto_register_ahash(alg);

[Severity: High]
Does this algorithm registration cause a divide-by-zero during testing if
the hardware lacks HC cores?

Algorithms are registered unconditionally here. When the crypto framework
allocates an algorithm for testing, cmh_core_select_instance() performs a
modulo by ct->num_instances. If the device tree safely omits HC cores, could
this crash during boot or driver probe?

[ ... ]

This isn't a bug introduced by this patch, but looking at cmh_tm_init() in
drivers/crypto/cmh/cmh_txn.c:

cmh_tm_init() {
    ...
    tm.thread = kthread_run(cmh_tm_thread, NULL, "cmh_tm");
    if (IS_ERR(tm.thread)) {
        ...
    }

    WRITE_ONCE(tm.running, true);
    ...
}

[Severity: High]
Could the transaction manager thread exit immediately upon creation?

Because kthread_run() synchronously starts and schedules cmh_tm_thread,
the new thread could check the tm.running flag before the parent thread
executes WRITE_ONCE(tm.running, true), observing it as false and exiting
permanently.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806195519.2703224-1-skrishnamoorthy@rambus.com?part=4

  reply	other threads:[~2026-08-06 20:12 UTC|newest]

Thread overview: 77+ 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:54 ` Saravanakrishnan Krishnamoorthy
2026-08-06 19:55 ` [PATCH v3 01/19] dt-bindings: crypto: add Rambus CryptoManager Hub Saravanakrishnan Krishnamoorthy
2026-08-06 19:55   ` Saravanakrishnan Krishnamoorthy
2026-08-06 20:01   ` sashiko-bot
2026-08-10  8:16   ` Krzysztof Kozlowski
2026-08-10  8:16     ` Krzysztof Kozlowski
2026-08-11  8:32     ` Krzysztof Kozlowski
2026-08-11  8:32       ` Krzysztof Kozlowski
2026-08-11 16:49       ` Ousherovitch, Alex
2026-08-11 16:49         ` Ousherovitch, Alex
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-11  8:31   ` Krzysztof Kozlowski
2026-08-11  8:31     ` Krzysztof Kozlowski
2026-08-11 18:19     ` Ousherovitch, Alex
2026-08-11 18:19       ` Ousherovitch, Alex
2026-08-11  8:36   ` Krzysztof Kozlowski
2026-08-11  8:36     ` Krzysztof Kozlowski
2026-08-11 18:20     ` Ousherovitch, Alex
2026-08-11 18:20       ` Ousherovitch, Alex
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-11  8:33   ` Krzysztof Kozlowski
2026-08-11  8:33     ` Krzysztof Kozlowski
2026-08-11 18:22     ` Ousherovitch, Alex
2026-08-11 18:22       ` Ousherovitch, Alex
2026-08-06 19:55 ` [PATCH v3 04/19] crypto: cmh - add SHA-2/SHA-3/SHAKE ahash Saravanakrishnan Krishnamoorthy
2026-08-06 19:55   ` Saravanakrishnan Krishnamoorthy
2026-08-06 20:12   ` sashiko-bot [this message]
2026-08-06 19:55 ` [PATCH v3 05/19] crypto: cmh - add HMAC ahash Saravanakrishnan Krishnamoorthy
2026-08-06 19:55   ` 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 19:55   ` Saravanakrishnan Krishnamoorthy
2026-08-06 20:10   ` sashiko-bot
2026-08-06 19:55 ` [PATCH v3 07/19] crypto: cmh - add SM3 ahash Saravanakrishnan Krishnamoorthy
2026-08-06 19:55   ` 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 19:55   ` 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 19:55   ` 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 19:55   ` 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 19:55   ` Saravanakrishnan Krishnamoorthy
2026-08-06 20:17   ` sashiko-bot
2026-08-11  8:38   ` Krzysztof Kozlowski
2026-08-11  8:38     ` Krzysztof Kozlowski
2026-08-11 18:23     ` Ousherovitch, Alex
2026-08-11 18:23       ` Ousherovitch, Alex
2026-08-06 19:55 ` [PATCH v3 12/19] crypto: cmh - add RSA akcipher Saravanakrishnan Krishnamoorthy
2026-08-06 19:55   ` 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 19:55   ` 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 19:55   ` 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 19:55   ` 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 19:55   ` 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 19:55   ` 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   ` Saravanakrishnan Krishnamoorthy
2026-08-06 19:55 ` [PATCH v3 19/19] MAINTAINERS: add Rambus CryptoManager Hub (CMH) Saravanakrishnan Krishnamoorthy
2026-08-06 19:55   ` 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=20260806201206.160F11F00A3A@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.