[4/7] media: sunxi-cir: Ensure no more interrupts can occur before free

Message ID e74a0caf91aaefaf98476a191e6489c606632bf1.1783673420.git.sean@mess.org (mailing list archive)
State New
Headers
Series None |

Commit Message

Sean Young July 10, 2026, 8:53 a.m. UTC
Only call rc_free_device() once the hardware has been stopped.

Fixes: dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq callbacks")
Signed-off-by: Sean Young <sean@mess.org>
---
 drivers/media/rc/sunxi-cir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

sashiko-bot@kernel.org July 10, 2026, 9:03 a.m. UTC | #1
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fails to fix the IRQ Use-After-Free race condition and exacerbates a bus fault vulnerability by disabling hardware clocks without synchronizing the devm-managed interrupt.
- [High] The interrupt is requested before the hardware is initialized in the probe function, leading to a possible bus fault on spurious interrupts and a Use-After-Free in the error path.
--

--- Patch [4]: [PATCH 4/7] media: sunxi-cir: Ensure no more interrupts can occur before free ---
commit 8ac4bdb72847c70ea6f26a6012ec7552bc70de07
Author: Sean Young <sean@mess.org>

media: sunxi-cir: Ensure no more interrupts can occur before free

This commit reorders the device removal sequence to call rc_free_device()
only after the hardware has been stopped via sunxi_ir_hw_exit(). The stated
intent is to prevent interrupts from occurring after the device is freed.

> diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
> index 28e840a7e5b8c..af1ee08ffdbec 100644
> --- a/drivers/media/rc/sunxi-cir.c
> +++ b/drivers/media/rc/sunxi-cir.c
> @@ -374,8 +374,8 @@ static void sunxi_ir_remove(struct platform_device *pdev)
>  	struct sunxi_ir *ir = platform_get_drvdata(pdev);
>  
>  	rc_unregister_device(ir->rc);
> -	rc_free_device(ir->rc);
>  	sunxi_ir_hw_exit(&pdev->dev);
> +	rc_free_device(ir->rc);

[Severity: High]
This is a pre-existing issue, but does this sequence completely prevent
interrupts from occurring before the free?

Because the interrupt is managed by devm_request_irq(), it remains active
until devres cleanup runs after sunxi_ir_remove() completes. Since
sunxi_ir_hw_exit() only disables clocks, if a pending or spurious interrupt
fires afterward, sunxi_ir_irq() will access unclocked memory-mapped registers
and trigger a bus fault.

Additionally, if the interrupt handler runs concurrently on another processor:

sunxi_ir_irq()
    ir_raw_event_overflow(ir->rc);

could it access ir->rc after it is freed by rc_free_device() here, since
there is no synchronize_irq() or disable_irq() in sunxi_ir_remove()?

[Severity: High]
This is also a pre-existing issue, but does sunxi_ir_probe() suffer from a
similar race condition?

In sunxi_ir_probe(), devm_request_irq() is called to unmask the interrupt
before sunxi_ir_hw_init() enables the clock. If a pending interrupt from
a previous boot or a spurious interrupt fires during this window,
sunxi_ir_irq() will execute before the clock is enabled, potentially causing
a bus fault.

Also, if sunxi_ir_hw_init() fails, the error path eventually calls
rc_free_device() without explicitly disabling the active interrupt, which
leaves a window for a use-after-free on ir->rc.

>  }
  

Patch

diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 28e840a7e5b8..af1ee08ffdbe 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -374,8 +374,8 @@  static void sunxi_ir_remove(struct platform_device *pdev)
 	struct sunxi_ir *ir = platform_get_drvdata(pdev);
 
 	rc_unregister_device(ir->rc);
-	rc_free_device(ir->rc);
 	sunxi_ir_hw_exit(&pdev->dev);
+	rc_free_device(ir->rc);
 }
 
 static void sunxi_ir_shutdown(struct platform_device *pdev)