Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Ousherovitch" <aousherovitch@rambus.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 03/19] crypto: cmh - add key provisioning and management
Date: Tue, 25 Aug 2026 22:30:10 +0000	[thread overview]
Message-ID: <20260825223010.9986B1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260825221539.255951-4-aousherovitch@rambus.com>

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] Persistent datastore objects are permanently leaked on success and error paths, allowing unprivileged DoS of the hardware datastore.
- [High] Missing `PKE_SWAP_FLAGS` in `cmh_mgmt_sm2_ecdh_hash` causes cryptographic corruption.
- [High] Treating DMA address 0 as "absent" causes silent cryptographic degradation and mapping leaks.
- [High] Unprotected concurrent access to `SYS_REF_TEMP` allows cross-process crypto key theft and corruption.
- [High] RSA buffer lengths are calculated via truncation, causing hardware DMA overflows on unaligned key sizes.
- [Medium] Cryptographic randomness buffers are freed with `kfree()` instead of `kfree_sensitive()`, leaking secrets.
- [Medium] `KEY_READ` fails to apply the reverse byte-swap for PKE keys, returning obfuscated keys to userspace.
--

commit 67f85ec0363d5636a036b63752d2d0407ae36205
Author: Alex Ousherovitch <aousherovitch@rambus.com>

crypto: cmh - add key provisioning and management

The in-kernel crypto API cannot express the CMH management plane, so
this patch adds a character device (/dev/cmh_mgmt) for it. The ioctl
commands fall into two groups, enabling datastore key lifecycle
management, KIC derivation, and asymmetric/PQC operations that keep
the private key hardware-resident.

> diff --git a/drivers/crypto/cmh/cmh_mgmt.c b/drivers/crypto/cmh/cmh_mgmt.c
> new file mode 100644
> index 0000000000000..c17a60a436c0f
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_mgmt.c

[ ... ]

> @@ -274,6 +274,10 @@ static int cmh_mgmt_key_read(void __user *argp)
>  		return -ENOMEM;
>  	}
>  
>  	vcq_set_header(&vcq[0], MGMT_VCQ_CMDS);
>  	vcq_add_sys_read(&vcq[1], req.ref, dma_addr, req.wrap_key, req.len);
>  	vcq_add_sys_flush(&vcq[2]);

[Severity: Medium]
Does this command need to conditionally reverse the PKE byte swap?

If a user writes an RSA or ECC key via KEY_WRITE, the driver applies
PKE_SWAP_FLAGS to store it in the internal big-endian representation.

Since the flags are not reversed here, could this return obfuscated, swapped
keys back to userspace?

[ ... ]

> @@ -661,6 +661,10 @@ static int cmh_mgmt_kic_hkdf1(void __user *argp)
>  out_ref:
>  	if (ref_buf) {
>  		cmh_dma_unmap_single(ref_dma, sizeof(*ref_buf),
>  				     DMA_FROM_DEVICE);
>  		kfree(ref_buf);
>  	}
>  	return ret;
>  }

[Severity: High]
Could this error path leak a persistent datastore object?

If cmh_tm_submit_sync_mbx() fails after the SYS_CMD_NEW command has already
executed and allocated the slot, this path does not call cmh_mgmt_ds_scrub().

This appears to leave an orphaned slot in the hardware datastore. Could a
caller repeatedly trigger timeouts or failures here to exhaust the finite
datastore capacity?

[ ... ]

> @@ -1094,6 +1094,10 @@ static int cmh_mgmt_kic_aes_cmac_kdf(void __user *argp)
>  out_unmap_label_cmac:
>  	if (label_buf && !cmh_dma_map_error(label_dma) && label_dma)
>  		cmh_dma_unmap_single(label_dma, req.label_len, DMA_TO_DEVICE);

[Severity: High]
Is it safe to treat DMA address 0 as an invalid mapping here?

On many architectures, 0 is a valid IOVA. The && label_dma check means the
mapping will be leaked if the label happens to map to address 0.

[ ... ]

