All of lore.kernel.org
 help / color / mirror / Atom feed
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 05/19] crypto: cmh - add HMAC ahash
Date: Thu, 06 Aug 2026 20:09:19 +0000	[thread overview]
Message-ID: <20260806200919.BCAC11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806195519.2703224-6-skrishnamoorthy@rambus.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Unbounded kernel memory leak due to orphaned dynamically allocated chunks when a hash request is aborted before `.final()` or re-initialized/imported.
- [Medium] Potential out-of-bounds write in `cmh_hmac_export` when exporting the software fallback state due to missing statesize validation.
- [Medium] Mapping an unaligned interior pointer (`chunk->data`) for DMA violates DMA API requirements and risks cacheline corruption or runtime warnings.
--

--- Patch [5]: [PATCH v3 05/19] crypto: cmh - add HMAC ahash ---
commit 29cce2e66e05b4cda73d07e16e2b43d65f198bd1
Author: Alex Ousherovitch <aousherovitch@rambus.com>

crypto: cmh - add HMAC ahash

This commit registers HMAC-SHA-2 and HMAC-SHA-3 ahash algorithms using the
CMH hash core. It implements a self-contained transaction model with
software fallback for large accumulated inputs and state cloning.

> diff --git a/drivers/crypto/cmh/cmh_hmac.c b/drivers/crypto/cmh/cmh_hmac.c
> new file mode 100644
> index 0000000000000..b43b358c35963
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_hmac.c
> @@ -0,0 +1,865 @@
[ ... ]
> +struct cmh_hmac_chunk {
> +	struct list_head  list;
> +	struct list_head  tfm_node; /* per-tfm orphan tracking */
> +	u32               len;
> +	u8                data[];
> +};

[Severity: Medium]
Does mapping this unaligned data array violate DMA API requirements?

The data array sits at an unaligned offset (36 bytes), which shares a
cacheline with the struct's metadata.

Later, in cmh_hmac_build_sg(), this unaligned interior pointer is passed to
the DMA mapping subsystem:

    list_for_each_entry(chunk, &rctx->chunks, list) {
        bufs[i].data = chunk->data;
        bufs[i].len = chunk->len;
        i++;
    }
    sgm = cmh_dma_build_sg(bufs, rctx->num_chunks, gfp);

Could this risk cacheline corruption on non-coherent architectures and
trigger CONFIG_DMA_API_DEBUG warnings?

[ ... ]
> +static int cmh_hmac_init(struct ahash_request *req)
> +{
> +	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> +	struct cmh_hmac_reqctx *rctx = ahash_request_ctx(req);
> +
> +	rctx->info = cmh_hmac_get_info(tfm);
> +	rctx->error = 0;
> +	INIT_LIST_HEAD(&rctx->chunks);

[Severity: High]
If cmh_hmac_init() is called on an active request, does this unconditionally
overwrite the list head and permanently lose track of any locally buffered
chunks?

A similar pattern appears in cmh_hmac_import().

[ ... ]
> +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;
> +	}
[ ... ]
> +	list_add_tail(&chunk->list, &rctx->chunks);
> +	spin_lock_bh(&tctx->chunk_lock);
> +	list_add_tail(&chunk->tfm_node, &tctx->all_chunks);
> +	spin_unlock_bh(&tctx->chunk_lock);

[Severity: High]
What happens to these allocations if an unprivileged user creates an
AF_ALG socket, sends data to trigger this allocation, and then closes the
socket before calling recv() to trigger final()?

Since the crypto API has no per-request destructor, and these chunks are
added to the global tctx->all_chunks list, it appears they are only freed
in cmh_hmac_cra_exit():

    list_for_each_entry_safe(chunk, tmp, &tctx->all_chunks, tfm_node) {
        list_del(&chunk->tfm_node);
        kfree_sensitive(chunk);
    }

Could a user repeat this in a loop on new accepted sockets to indefinitely
consume kernel memory until the system runs out of memory?

[ ... ]
> +static int cmh_hmac_export(struct ahash_request *req, void *out)
> +{
[ ... ]
> +	if (rctx->switched) {
> +		state->format = CMH_HMAC_FMT_FB;
> +		return crypto_ahash_export(cmh_hmac_fb_req(rctx), state->data);
> +	}

[Severity: Medium]
Is there a risk of an out-of-bounds write here if the generic software
fallback algorithm allocated in cmh_hmac_cra_init() has a state size larger
than CMH_HMAC_EXPORT_MAX?

The state buffer size is computed using crypto_ahash_statesize(tfm), but
there appears to be no structural validation in cmh_hmac_cra_init() ensuring
the allocated fallback's state actually fits within this fixed-size limit
before it is exported.

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

  reply	other threads:[~2026-08-06 20:09 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
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 [this message]
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=20260806200919.BCAC11F000E9@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.