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 v4 14/19] crypto: cmh - add ECDH/X25519 kpp
Date: Tue, 25 Aug 2026 22:41:28 +0000 [thread overview]
Message-ID: <20260825224129.3AC111F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825221539.255951-15-aousherovitch@rambus.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Lack of synchronization in `cmh_ecdh_scratch_free` causes a data race and Use-After-Free/NULL-dereference with active TFMs.
- [High] Async PKE operations directly reference `ctx->key.raw.dma` without taking a reference, leading to a DMA Use-After-Free if `set_secret` is called concurrently.
--
commit 9c7dc04a32751847394f5938e43b1f3fa2bfd7c8
Author: Alex Ousherovitch <aousherovitch@rambus.com>
crypto: cmh - add ECDH/X25519 kpp
Register ECDH and X25519 kpp algorithms using the CMH PKE core.
Supports P-256, P-384, and Curve25519 for key agreement.
> diff --git a/drivers/crypto/cmh/cmh_pke_ecdh.c b/drivers/crypto/cmh/cmh_pke_ecdh.c
> new file mode 100644
> index 0000000000000..2264fea1facbb
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_pke_ecdh.c
[ ... ]
> +static int cmh_ecdh_generate_public_key(struct kpp_request *req)
> +{
[ ... ]
> + vcq_add_sys_write(&vcq[idx], SYS_REF_TEMP, ctx->key.raw.dma,
> + SYS_REF_NONE, ctx->key.raw.len,
> + ctx->key.raw.sys_type);
[Severity: High]
Does this code risk a DMA use-after-free if the key is updated concurrently?
This queues an asynchronous hardware command using the transform's key DMA
address (ctx->key.raw.dma) as the data source, and then returns -EINPROGRESS.
However, the kernel crypto API does not serialize set_secret against in-flight
asynchronous operations.
If set_secret is called concurrently, cmh_ecdh_commit_key() delegates to
cmh_key_setkey_raw(), which destroys the key:
drivers/crypto/cmh/cmh_key.c:cmh_key_destroy() {
if (ctx->mode == CMH_KEY_RAW && ctx->raw.data) {
cmh_dma_unmap_single(ctx->raw.dma, ctx->raw.len,
DMA_TO_DEVICE);
kfree_sensitive(ctx->raw.data);
...
}
This immediately executes cmh_dma_unmap_single() and kfree_sensitive() on the
key material without waiting for pending operations to complete. Could this
allow the hardware to read from unmapped or freed memory?
[ ... ]
> +static void cmh_ecdh_scratch_free(void)
> +{
> + u32 i;
> +
> + if (!cmh_ecdh_key_scratch)
> + return;
> +
> + for (i = 0; i < cmh_ecdh_scratch_count; i++) {
> + struct vcq_cmd vcq[3];
> +
> + if (!cmh_ecdh_key_scratch[i])
> + continue;
> +
> + vcq_set_header(&vcq[0], 3);
> + vcq_add_sys_grant(&vcq[1], cmh_ecdh_key_scratch[i], 0, 0, 0);
> + vcq_add_sys_flush(&vcq[2]);
> + cmh_tm_submit_sync_mbx(vcq, 3, 1, (s32)i);
> + cmh_ecdh_key_scratch[i] = 0;
> + }
> +
> + kfree(cmh_ecdh_key_scratch);
> + cmh_ecdh_key_scratch = NULL;
> + cmh_ecdh_scratch_count = 0;
> + cmh_ecdh_scratch_ready = false;
> +}
[Severity: High]
Does this cleanup path safely handle active TFMs?
This function frees the cmh_ecdh_key_scratch array without holding the
cmh_ecdh_scratch_lock mutex and without waiting for active TFMs to be
destroyed.
If the device is unbound (e.g., via sysfs unbind) while a user holds an
active AF_ALG socket, the remove path calls cmh_remove() ->
cmh_pke_ecdh_unregister() -> cmh_ecdh_scratch_free().
If the user submits a request via the active socket concurrently:
drivers/crypto/cmh/cmh_pke_ecdh.c:cmh_ecdh_compute_shared_secret() {
...
if (dd.mbx_idx < 0 || (u32)dd.mbx_idx >= cmh_ecdh_scratch_count ||
!cmh_ecdh_key_scratch[dd.mbx_idx]) {
ret = -EIO;
goto out_unmap;
}
...
}
This locklessly accesses cmh_ecdh_key_scratch, leading to a NULL pointer
dereference or reading unmapped memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260825221539.255951-1-aousherovitch@rambus.com?part=14
next prev parent reply other threads:[~2026-08-25 22:41 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 22:15 [PATCH v4 00/19] crypto: cmh - add Rambus CryptoManager Hub driver Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 01/19] dt-bindings: crypto: add Rambus CryptoManager Hub Alex Ousherovitch
2026-08-25 22:28 ` sashiko-bot
2026-08-26 17:02 ` Conor Dooley
2026-08-27 1:39 ` Ousherovitch, Alex
2026-08-27 17:14 ` Conor Dooley
2026-08-27 18:21 ` Ousherovitch, Alex
2026-08-25 22:15 ` [PATCH v4 02/19] crypto: cmh - add core platform driver Alex Ousherovitch
2026-08-25 22:34 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 03/19] crypto: cmh - add key provisioning and management Alex Ousherovitch
2026-08-25 22:30 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 04/19] crypto: cmh - add SHA-2/SHA-3/SHAKE ahash Alex Ousherovitch
2026-08-25 22:27 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 05/19] crypto: cmh - add HMAC ahash Alex Ousherovitch
2026-08-25 22:30 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 06/19] crypto: cmh - add CSHAKE/KMAC ahash Alex Ousherovitch
2026-08-25 22:30 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 07/19] crypto: cmh - add SM3 ahash Alex Ousherovitch
2026-08-25 22:28 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 08/19] crypto: cmh - add AES skcipher/aead/cmac Alex Ousherovitch
2026-08-25 22:28 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 09/19] crypto: cmh - add SM4 skcipher/aead/cmac/xcbc Alex Ousherovitch
2026-08-25 22:25 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 10/19] crypto: cmh - add ChaCha20-Poly1305 Alex Ousherovitch
2026-08-25 22:30 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 11/19] crypto: cmh - add DRBG hwrng Alex Ousherovitch
2026-08-25 22:32 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 12/19] crypto: cmh - add RSA akcipher Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 13/19] crypto: cmh - add ECDSA/SM2 sig Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 14/19] crypto: cmh - add ECDH/X25519 kpp Alex Ousherovitch
2026-08-25 22:41 ` sashiko-bot [this message]
2026-08-25 22:15 ` [PATCH v4 15/19] crypto: cmh - add ML-KEM/ML-DSA (QSE) Alex Ousherovitch
2026-08-25 22:36 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 16/19] crypto: cmh - add SLH-DSA/LMS/XMSS (HCQ) Alex Ousherovitch
2026-08-25 22:37 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 17/19] Documentation: ioctl: add CMH ioctl documentation and register 'J' Alex Ousherovitch
2026-08-25 22:34 ` sashiko-bot
2026-08-25 22:15 ` [PATCH v4 18/19] selftests: crypto: cmh - add kselftest for management ioctl Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 19/19] MAINTAINERS: add Rambus CryptoManager Hub (CMH) Alex Ousherovitch
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=20260825224129.3AC111F000E9@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