> @@ -1470,6 +1470,12 @@ static long cmh_mgmt_ioctl(struct file *file, unsigned int cmd,
>  			   unsigned long arg)
>  {
>  	void __user *argp = (void __user *)arg;
>  	int ret;
>  
>  	if (cmh_mgmt_needs_temp_flush(cmd) &&
>  	    atomic_xchg(&mgmt_temp_dirty, 0)) {
>  		ret = cmh_tm_flush_mbx(MGMT_MBX);

[Severity: High]
Is the per-mailbox SYS_REF_TEMP state fully protected here?

The lockless atomic_xchg combined with the lack of an ioctl-level mutex
appears to leave the temporary key store vulnerable to concurrent clobbering.

If two processes interleave calls (e.g., one doing KIC_HKDF1 and another
doing DS_EXPORT), could temporary keys derived by one process be exported or
overwritten by the other?

> diff --git a/drivers/crypto/cmh/cmh_mgmt_pke.c b/drivers/crypto/cmh/cmh_mgmt_pke.c
> new file mode 100644
> index 0000000000000..649ad20086579
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_mgmt_pke.c

[ ... ]

> @@ -50,6 +50,10 @@ int cmh_mgmt_pke_rsa_enc(void __user *argp)
>  	if (req.bits < PKE_RSA_MIN_BITS || req.bits > PKE_RSA_MAX_BITS)
>  		return -EINVAL;
>  	if (!req.e_len || req.e_len > PKE_MAX_OPERAND)
>  		return -EINVAL;
>  
>  	n_len = req.bits / 8;

[Severity: High]
If req.bits is not a multiple of 8 (e.g., 2049), does this integer division
drop the fractional byte?

This would underestimate the required DMA buffer size.

Could the hardware then write more bytes than the buffer holds, leading to
memory corruption or an IOMMU fault?

> diff --git a/drivers/crypto/cmh/cmh_mgmt_pqc.c b/drivers/crypto/cmh/cmh_mgmt_pqc.c
> new file mode 100644
> index 0000000000000..83af21eec716e
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_mgmt_pqc.c

[ ... ]

> @@ -852,6 +852,10 @@ int cmh_mgmt_ml_dsa_sign(void __user *argp)
>  out_unmap:
>  	if (rnd_dma && !cmh_dma_map_error(rnd_dma))
>  		cmh_dma_unmap_single(rnd_dma, rnd_len, DMA_TO_DEVICE);

[Severity: High]
Is this if (rnd_dma) check correct for validating the DMA mapping?

As mentioned earlier, DMA address 0 is a valid IOVA on some platforms. If the
mapping returns 0, this check evaluates to false and skips unmapping, which
leaks the mapping.

If the hardware interprets a 0 pointer as absent randomness, could this also
silently drop the randomness from the signature generation, degrading its
security?

[ ... ]

> @@ -869,6 +873,11 @@ int cmh_mgmt_ml_dsa_sign(void __user *argp)
>  out_free:
>  	kfree(rnd_buf);
>  	kfree(sig_buf);
>  	kfree(m_buf);
>  	kfree_sensitive(sk_buf);
>  	return ret;
>  }

[Severity: Medium]
Should rnd_buf be cleared with kfree_sensitive() instead of kfree()?

This buffer holds the user's secret cryptographic randomness.

Freeing it without zeroization leaves sensitive secrets in the kernel heap,
where they might be exposed by a memory leak vulnerability.

> diff --git a/drivers/crypto/cmh/cmh_pke_sm2.c b/drivers/crypto/cmh/cmh_pke_sm2.c
> new file mode 100644
> index 0000000000000..9daeaaa948281
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_pke_sm2.c

[ ... ]

> @@ -622,6 +622,10 @@ int cmh_mgmt_sm2_ecdh_hash(void __user *argp)
>  	/* Phase 2: read shared key from DS -> DMA */
>  	vcq_set_header(&vcq[0], 3);
>  	vcq_add_sys_data(&vcq[1], *ref_buf, sk_dma, SM2_SHARED_KEY_LEN);
>  	vcq_add_sys_flush(&vcq[2]);

[Severity: High]
Does this missing PKE_SWAP_FLAGS cause cryptographic corruption?

In Phase 1 and in SM2_ECDH, the command is OR'd with PKE_SWAP_FLAGS to
reverse the byte order.

Since vcq[1].id is not modified here, will the shared key be returned to
userspace in the internal big-endian format rather than the host's format?

[ ... ]

> @@ -651,6 +655,8 @@ int cmh_mgmt_sm2_ecdh_hash(void __user *argp)
>  out_unmap:
>  	if (!cmh_dma_map_error(ref_dma))
>  		cmh_dma_unmap_single(ref_dma, sizeof(u64), DMA_FROM_DEVICE);

[Severity: High]
Is it possible that the persistent datastore object referenced by *ref_buf
is permanently leaked here?

The *ref_buf object created by SYS_CMD_NEW is never scrubbed on the success
path or the error path.

Could repeated calls to this ioctl exhaust the finite datastore capacity
and brick the hardware until a reset?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260825221539.255951-1-aousherovitch@rambus.com?part=3

  reply	other threads:[~2026-08-25 22:30 UTC|newest]

Thread overview: 37+ 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-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 [this message]
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
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=20260825223010.9986B1F00A3A@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