From: sashiko-bot@kernel.org
To: "Alex Ousherovitch" <aousherovitch@rambus.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v4 05/19] crypto: cmh - add HMAC ahash
Date: Tue, 25 Aug 2026 22:30:09 +0000 [thread overview]
Message-ID: <20260825223009.D648F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825221539.255951-6-aousherovitch@rambus.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unbounded kernel memory leak via abandoned or re-initialized AF_ALG requests due to chunks orphaned in a shared TFM list.
--
commit bee5ec8c501d04b362a9a4720d98954a72b38c9e
Author: Alex Ousherovitch <aousherovitch@rambus.com>
crypto: cmh - add HMAC ahash
This commit registers HMAC ahash algorithms for the CMH hash core,
supporting HMAC-SHA-2 and HMAC-SHA-3. It implements a software
accumulation buffer to handle intermediate HMAC state.
> diff --git a/drivers/crypto/cmh/cmh_hmac.c b/drivers/crypto/cmh/cmh_hmac.c
> new file mode 100644
> index 0000000000000..528079f60bfa9
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_hmac.c
[ ... ]
> +static int cmh_hmac_init(struct ahash_request *req)
> +{
> + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
> + struct cmh_hmac_reqctx *rctx = ahash_request_ctx(req);
> +
> + rctx->info = cmh_hmac_get_info(tfm);
> + rctx->error = 0;
> + INIT_LIST_HEAD(&rctx->chunks);
[Severity: High]
If an active request is re-initialized by calling cmh_hmac_init(), does this
INIT_LIST_HEAD() blindly wipe the list head and permanently sever access to
previously accumulated chunks, leaving them stranded on the TFM list?
[ ... ]
> +static int cmh_hmac_update(struct ahash_request *req)
> +{
[ ... ]
> + chunk->len = req->nbytes;
> + if (req->base.flags & CRYPTO_AHASH_REQ_VIRT) {
> + memcpy(chunk->data, req->svirt, req->nbytes);
> + } else {
> + nents = sg_nents_for_len(req->src, req->nbytes);
> + if (nents < 0 ||
> + sg_copy_to_buffer(req->src, nents,
> + chunk->data, req->nbytes) != req->nbytes) {
> + kfree_sensitive(chunk);
> + rctx->error = -EINVAL;
> + goto err_free_chunks;
> + }
> + }
> +
> + list_add_tail(&chunk->list, &rctx->chunks);
> + spin_lock_bh(&tctx->chunk_lock);
> + list_add_tail(&chunk->tfm_node, &tctx->all_chunks);
> + spin_unlock_bh(&tctx->chunk_lock);
[Severity: High]
Since chunks are added to the per-transform list to survive request
destruction, doesn't this tie their lifecycle to the long-lived TFM?
Could this cause an unbounded kernel memory leak? An unprivileged local user
can create an AF_ALG socket, call accept() to create child sockets sharing
the same parent TFM, send data to allocate internal chunks here, and then
close the child socket. Since the crypto API lacks a per-request destructor
hook, the request context is freed without notifying the driver, leaving the
chunks orphaned on the TFM list.
[ ... ]
> +static int cmh_hmac_import(struct ahash_request *req, const void *in)
> +{
[ ... ]
> + /*
> + * 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 cra_exit.
> + */
> + rctx->info = cmh_hmac_get_info(tfm);
> + rctx->error = 0;
> + INIT_LIST_HEAD(&rctx->chunks);
[Severity: High]
Similar to cmh_hmac_init(), does importing over an active request orphan its
chunks? The comment acknowledges reliance on cmh_hmac_cra_exit() for cleanup,
which confirms the memory remains tied up for the lifetime of the TFM.
[ ... ]
> +static void cmh_hmac_cra_exit(struct crypto_tfm *tfm)
> +{
> + struct cmh_hmac_tfm_ctx *tctx = crypto_tfm_ctx(tfm);
> + struct cmh_hmac_chunk *chunk, *tmp;
> +
> + /* Free any orphaned chunks (e.g. testmgr export/reimport poison) */
> + spin_lock_bh(&tctx->chunk_lock);
> + list_for_each_entry_safe(chunk, tmp, &tctx->all_chunks, tfm_node) {
> + list_del(&chunk->tfm_node);
> + kfree_sensitive(chunk);
> + }
> + spin_unlock_bh(&tctx->chunk_lock);
[Severity: High]
Sweeping orphaned chunks only at TFM destruction causes unbounded
accumulation when many requests are created and destroyed over the lifetime
of a single TFM. Is there a way to manage chunk lifetimes without tying them
to the TFM?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260825221539.255951-1-aousherovitch@rambus.com?part=5
next prev parent reply other threads:[~2026-08-25 22:30 UTC|newest]
Thread overview: 39+ 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-27 17:14 ` Conor Dooley
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: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 [this message]
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=20260825223009.D648F1F000E9@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