From: Herbert Xu <herbert@gondor.apana.org.au>
To: T Pratham <t-pratham@ti.com>
Cc: "David S. Miller" <davem@davemloft.net>,
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, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal
Date: Thu, 8 Oct 2026 16:07:39 +1100 [thread overview]
Message-ID: <asclG7JDJ4SYHZiy@gondor.apana.org.au> (raw)
In-Reply-To: <20260930112533.1593952-5-t-pratham@ti.com>
On Wed, Sep 30, 2026 at 04:55:22PM +0530, T Pratham wrote:
>
> +struct dthe_data *dthe_get_drvdata(struct device *dev)
> +{
> + struct dthe_data *dev_data;
> +
> + spin_lock_bh(&dthe_dev_list.lock);
> + dev_data = dev_get_drvdata(dev);
> + if (dev_data && !atomic_fetch_inc(&dev_data->req_refcnt))
> + reinit_completion(&dev_data->drain_compl);
This is correct but rather baroque.
How about simplifying it by making the drvdata also hold a ref
count. That way the refcount will only hit zero during the removal
process. So you don't have to keep reinitialising the completion
object over and over again.
Also refcnt should use kref_t which is easier to use than atomic_t.
+struct dthe_data *dthe_get_drvdata(struct device *dev)
+{
+ struct dthe_data *dev_data;
+
+ spin_lock_bh(&dthe_dev_list.lock);
+ dev_data = dev_get_drvdata(dev);
+ if (dev_data)
+ kref_get(&dev_data->req_refcnt);
spin_unlock_bh(&dthe_dev_list.lock);
return dev_data;
}
+void dthe_release_drvdata(struct kref *kref)
+{
+ struct dthe_data dev_data = container_of(kref, struct dthe_data, req_refcnt);
+
+ complete(&dev_data->drain_compl);
+}
+
+void dthe_put_drvdata(struct dthe_data *dev_data)
+{
+ kref_put(&dev_data->req_refcnt, dthe_release_drvdata);
+ complete(&dev_data->drain_compl);
+}
+
> @@ -152,6 +176,10 @@ static int dthe_probe(struct platform_device *pdev)
> if (IS_ERR(dev_data->regs))
> return PTR_ERR(dev_data->regs);
>
> + atomic_set(&dev_data->req_refcnt, 0);
Use kref_init so that drvdata holds a refcount too.
> + init_completion(&dev_data->drain_compl);
> + complete(&dev_data->drain_compl);
You can then drop the complete call as the last kref_put will
automatically complete the object.
> @@ -202,10 +230,13 @@ static void dthe_remove(struct platform_device *pdev)
>
> spin_lock_bh(&dthe_dev_list.lock);
> list_del(&dev_data->list);
> + platform_set_drvdata(pdev, NULL);
> spin_unlock_bh(&dthe_dev_list.lock);
>
> dthe_unregister_algs();
Just add this here:
+ dthe_put_drvdata(dev_data);
> + wait_for_completion(&dev_data->drain_compl);
Thanks,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
next prev parent reply other threads:[~2026-10-08 5:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 11:25 [PATCH v6 00/15] Fix several issues in DTHEv2 driver T Pratham
2026-09-30 11:25 ` [PATCH v6 01/15] crypto: ti - Use list_first_entry_or_null() in dthe_get_dev() T Pratham
2026-09-30 11:25 ` [PATCH v6 02/15] crypto: ti - Fix spinlock inconsistency in DTHEv2 T Pratham
2026-09-30 11:25 ` [PATCH v6 03/15] crypto: ti - Fix potential memory corruption on highmem pages T Pratham
2026-09-30 11:25 ` [PATCH v6 04/15] crypto: ti - Fix use-after-free of dev_data on DTHEv2 driver removal T Pratham
2026-10-08 5:07 ` Herbert Xu [this message]
2026-09-30 11:25 ` [PATCH v6 05/15] crypto: ti - Trim scatterlists to correct length in AES T Pratham
2026-09-30 11:25 ` [PATCH v6 06/15] crypto: ti - Align buffers to cacheline for DMA T Pratham
2026-09-30 11:25 ` [PATCH v6 07/15] crypto: ti - Separate padding buffer for src and dst T Pratham
2026-09-30 11:25 ` [PATCH v6 08/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AES T Pratham
2026-09-30 11:25 ` [PATCH v6 09/15] crypto: ti - Validate sg_nents_for_len() return value in DTHEv2 AEAD T Pratham
2026-09-30 11:25 ` [PATCH v6 10/15] crypto: ti - Terminate DMA on all error paths in AES to clear descriptors T Pratham
2026-09-30 11:25 ` [PATCH v6 11/15] crypto: ti - Terminate DMA on all error paths in AEAD " T Pratham
2026-09-30 11:25 ` [PATCH v6 12/15] crypto: ti - Do AEAD software fallback on only ENOMEM T Pratham
2026-09-30 11:25 ` [PATCH v6 13/15] crypto: ti - Correct AEAD tag operations against dma cache invalidation T Pratham
2026-09-30 11:25 ` [PATCH v6 14/15] crypto: ti - Change lengths in AES to u64 to avoid potential overflows T Pratham
2026-09-30 11:25 ` [PATCH v6 15/15] crypto: ti - Change lengths in AEAD " T Pratham
2026-09-30 13:03 ` [PATCH v6 00/15] Fix several issues in DTHEv2 driver 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=asclG7JDJ4SYHZiy@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=davem@davemloft.net \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m-chawdhry@ti.com \
--cc=praneeth@ti.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®