Skip to content
/ linux Public

Commit f50433f

Browse files
whameSasha Levin
authored andcommitted
power: supply: ab8500: Fix use-after-free in power_supply_changed()
[ Upstream commit c4af8a9 ] Using the `devm_` variant for requesting IRQ _before_ the `devm_` variant for allocating/registering the `power_supply` handle, means that the `power_supply` handle will be deallocated/unregistered _before_ the interrupt handler (since `devm_` naturally deallocates in reverse allocation order). This means that during removal, there is a race condition where an interrupt can fire just _after_ the `power_supply` handle has been freed, *but* just _before_ the corresponding unregistration of the IRQ handler has run. This will lead to the IRQ handler calling `power_supply_changed()` with a freed `power_supply` handle. Which usually crashes the system or otherwise silently corrupts the memory... Note that there is a similar situation which can also happen during `probe()`; the possibility of an interrupt firing _before_ registering the `power_supply` handle. This would then lead to the nasty situation of using the `power_supply` handle *uninitialized* in `power_supply_changed()`. Commit 1c1f13a ("power: supply: ab8500: Move to componentized binding") introduced this issue during a refactorization. Fix this racy use-after-free by making sure the IRQ is requested _after_ the registration of the `power_supply` handle. Fixes: 1c1f13a ("power: supply: ab8500: Move to componentized binding") Signed-off-by: Waqar Hameed <waqar.hameed@axis.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/ccf83a09942cb8dda3dff70b2682f2c2e9cb97f2.1766268280.git.waqar.hameed@axis.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2ad5078 commit f50433f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

drivers/power/supply/ab8500_charger.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3456,26 +3456,6 @@ static int ab8500_charger_probe(struct platform_device *pdev)
34563456
return ret;
34573457
}
34583458

3459-
/* Request interrupts */
3460-
for (i = 0; i < ARRAY_SIZE(ab8500_charger_irq); i++) {
3461-
irq = platform_get_irq_byname(pdev, ab8500_charger_irq[i].name);
3462-
if (irq < 0)
3463-
return irq;
3464-
3465-
ret = devm_request_threaded_irq(dev,
3466-
irq, NULL, ab8500_charger_irq[i].isr,
3467-
IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
3468-
ab8500_charger_irq[i].name, di);
3469-
3470-
if (ret != 0) {
3471-
dev_err(dev, "failed to request %s IRQ %d: %d\n"
3472-
, ab8500_charger_irq[i].name, irq, ret);
3473-
return ret;
3474-
}
3475-
dev_dbg(dev, "Requested %s IRQ %d: %d\n",
3476-
ab8500_charger_irq[i].name, irq, ret);
3477-
}
3478-
34793459
/* initialize lock */
34803460
spin_lock_init(&di->usb_state.usb_lock);
34813461
mutex_init(&di->usb_ipt_crnt_lock);
@@ -3604,6 +3584,26 @@ static int ab8500_charger_probe(struct platform_device *pdev)
36043584
return PTR_ERR(di->usb_chg.psy);
36053585
}
36063586

3587+
/* Request interrupts */
3588+
for (i = 0; i < ARRAY_SIZE(ab8500_charger_irq); i++) {
3589+
irq = platform_get_irq_byname(pdev, ab8500_charger_irq[i].name);
3590+
if (irq < 0)
3591+
return irq;
3592+
3593+
ret = devm_request_threaded_irq(dev,
3594+
irq, NULL, ab8500_charger_irq[i].isr,
3595+
IRQF_SHARED | IRQF_NO_SUSPEND | IRQF_ONESHOT,
3596+
ab8500_charger_irq[i].name, di);
3597+
3598+
if (ret != 0) {
3599+
dev_err(dev, "failed to request %s IRQ %d: %d\n"
3600+
, ab8500_charger_irq[i].name, irq, ret);
3601+
return ret;
3602+
}
3603+
dev_dbg(dev, "Requested %s IRQ %d: %d\n",
3604+
ab8500_charger_irq[i].name, irq, ret);
3605+
}
3606+
36073607
/*
36083608
* Check what battery we have, since we always have the USB
36093609
* psy, use that as a handle.

0 commit comments

Comments
 (0)