devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Saravanakrishnan Krishnamoorthy" <skrishnamoorthy@rambus.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 14/19] crypto: cmh - add ECDH/X25519 kpp
Date: Thu, 06 Aug 2026 20:34:21 +0000	[thread overview]
Message-ID: <20260806203422.3D1461F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806195519.2703224-15-skrishnamoorthy@rambus.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Hardware datastore slots allocated for the ECDH shared secret are permanently leaked on success and error paths.
- [Medium] Phase 2 of shared secret computation violates the async crypto API contract by unconditionally enabling backlog and bubbling spurious `-EINPROGRESS` notifications.
- [Medium] The driver bypasses FIPS 186-5 validation for caller-provided private scalars on NIST curves, allowing degenerate or out-of-bounds keys.
--

--- Patch [14]: [PATCH v3 14/19] crypto: cmh - add ECDH/X25519 kpp ---
commit 9f2cb0033e85cf322ca1c6ba96a2932f498d8824
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..1b49dd060e52c
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_pke_ecdh.c

[ ... ]

> +static int cmh_ecdh_set_secret_nist(struct crypto_kpp *tfm,
> +				    const void *buf, unsigned int len)
> +{

[ ... ]

> +	if (key_size == 0) {
> +		/*
> +		 * key_size == 0: generate a validated random private key.
> +		 * Uses the kernel ECC library (FIPS 186-5 A.2.2) to ensure
> +		 * the scalar is in the valid range [2, n-3] for the curve.
> +		 */

[ ... ]

> +		ret = cmh_key_setkey_raw(&ctx->key, rnd, ctx->clen,
> +					 CORE_ID_PKE);
> +		kfree_sensitive(rnd);
> +		return ret;
> +	}
> +
> +	if (key_size != ctx->clen)
> +		return -EINVAL;
> +
> +	if (secret.len != ECDH_KPP_SECRET_MIN_SIZE + key_size)
> +		return -EINVAL;
> +
> +	return cmh_key_setkey_raw(&ctx->key, ptr, key_size, CORE_ID_PKE);

[Severity: Medium]
Are we missing a validity check for caller-provided private scalars?

When key_size != 0, we write the raw private key directly into the key
context without calling ecc_is_key_valid() to verify it falls within the
valid range [1, n-1] for the NIST curve.

> +}

[ ... ]

> +static void cmh_ecdh_ss_phase1_complete(void *data, int error)
> +{

[ ... ]

> +	/* Read the DS reference written by Phase 1 */
> +	cmh_dma_sync_for_cpu(rctx->ref_dma, sizeof(u64), DMA_FROM_DEVICE);
> +	cmh_dma_unmap_single(rctx->ref_dma, sizeof(u64), DMA_FROM_DEVICE);
> +	rctx->ref_dma = DMA_MAPPING_ERROR;
> +
> +	/* Phase 2: extract shared secret from DS */
> +	vcq_set_header(&vcq[0], 3);
> +	vcq_add_sys_data(&vcq[1], *rctx->ref_buf, rctx->ss_dma,
> +			 rctx->clen);
> +	vcq[1].id |= rctx->dma_swap;
> +	vcq_add_sys_flush(&vcq[2]);
> +
> +	ret = cmh_tm_submit_async(vcq, 3, 1, rctx->mbx_idx,
> +				  cmh_ecdh_ss_phase2_complete, req,
> +				  true, 0);

[Severity: Medium]
Can this violate the async crypto API contract by bubbling spurious
-EINPROGRESS notifications?

Phase 2 submission hardcodes the backlog_ok parameter to true, which ignores
the user's req->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG setting.

If the queue is full and Phase 2 is backlogged, cmh_ecdh_ss_phase2_complete()
will pass -EINPROGRESS to cmh_complete(), even if the caller did not allow
backlogging.

> +	if (ret == -EBUSY || !ret)
> +		return;
> +
> +	error = ret;
> +
> +out_cleanup:
> +	if (!cmh_dma_map_error(rctx->ref_dma))
> +		cmh_dma_unmap_single(rctx->ref_dma, sizeof(u64),
> +				     DMA_FROM_DEVICE);
> +	if (!cmh_dma_map_error(rctx->ss_dma))
> +		cmh_dma_unmap_single(rctx->ss_dma, rctx->clen,
> +				     DMA_FROM_DEVICE);
> +	kfree(rctx->ref_buf);
> +	rctx->ref_buf = NULL;
> +	kfree_sensitive(rctx->ss_buf);
> +	rctx->ss_buf = NULL;
> +	cmh_complete(&req->base, error);
> +}

[ ... ]

> +static int cmh_ecdh_compute_shared_secret(struct kpp_request *req)
> +{

[ ... ]

> +	dd = cmh_core_select_instance(CMH_CORE_PKE);
> +	rctx->mbx_idx = dd.mbx_idx;
> +
> +	vcq_set_header(&vcq[0], 5);
> +	idx = 1;
> +	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);
> +	vcq[idx].id |= dma_swap;
> +	idx++;
> +	vcq_add_sys_new(&vcq[idx++], 0, rctx->ref_dma, clen);

[Severity: High]
Does this leak the hardware datastore slot?

We allocate a DS slot using SYS_CMD_NEW, but neither the success path in
cmh_ecdh_ss_phase2_complete() nor the error path in
cmh_ecdh_ss_phase1_complete() appear to issue a SYS_CMD_GRANT with 0
permissions to delete the object.

Could this eventually exhaust the hardware datastore memory on repeated
operations?

> +	vcq_add_pke_ecdh(&vcq[idx++], dd.core_id, ctx->curve, clen,
> +			 clen, ss_type, rctx->peer_dma,
> +			 SYS_REF_TEMP, SYS_REF_LAST, swap);
> +	vcq_add_pke_flush(&vcq[idx++], dd.core_id);
> +
> +	ret = cmh_tm_submit_async(vcq, 5, 1, dd.mbx_idx,
> +				  cmh_ecdh_ss_phase1_complete, req,
> +				  !!(req->base.flags &
> +				     CRYPTO_TFM_REQ_MAY_BACKLOG), 0);

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

  reply	other threads:[~2026-08-06 20:34 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
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 [this message]
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=20260806203422.3D1461F000E9@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;
as well as URLs for NNTP newsgroup(s).