rtc: msc313: fix NULL deref in shared IRQ handler at probe
Subsystems (2)
PATCH 1/1 rtc: msc313: fix NULL deref in shared IRQ handler at probe
msc313_rtc_probe() calls devm_request_irq() with IRQF_SHARED and &pdev->dev as the cookie, but platform_set_drvdata() is only called later after the clock setup. With a shared IRQ line, another device on the same line can trigger the handler in that window. The handler does dev_get_drvdata() on the cookie, gets NULL, and dereferences priv->rtc_base in interrupt context.
Pass priv as the cookie directly so the handler reads it from dev_id without the lookup, removing the dependency on probe order.
--- drivers/rtc/rtc-msc313.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/rtc/rtc-msc313.c +2 -2
@@ -160,7 +160,7 @@ static const struct rtc_class_ops msc313_rtc_ops = {static irqreturn_t msc313_rtc_interrupt (s32 irq,void *dev_id) { -struct msc313_rtc *priv =dev_get_drvdata (dev_id); +struct msc313_rtc *priv = dev_id;u16 reg; reg =readw (priv->rtc_base +REG_RTC_STATUS_INT );
@@ -206,7 +206,7 @@ static int msc313_rtc_probe(struct platform_device *pdev) priv->rtc_dev->range_max =U32_MAX ; ret =devm_request_irq (dev, irq, msc313_rtc_interrupt,IRQF_SHARED , -dev_name (&pdev->dev), &pdev->dev); +dev_name (&pdev->dev), priv);if (ret) {dev_err (dev,"Could not request IRQ\n" );return ret;
Signature · 1 line
2.43.0
Quoted 8 lines · Stepan Ionichev
msc313_rtc_probe()callsdevm_request_irq()withIRQF_SHAREDand&pdev->devas the cookie, butplatform_set_drvdata()is only called later after the clock setup. With a shared IRQ line, another device on the same line can trigger the handler in that window. The handler doesdev_get_drvdata()on the cookie, gets NULL, and dereferencespriv->rtc_basein interrupt context.[...]
Applied, thanks!
[1/1] rtc: msc313: fix NULL deref in shared IRQ handler at probe
https://git.kernel.org/abelloni/c/a369f48be8de
Best regards,
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com