Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: caam/jr: fix use-after-free in interrupt handler teardown
@ 2026-07-30 23:16 Rosen Penev
  2026-08-10  8:10 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-07-30 23:16 UTC (permalink / raw)
  To: linux-crypto
  Cc: Horia Geantă, Pankaj Gupta, Gaurav Jain, Herbert Xu,
	David S. Miller, open list

caam_jr_shutdown() currently calls tasklet_kill() without freeing the
IRQ first, creating a window where the interrupt handler can fire and
schedule the tasklet after it has been killed.  Move from
devm_request_irq() to request_irq()/free_irq() so that the IRQ is
explicitly freed in caam_jr_shutdown() before the tasklet is killed.

As part of this change, pass jrp directly as the dev_id cookie to
request_irq() instead of the device pointer.  This lets the interrupt
handler obtain jrp directly from the cookie, eliminating the
dev_get_drvdata() call in the hot path.

Two related fixes:
- Use jrp->dev instead of the now-undefined dev local in the handler's
  error path.
- Set jrpriv->dev before calling caam_jr_init() so that jrp->dev is
  valid before the IRQ is registered and the handler can run.

Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/crypto/caam/jr.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index bddeaaaca487..b577c6a2e4aa 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -173,6 +173,7 @@ static int caam_jr_shutdown(struct device *dev)
 
 	ret = caam_reset_hw_jr(dev);
 
+	free_irq(jrp->irq, jrp);
 	tasklet_kill(&jrp->irqtask);
 
 	return ret;
@@ -218,8 +219,7 @@ static void caam_jr_remove(struct platform_device *pdev)
 /* Main per-ring interrupt handler */
 static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
 {
-	struct device *dev = st_dev;
-	struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
+	struct caam_drv_private_jr *jrp = st_dev;
 	u32 irqstate;
 
 	/*
@@ -236,7 +236,7 @@ static irqreturn_t caam_jr_interrupt(int irq, void *st_dev)
 	 * restart the queue (and fix code).
 	 */
 	if (irqstate & JRINT_JR_ERROR) {
-		dev_err(dev, "job ring error: irqstate: %08x\n", irqstate);
+		dev_err(jrp->dev, "job ring error: irqstate: %08x\n", irqstate);
 		BUG();
 	}
 
@@ -563,8 +563,8 @@ static int caam_jr_init(struct device *dev)
 		     (unsigned long)&jrp->tasklet_params);
 
 	/* Connect job ring interrupt handler. */
-	error = devm_request_irq(dev, jrp->irq, caam_jr_interrupt, IRQF_SHARED,
-				 dev_name(dev), dev);
+	error = request_irq(jrp->irq, caam_jr_interrupt, IRQF_SHARED,
+				 dev_name(dev), jrp);
 	if (error) {
 		dev_err(dev, "can't connect JobR %d interrupt (%d)\n",
 			jrp->ridx, jrp->irq);
@@ -658,12 +658,12 @@ static int caam_jr_probe(struct platform_device *pdev)
 	if (error)
 		return error;
 
+	jrpriv->dev = jrdev;
+
 	/* Now do the platform independent part */
 	error = caam_jr_init(jrdev); /* now turn on hardware */
 	if (error)
 		return error;
-
-	jrpriv->dev = jrdev;
 	spin_lock(&driver_data.jr_alloc_lock);
 	list_add_tail(&jrpriv->list_node, &driver_data.jr_list);
 	spin_unlock(&driver_data.jr_alloc_lock);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: caam/jr: fix use-after-free in interrupt handler teardown
  2026-07-30 23:16 [PATCH] crypto: caam/jr: fix use-after-free in interrupt handler teardown Rosen Penev
@ 2026-08-10  8:10 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2026-08-10  8:10 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-crypto, Horia Geantă, Pankaj Gupta, Gaurav Jain,
	David S. Miller, open list

On Thu, Jul 30, 2026 at 04:16:03PM -0700, Rosen Penev wrote:
> caam_jr_shutdown() currently calls tasklet_kill() without freeing the
> IRQ first, creating a window where the interrupt handler can fire and
> schedule the tasklet after it has been killed.  Move from
> devm_request_irq() to request_irq()/free_irq() so that the IRQ is
> explicitly freed in caam_jr_shutdown() before the tasklet is killed.
> 
> As part of this change, pass jrp directly as the dev_id cookie to
> request_irq() instead of the device pointer.  This lets the interrupt
> handler obtain jrp directly from the cookie, eliminating the
> dev_get_drvdata() call in the hot path.
> 
> Two related fixes:
> - Use jrp->dev instead of the now-undefined dev local in the handler's
>   error path.
> - Set jrpriv->dev before calling caam_jr_init() so that jrp->dev is
>   valid before the IRQ is registered and the handler can run.
> 
> Assisted-by: opencode:big-pickle
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/crypto/caam/jr.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)

I think we should fix the general problem of hardware removal
in the middle of a crypto operation first before attempting these
fixes.

The driver needs to be modified so that it can fail gracefully
if the hardware is forcefully unbound while a crypto op is ongoing.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-10  8:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-30 23:16 [PATCH] crypto: caam/jr: fix use-after-free in interrupt handler teardown Rosen Penev
2026-08-10  8:10 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox