regulator: disable disable_work for good in regulator_unregister()
Subsystems (2)
PATCH v2 1/1 regulator: disable disable_work for good in regulator_unregister()
regulator_unregister() stops rdev->disable_work with flush_work(&dw->work), which is a no-op for a delayed_work pending on the timer wheel: flush_work() only waits for a queued or running work item. A disable deferred by a consumer's regulator_disable_deferred() therefore survives the provider's unbind, and regulator_disable_work() fires after device_unregister() has freed the rdev, dereferencing it via container_of(). Use-after-free.
The in-tree users are ASoC DAPM regulator widgets with a 20 ms power-down delay (sound/soc/soc-dapm.c): the window is the entire deferral period, not a race between adjacent instructions.
Use disable_delayed_work_sync(): it dequeues a timer-pending instance and waits for a running callback, and keeps the work disabled so a concurrent regulator_disable_deferred() cannot re-arm it while the teardown proceeds.
Found by static analysis.
---
v2: switch to disable_delayed_work_sync() (Mark Brown): also keeps the
work disabled so nothing can re-arm it past the teardown.
v1: https://lore.kernel.org/r/[email protected]
drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/core.c +1 -1
@@ -6300,7 +6300,7 @@ void regulator_unregister(struct regulator_dev *rdev)regulator_put (rdev->supply); } -flush_work (&rdev->disable_work.work); +disable_delayed_work_sync (&rdev->disable_work);mutex_lock (®ulator_list_mutex);
Signature · 1 line
2.25.1