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 08/19] crypto: cmh - add AES skcipher/aead/cmac
Date: Tue, 25 Aug 2026 22:28:46 +0000 [thread overview]
Message-ID: <20260825222847.338B31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825221539.255951-9-aousherovitch@rambus.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Aborted or re-initialized `cmac(aes)` ahash requests leak accumulated dynamically allocated chunks until TFM destruction, allowing trivial kernel memory exhaustion (OOM).
- [High] Incorrect IV state update in `cmh_aes_update_iv` for AES-CFB mode with partial blocks breaks cipher chaining.
- [Medium] The skcipher driver attempts to kmalloc up to 32MB for input/output buffers, deterministically failing for valid large requests.
--
commit 0ec57ce28ce08fa19d032fb79fd5650db5f53a75
Author: Alex Ousherovitch <aousherovitch@rambus.com>
Subject: crypto: cmh - add AES skcipher/aead/cmac
This commit registers AES algorithms using the CMH AES core for skcipher,
aead, and ahash interfaces. It handles key management, context setup, and
VCQ command sequencing for encryption and authentication.
> diff --git a/drivers/crypto/cmh/cmh_aes.c b/drivers/crypto/cmh/cmh_aes.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_aes.c
[ ... ]
> +static void cmh_aes_update_iv(struct skcipher_request *req, u32 mode,
> + u32 op, const u8 *in_buf, const u8 *out_buf)
> +{
> + u32 bs = CMH_AES_BLOCK_SIZE;
> + u32 nblocks;
> +
> + switch (mode) {
[ ... ]
> + case AES_MODE_CFB:
> + /*
> + * CFB-128 chains on the last ciphertext block. On encrypt,
> + * that is out_buf; on decrypt, it is in_buf.
> + *
> + * For sub-block requests (cryptlen < 16), there is no
> + * complete ciphertext block to chain, so the IV is left
> + * unchanged -- CFB-128 has no defined chaining semantic
> + * for partial blocks (shift-register CFB-n is a different
> + * mode). Without this guard the pointer arithmetic
> + * underflows and reads before the buffer.
> + */
> + if (req->cryptlen >= bs) {
> + if (op == AES_OP_ENCRYPT)
> + memcpy(req->iv, out_buf + req->cryptlen - bs,
> + bs);
> + else
> + memcpy(req->iv, in_buf + req->cryptlen - bs,
> + bs);
> + }
> + break;
[Severity: High]
When dealing with partial blocks in CFB mode where req->cryptlen is not a
multiple of the block size, will the offset calculation (req->cryptlen - bs)
point to an unaligned offset rather than the last full block boundary? The
next operation in a chained CFB stream requires the last full ciphertext
block for the chaining IV, so could this break the cipher chaining by
copying the wrong bytes?
[ ... ]
> +#define CMH_AES_MAX_CRYPTLEN SZ_32M
[ ... ]
> +static int cmh_aes_crypt(struct skcipher_request *req, u32 aes_op)
> +{
[ ... ]
> + if (req->cryptlen > CMH_AES_MAX_CRYPTLEN)
> + return -EINVAL;
[ ... ]
> + /*
> + * Linearise input from scatterlist. cryptlen is user-controlled up
> + * to CMH_AES_MAX_CRYPTLEN (well above KMALLOC_MAX_SIZE), so use
> + * __GFP_NOWARN: an oversized request fails cleanly with -ENOMEM
> + * instead of splatting the page allocator.
> + */
> + rctx->in_buf = kmalloc(req->cryptlen, gfp | __GFP_NOWARN);
> + if (!rctx->in_buf)
> + return -ENOMEM;
[Severity: Medium]
Does this driver attempt to allocate up to 32MB of physically contiguous
memory via kmalloc() for the input and output buffers? While the __GFP_NOWARN
flag ensures a clean failure, any valid request larger than KMALLOC_MAX_SIZE
(typically 4MB or 8MB) will deterministically fail with -ENOMEM. Would it be
better to cap the maximum length to KMALLOC_MAX_SIZE instead of 32MB, or
process the buffers in smaller chunks?
> diff --git a/drivers/crypto/cmh/cmh_aes_cmac.c b/drivers/crypto/cmh/cmh_aes_cmac.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_aes_cmac.c
[ ... ]
> +static int cmh_aes_cmac_init(struct ahash_request *req)
> +{
> + struct cmh_aes_cmac_reqctx *rctx = ahash_request_ctx(req);
> +
> + memset(rctx, 0, sizeof(*rctx));
> + INIT_LIST_HEAD(&rctx->chunks);
> + return 0;
> +}
[Severity: High]
If a user opens an AF_ALG socket, accumulates data by calling
crypto_ahash_update(), and then calls crypto_ahash_init() to reset the hash
state, won't this memset() clear the rctx->chunks list head and leak the
dynamically allocated chunks? The orphaned chunks would remain on
tctx->all_chunks indefinitely until the long-lived TFM is destroyed, which
could allow unprivileged userspace to easily exhaust kernel memory.
[ ... ]
> +static int cmh_aes_cmac_import(struct ahash_request *req, const void *in)
> +{
> + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> + struct cmh_aes_cmac_tfm_ctx *tctx = crypto_ahash_ctx(tfm);
> + struct cmh_aes_cmac_reqctx *rctx = ahash_request_ctx(req);
> + const struct cmh_aes_cmac_export_state *state = in;
> + struct cmh_aes_cmac_chunk *chunk;
> +
> + /*
> + * Do NOT call free_chunks() here: the crypto API does not
> + * guarantee the request context is in a valid state before
> + * import(), so the list pointers may be stale or invalid.
> + * Re-initialize from scratch instead. Any pre-existing chunks
> + * are tracked on tctx->all_chunks and freed in exit_tfm.
> + */
> + memset(rctx, 0, sizeof(*rctx));
> + INIT_LIST_HEAD(&rctx->chunks);
[Severity: High]
Similarly, if a caller performs a state import over a request that has
already accumulated data in its own chunk list, doesn't this memset() also
strand any previously allocated chunks?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260825221539.255951-1-aousherovitch@rambus.com?part=8
next prev parent reply other threads:[~2026-08-25 22:28 UTC|newest]
Thread overview: 65+ 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 ` Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 01/19] dt-bindings: crypto: add Rambus CryptoManager Hub Alex Ousherovitch
2026-08-25 22:15 ` Alex Ousherovitch
2026-08-25 22:28 ` sashiko-bot
2026-08-26 17:02 ` Conor Dooley
2026-08-26 17:02 ` Conor Dooley
2026-08-27 1:39 ` Ousherovitch, Alex
2026-08-27 1:39 ` Ousherovitch, Alex
2026-08-27 17:14 ` Conor Dooley
2026-08-27 17:14 ` Conor Dooley
2026-08-27 18:21 ` Ousherovitch, Alex
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:15 ` Alex Ousherovitch
2026-08-25 22:27 ` sashiko-bot
2026-09-11 4:31 ` Herbert Xu
2026-09-11 4:31 ` Herbert Xu
2026-09-11 21:29 ` Ousherovitch, Alex
2026-09-11 21:29 ` Ousherovitch, Alex
2026-08-25 22:15 ` [PATCH v4 05/19] crypto: cmh - add HMAC ahash Alex Ousherovitch
2026-08-25 22:15 ` 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:15 ` 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:15 ` 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:15 ` Alex Ousherovitch
2026-08-25 22:28 ` sashiko-bot [this message]
2026-08-25 22:15 ` [PATCH v4 09/19] crypto: cmh - add SM4 skcipher/aead/cmac/xcbc Alex Ousherovitch
2026-08-25 22:15 ` 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:15 ` 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:15 ` 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 ` Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 13/19] crypto: cmh - add ECDSA/SM2 sig Alex Ousherovitch
2026-08-25 22:15 ` Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 14/19] crypto: cmh - add ECDH/X25519 kpp Alex Ousherovitch
2026-08-25 22:15 ` 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:15 ` 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:15 ` 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:15 ` 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 ` Alex Ousherovitch
2026-08-25 22:15 ` [PATCH v4 19/19] MAINTAINERS: add Rambus CryptoManager Hub (CMH) Alex Ousherovitch
2026-08-25 22:15 ` 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=20260825222847.338B31F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.