[PATCH net v2 0/2] net: pse-pd: fix use-after-free of PI array on controller unregister
From: Carlo Szelinsky <hidden>
Date: 2026-07-11 12:25:42
Also in:
lkml
This series fixes use-after-free bugs in the PSE core teardown path. When a PSE controller is unregistered, pse_controller_unregister() frees the PI array (pcdev->pi) and the power domain supplies. But the IRQ handler, the notification worker, and the regulator disable path can still run at that point and touch this freed memory. Patch 1 reorders pse_controller_unregister() so the IRQ and the worker are stopped before anything they use is freed. Patch 2 clears pcdev->pi under the lock after freeing it, and makes the three regulator ops that read pcdev->pi return early when it is NULL. This series closes the use-after-free reachable from the regulator core and the controller's own IRQ and worker during unregister. The wider case - a pse_control consumer (the ethtool path) whose handle outlives the controller - is a separate lifetime problem handled by the PSE notifier decoupling work for net-next, not this fix. Both bugs are pre-existing. They are teardown races, so there is no easy way to trigger them on purpose and no simple reproducer. The fix is based on code review. It is compile tested and checkpatch clean. v1: https://lore.kernel.org/all/20260524223306.2570676-1-github@szelinsky.de/ (local) Changes in v2: - Patch 1: also stop the IRQ before pse_flush_pw_ds(), and cancel the notification worker before pse_release_pis(). v1 only moved disable_irq() ahead of pse_release_pis(). Also fix the commit message, which wrongly said the worker does not touch pcdev->pi. - Patch 2: take pcdev->lock around the kfree() and the pcdev->pi = NULL store, so a reader sees an authoritative NULL. Add the same NULL guard to pse_pi_enable() and pse_pi_is_enabled(), not just pse_pi_disable(). - Thanks to Simon Horman for the review. Carlo Szelinsky (2): net: pse-pd: stop async event sources before freeing PI data in unregister net: pse-pd: guard regulator ops against freed PI data during unregister drivers/net/pse-pd/pse_core.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) -- 2.43.0