mfd: si476x-i2c: cancel RDS drainer work before freeing RDS FIFO
PATCH 1/1 mfd: si476x-i2c: cancel RDS drainer work before freeing RDS FIFO
From: Hyunjung Ko <[email protected]>
The RDS FIFO drainer work (core->rds_fifo_drainer) is scheduled from the interrupt dispatcher si476x_core_get_and_signal_status() whenever an SI476X_FM_RDS_INT interrupt is seen:
if (status & SI476X_FM_RDS_INT) si476x_core_start_rds_drainer_once(core);
si476x_core_start_rds_drainer_once() runs the work on the shared system workqueue via schedule_work(&core->rds_fifo_drainer). The work handler si476x_core_drain_rds_fifo() dereferences @core and reads from core->rds_fifo.
si476x_core_remove() does not cancel this work. It disables the interrupt (or, in polling mode, cancels only the sibling core->status_monitor delayed work) and then frees the RDS FIFO:
if (client->irq) disable_irq(client->irq); else cancel_delayed_work_sync(&core->status_monitor); kfifo_free(&core->rds_fifo);
disable_irq() waits for the interrupt handler to finish but does not flush or cancel work that the handler has already queued. A drainer work item that was scheduled just before (or is still running at) remove time can therefore run after kfifo_free() and after the devm-allocated @core itself is freed, dereferencing freed memory and operating on a freed kfifo (use-after-free). The sibling status_monitor work is drained on teardown but this one is not.
Drain the RDS drainer work before freeing the FIFO (and before the devm-managed @core is released) to close the window.
Found by code review; not runtime-reproduced (requires si476x AM/FM radio hardware and an RDS interrupt racing device removal).
--- drivers/mfd/si476x-i2c.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mfd/si476x-i2c.c +2 -0
@@ -831,6 +831,8 @@ static void si476x_core_remove(struct i2c_client *client)if (client->irq)disable_irq (client->irq);else cancel_delayed_work_sync (&core->status_monitor); +cancel_work_sync (&core->rds_fifo_drainer); +kfifo_free (&core->rds_fifo);
}
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] mfd: si476x-i2c: uncapitalized commit subject description after prefix --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] mfd: si476x-i2c: uncapitalized commit subject description after prefix --
commit 0681987cd726a1a3d6c3c547f0ac0af0aee3c7e7
Author: Hyunjung Ko <[email protected]>
mfd: si476x-i2c: cancel RDS drainer work before freeing RDS FIFO
This commit cancels core->rds_fifo_drainer synchronously in si476x_core_remove() before freeing core->rds_fifo to prevent a potential use-after-free when an SI476X_FM_RDS_INT interrupt schedules the drainer work shortly before device removal.
Quoted 33 lines
mfd: si476x-i2c: cancel RDS drainer work before freeing RDS FIFO
The RDS FIFO drainer work (
core->rds_fifo_drainer) is scheduled from the interrupt dispatchersi476x_core_get_and_signal_status()whenever anSI476X_FM_RDS_INTinterrupt is seen:if (status &
SI476X_FM_RDS_INT)
si476x_core_start_rds_drainer_once(core);
si476x_core_start_rds_drainer_once()runs the work on the shared system workqueue viaschedule_work(&core->rds_fifo_drainer). The work handlersi476x_core_drain_rds_fifo()dereferences @core and reads fromcore->rds_fifo.
si476x_core_remove()does not cancel this work. It disables the interrupt (or, in polling mode, cancels only the siblingcore->status_monitordelayed work) and then frees the RDS FIFO:if (
client->irq)
disable_irq(client->irq);
else
cancel_delayed_work_sync(&core->status_monitor);
kfifo_free(&core->rds_fifo);
disable_irq()waits for the interrupt handler to finish but does not flush or cancel work that the handler has already queued. A drainer work item that was scheduled just before (or is still running at) remove time can therefore run afterkfifo_free()and after the devm-allocated @core itself is freed, dereferencing freed memory and operating on a freed kfifo (use-after-free). The siblingstatus_monitorwork is drained on teardown but this one is not.
Quoted 7 lines
Drain the RDS drainer work before freeing the FIFO (and before the devm-managed @core is released) to close the window.
Found by code review; not runtime-reproduced (requires si476x AM/FM radio hardware and an RDS interrupt racing device removal).
Signed-off-by Hyunjung Ko <[email protected]>
[Severity: Low]
This isn't a bug in si476x_core_remove() in drivers/mfd/si476x-i2c.c, but the mfd subsystem convention is to capitalize the commit description after the driver prefix. Could the subject line be updated to:
mfd: si476x-i2c: Cancel RDS drainer work before freeing RDS FIFO
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: (subset) [PATCH] mfd: si476x-i2c: cancel RDS drainer work before freeing RDS FIFO
In reply to hyunjunggQuoted 8 lines · hyunjungg
The RDS FIFO drainer work (
core->rds_fifo_drainer) is scheduled from the interrupt dispatchersi476x_core_get_and_signal_status()whenever anSI476X_FM_RDS_INTinterrupt is seen:if (status & SI476X_FM_RDS_INT) si476x_core_start_rds_drainer_once(core);[...]
Applied, thanks!
[1/1] mfd: si476x-i2c: cancel RDS drainer work before freeing RDS FIFO
commit: f06fa446a04cbb3b7600d4566f774e268ecdde20
--
Lee Jones [李琼斯]