From: sashiko-bot@kernel.org
To: "Saravanakrishnan Krishnamoorthy" <skrishnamoorthy@rambus.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v3 13/19] crypto: cmh - add ECDSA/SM2 sig
Date: Thu, 06 Aug 2026 20:24:30 +0000 [thread overview]
Message-ID: <20260806202430.B78031F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806195519.2703224-14-skrishnamoorthy@rambus.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] DMA Use-After-Free (UAF) memory corruption during hardware timeout in synchronous ECDSA operations.
- [Medium] Latent stack buffer overflow in ecdsa_be_to_vli() due to flawed bounds checking logic.
--
--- Patch [13]: [PATCH v3 13/19] crypto: cmh - add ECDSA/SM2 sig ---
commit 93e934df7eae63fe0a90fc7b8a6f5ff276f60f86
Author: Alex Ousherovitch <aousherovitch@rambus.com>
crypto: cmh - add ECDSA/SM2 sig
Register ECDSA and SM2 sig algorithms using the CMH PKE core.
Supports P-256, P-384, P-521, and SM2 curves for sign and verify
operations. SM2 is registered as verify-only via the crypto API.
> diff --git a/drivers/crypto/cmh/cmh_pke_ecdsa.c b/drivers/crypto/cmh/cmh_pke_ecdsa.c
> new file mode 100644
> index 0000000000000..6d6b8aec6c884
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_pke_ecdsa.c
[ ... ]
> +static void ecdsa_be_to_vli(const u8 *in, unsigned int in_len,
> + u64 *vli, unsigned int max_digits)
> +{
> + unsigned int full_len = max_digits * sizeof(u64);
> + u8 tmp[ECC_MAX_BYTES];
> + unsigned int i;
> +
> + if (WARN_ON_ONCE(max_digits > ECC_MAX_DIGITS))
> + max_digits = ECC_MAX_DIGITS;
> +
> + memset(tmp, 0, full_len);
[Severity: Medium]
Does this code calculate full_len before clamping max_digits?
If a caller passes a large max_digits, full_len could exceed ECC_MAX_BYTES
before the clamping happens, potentially causing a stack buffer overflow
in the memset. Would it be safer to calculate full_len after the check?
[ ... ]
> +static int cmh_ecdsa_verify(struct crypto_sig *tfm,
> + const void *src, unsigned int slen,
> + const void *digest, unsigned int dlen)
> +{
[ ... ]
> + ret = cmh_tm_submit_sync_mbx(vcq, PKE_VCQ_CMDS_MIN, 1, d.mbx_idx);
> +
> +out_unmap:
> + if (!cmh_dma_map_error(rp_dma))
> + cmh_dma_unmap_single(rp_dma, clen, DMA_FROM_DEVICE);
> + if (!cmh_dma_map_error(sig_dma))
> + cmh_dma_unmap_single(sig_dma, sig_raw_len, DMA_TO_DEVICE);
> + if (!cmh_dma_map_error(dig_dma))
> + cmh_dma_unmap_single(dig_dma, clen, DMA_TO_DEVICE);
> + if (!cmh_dma_map_error(pk_dma))
> + cmh_dma_unmap_single(pk_dma, ctx->pub_key_len, DMA_TO_DEVICE);
> +
> +out_free:
> + kfree(rp_buf);
[Severity: High]
Is it possible for the hardware to still write to rp_buf if
cmh_tm_submit_sync_mbx() times out?
If a timeout occurs, this path unmaps and frees rp_buf back to the slab
allocator. Without a mechanism to abort the in-flight hardware operation,
could the hardware later complete its DMA write and corrupt the reallocated
memory?
> + kfree(pk_buf);
> + kfree(sig_raw);
> + kfree(dig_buf);
> + return ret;
> +}
[ ... ]
> +static int cmh_ecdsa_sign(struct crypto_sig *tfm,
> + const void *src, unsigned int slen,
> + void *dst, unsigned int dlen)
> +{
[ ... ]
> + ret = cmh_tm_submit_sync_mbx(vcq, idx, 1, dd.mbx_idx);
> + if (!ret) {
> + /* Sync bounce buffer so CPU sees the DMA-written signature */
> + cmh_dma_sync_for_cpu(sig_dma, sig_raw_len, DMA_FROM_DEVICE);
> +
> + /* Encode raw (r||s) into VLI ecdsa_raw_sig for kernel API */
> + ret = ecdsa_raw_to_sig(sig_buf, clen, dst, dlen);
> + }
> +
> +out_unmap:
> + if (!cmh_dma_map_error(sig_dma))
> + cmh_dma_unmap_single(sig_dma, sig_raw_len, DMA_FROM_DEVICE);
> + if (!cmh_dma_map_error(dig_dma))
> + cmh_dma_unmap_single(dig_dma, clen, DMA_TO_DEVICE);
> +
> +out_free:
> + kfree(sig_buf);
[Severity: High]
Similarly, does this free sig_buf while the hardware might still attempt a
DMA write upon a late completion?
Like the verify path, a timeout from cmh_tm_submit_sync_mbx could lead to
the hardware overwriting freed memory if the transaction is not successfully
aborted on the device.
> + kfree(dig_buf);
> + return ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806195519.2703224-1-skrishnamoorthy@rambus.com?part=13
next prev parent reply other threads:[~2026-08-06 20:24 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 [this message]
2026-08-06 19:55 ` [PATCH v3 14/19] crypto: cmh - add ECDH/X25519 kpp 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 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=20260806202430.B78031F000E9@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