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 12/19] crypto: cmh - add RSA akcipher
Date: Thu, 06 Aug 2026 20:18:27 +0000 [thread overview]
Message-ID: <20260806201828.11D1F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806195519.2703224-13-skrishnamoorthy@rambus.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] State corruption in RSA akcipher key setup allows unprivileged kernel panic or out-of-bounds DMA access.
--
--- Patch [12]: [PATCH v3 12/19] crypto: cmh - add RSA akcipher ---
commit 1cce85c01c65473c016e5f55fbec7d241cfe672c
Author: Alex Ousherovitch <aousherovitch@rambus.com>
crypto: cmh - add RSA akcipher
This commit registers the RSA akcipher algorithm using the CMH PKE core.
It supports encrypt, decrypt, sign, and verify operations with 2048, 3072,
and 4096-bit keys, as well as 512 and 1024-bit keys for interoperability.
> diff --git a/drivers/crypto/cmh/cmh_pke_rsa.c b/drivers/crypto/cmh/cmh_pke_rsa.c
> new file mode 100644
> index 0000000000000..a848b7eddc8e2
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_pke_rsa.c
[ ... ]
> +static int cmh_rsa_set_pub_key(struct crypto_akcipher *tfm,
> + const void *key, unsigned int keylen)
> +{
> + struct cmh_rsa_tfm_ctx *ctx = cmh_rsa_ctx(tfm);
> + struct rsa_key rsa = {};
> + int ret;
[ ... ]
> + /* Strip ASN.1 leading zero padding from modulus */
> + while (rsa.n_sz > 0 && rsa.n[0] == 0) {
> + rsa.n++;
> + rsa.n_sz--;
> + }
> +
> + ctx->bits = cmh_rsa_key_bits(rsa.n_sz);
> + if (!ctx->bits)
> + return -EINVAL;
> +
> + /* Reject an exponent wider than the modulus (HW buffer bound). */
> + if (!rsa.e_sz || rsa.e_sz > ctx->bits / 8)
> + return -EINVAL;
[Severity: Critical]
Does this code corrupt the tfm state if validation fails?
If a valid key is set first, ctx->n and ctx->e are populated. Then, if
a subsequent invalid key is provided (e.g. an unsupported modulus size where
cmh_rsa_key_bits() returns 0), ctx->bits is updated to 0 and an error is
returned.
This leaves the tfm in a split state where ctx->n and ctx->e are non-NULL
but ctx->bits is 0.
If a subsequent cmh_rsa_enc() is called with a zero-length source buffer:
cmh_rsa_enc()
u32 key_bytes = ctx->bits / 8; // 0
...
rctx->m_buf = kzalloc(key_bytes, gfp); // Returns ZERO_SIZE_PTR
...
rctx->m_dma = cmh_dma_map_single(rctx->m_buf, key_bytes, DMA_TO_DEVICE);
The ZERO_SIZE_PTR is passed to cmh_dma_map_single(), which can cause a
kernel panic (Oops). This path appears reachable by unprivileged userspace
via the AF_ALG interface.
[ ... ]
> +static int cmh_rsa_set_priv_key(struct crypto_akcipher *tfm,
> + const void *key, unsigned int keylen)
> +{
> + struct cmh_rsa_tfm_ctx *ctx = cmh_rsa_ctx(tfm);
> + struct rsa_key rsa = {};
> + u32 key_bytes;
> + u8 *d_padded;
> + int ret;
[ ... ]
> + /* Strip ASN.1 leading zero padding from modulus */
> + while (rsa.n_sz > 0 && rsa.n[0] == 0) {
> + rsa.n++;
> + rsa.n_sz--;
> + }
> +
> + ctx->bits = cmh_rsa_key_bits(rsa.n_sz);
> + if (!ctx->bits || !rsa.d_sz)
> + return -EINVAL;
> +
> + key_bytes = ctx->bits / 8;
> +
> + /* Strip ASN.1 leading zero padding from private exponent */
> + while (rsa.d_sz > 0 && rsa.d[0] == 0) {
> + rsa.d++;
> + rsa.d_sz--;
> + }
> +
> + if (!rsa.d_sz || rsa.d_sz > key_bytes)
> + return -EINVAL;
[Severity: Critical]
Could this similarly corrupt ctx->bits on failure?
As with cmh_rsa_set_pub_key(), updating ctx->bits before completing all
validation checks allows the tfm to be left in an inconsistent state if an
error is returned, potentially leading to the same zero-size allocation and
DMA mapping crash during later operations.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260806195519.2703224-1-skrishnamoorthy@rambus.com?part=12
next prev parent reply other threads:[~2026-08-06 20:18 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 [this message]
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
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=20260806201828.11D1F1F000E9@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