All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "T Pratham" <t-pratham@ti.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: "Sebin Francis" <sebin.francis@ti.com>,
	"Manorit Chawdhry" <m-chawdhry@ti.com>,
	"Praneeth Bajjuri" <praneeth@ti.com>,
	"Vishal Mahaveer" <vishalm@ti.com>,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v12 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal
Date: Sat, 07 Nov 2026 16:20:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-203049@kernel.org> (raw)
In-Reply-To: <20261107160631.2592763-5-t-pratham@ti.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] crypto: ti - missing dev_data refcnt drain on dthe_probe()
  error path
--

commit 671be96b9ffa7abb434446440cf647e7e1f76348
Author: T Pratham <t-pratham@ti.com>

crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal

This commit moves the dthe_data pointer from the transform context to the
request context, binds transforms to a reference-counted struct device,
and adds a kref and completion to struct dthe_data so dthe_remove() waits
for in-flight requests to drain before tearing down the device.

> diff --git a/drivers/crypto/ti/dthev2-common.c b/drivers/crypto/ti/dthev2-common.c
> index 911e6bbe4d241..cd4626ed4c39a 100644
> --- a/drivers/crypto/ti/dthev2-common.c
> +++ b/drivers/crypto/ti/dthev2-common.c

[ ... ]

> @@ -184,6 +219,7 @@ static int dthe_probe(struct platform_device *pdev)
>  probe_register_algs_err:
>  	spin_lock_bh(&dthe_dev_list.lock);
>  	list_del(&dev_data->list);
> +	platform_set_drvdata(pdev, NULL);
>  	spin_unlock_bh(&dthe_dev_list.lock);
>  probe_engine_start_err:
>  	crypto_engine_exit(dev_data->engine);

[Severity: Medium]
Does the probe_register_algs_err rollback path also need to drop the
initial reference and wait for drain_compl like dthe_remove() does?

dthe_probe() publishes dev_data in drvdata and dthe_dev_list before calling
dthe_register_algs(), which registers skcipher algorithms first and AEAD
algorithms second:

drivers/crypto/ti/dthev2-aes.c:dthe_register_aes_algs() {
	ret = crypto_engine_register_skciphers(cipher_algs, ARRAY_SIZE(cipher_algs));
	if (ret)
		return ret;
	ret = crypto_engine_register_aeads(aead_algs, ARRAY_SIZE(aead_algs));
	if (ret)
		crypto_engine_unregister_skciphers(cipher_algs, ARRAY_SIZE(cipher_algs));

	return ret;
}

If registering one of the later algorithms fails after an earlier algorithm
has already been picked up by cryptomgr_test or another user, a request can
remain in flight after crypto_engine_unregister_skciphers() returns:

CPU0                              CPU1
dthe_probe()
  platform_set_drvdata(pdev, dev_data)
  list_add(&dev_data->list, ...)
  dthe_register_algs()
    crypto_engine_register_skciphers()
                                  dthe_cipher_init_tfm()
                                    ctx->dev = dthe_get_dev()
                                  dthe_aes_crypt()
                                    dev_data = dthe_get_drvdata(ctx->dev)
    crypto_engine_register_aeads() -> fails
    crypto_engine_unregister_skciphers()
  list_del(&dev_data->list)
  platform_set_drvdata(pdev, NULL)
  crypto_engine_exit(dev_data->engine)
  return ret; (frees devm dev_data)
                                    crypto_transfer_skcipher_request_to_engine()
                                    dthe_put_drvdata(dev_data)
                                      <-- use-after-free

Calling dthe_put_drvdata(dev_data) and
wait_for_completion(&dev_data->drain_compl) before probe_engine_start_err
would wait for any in-flight requests to finish before tearing down the
engine and freeing dev_data.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261107160631.2592763-1-t-pratham@ti.com?part=4

  reply	other threads:[~2026-11-07 16:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07 16:06 [PATCH v12 00/15] Fix several issues in DTHEv2 driver T Pratham
2026-11-07 16:06 ` [PATCH v12 01/15] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() T Pratham
2026-11-07 16:06 ` [PATCH v12 02/15] crypto: ti - Fix spinlock inconsistency in DTHEv2 T Pratham
2026-11-07 16:06 ` [PATCH v12 03/15] crypto: ti - Fix potential memory corruption on highmem pages T Pratham
2026-11-07 16:06 ` [PATCH v12 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal T Pratham
2026-11-07 16:20   ` sashiko-bot [this message]
2026-11-07 16:06 ` [PATCH v12 05/15] crypto: ti - Trim scatterlists to correct length in AES T Pratham
2026-11-07 16:06 ` [PATCH v12 06/15] crypto: ti - Align buffers to cacheline for DMA T Pratham
2026-11-07 16:06 ` [PATCH v12 07/15] crypto: ti - Separate padding buffer for src and dst T Pratham
2026-11-07 16:06 ` [PATCH v12 08/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AES T Pratham
2026-11-07 16:06 ` [PATCH v12 09/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AEAD T Pratham
2026-11-07 16:06 ` [PATCH v12 10/15] crypto: ti - Terminate DMA on all error paths in AES to clear descriptors T Pratham
2026-11-07 16:06 ` [PATCH v12 11/15] crypto: ti - Terminate DMA on all error paths in AEAD " T Pratham
2026-11-07 16:06 ` [PATCH v12 12/15] crypto: ti - Do AEAD software fallback on only ENOMEM T Pratham
2026-11-07 16:06 ` [PATCH v12 13/15] crypto: ti - Correct AEAD tag operations against dma cache invalidation T Pratham
2026-11-07 16:06 ` [PATCH v12 14/15] crypto: ti - Change lengths in AES to u64 to avoid potential overflows T Pratham
2026-11-07 16:06 ` [PATCH v12 15/15] crypto: ti - Change lengths in AEAD " T Pratham

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=sashiko-outbox-203049@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=m-chawdhry@ti.com \
    --cc=praneeth@ti.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebin.francis@ti.com \
    --cc=t-pratham@ti.com \
    --cc=vishalm@ti.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 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.