Skip to content

Commit 2306725

Browse files
whamesre
authored andcommitted
power: supply: pm8916_lbc: Fix use-after-free for extcon in IRQ handler
Using the `devm_` variant for requesting IRQ _before_ the `devm_` variant for allocating/registering the `extcon` handle, means that the `extcon` 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 `extcon` handle has been freed, *but* just _before_ the corresponding unregistration of the IRQ handler has run. This will lead to the IRQ handler calling `extcon_set_state_sync()` with a freed `extcon` handle. Which usually crashes the system or otherwise silently corrupts the memory... Fix this racy use-after-free by making sure the IRQ is requested _after_ the registration of the `extcon` handle. Fixes: f8d7a3d ("power: supply: Add driver for pm8916 lbc") Signed-off-by: Waqar Hameed <waqar.hameed@axis.com> Reviewed-by: Nikita Travkin <nikita@trvn.ru> Link: https://patch.msgid.link/e2a4cd2fcd42b6cd97d856c17c097289a2aed393.1769163273.git.waqar.hameed@axis.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 562357a commit 2306725

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

drivers/power/supply/pm8916_lbc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,6 @@ static int pm8916_lbc_charger_probe(struct platform_device *pdev)
327327
if (irq < 0)
328328
return irq;
329329

330-
ret = devm_request_threaded_irq(dev, irq, NULL, pm8916_lbc_charger_state_changed_irq,
331-
IRQF_ONESHOT, "pm8916_lbc", chg);
332-
if (ret)
333-
return ret;
334-
335330
chg->edev = devm_extcon_dev_allocate(dev, pm8916_lbc_charger_cable);
336331
if (IS_ERR(chg->edev))
337332
return PTR_ERR(chg->edev);
@@ -340,6 +335,11 @@ static int pm8916_lbc_charger_probe(struct platform_device *pdev)
340335
if (ret < 0)
341336
return dev_err_probe(dev, ret, "failed to register extcon device\n");
342337

338+
ret = devm_request_threaded_irq(dev, irq, NULL, pm8916_lbc_charger_state_changed_irq,
339+
IRQF_ONESHOT, "pm8916_lbc", chg);
340+
if (ret)
341+
return ret;
342+
343343
ret = regmap_read(chg->regmap, chg->reg[LBC_USB] + PM8916_INT_RT_STS, &tmp);
344344
if (ret)
345345
goto comm_error;

0 commit comments

Comments
 (0)