staging: nvec: fix race between power-off callback and driver removal
Subsystems (3)
PATCH 1/1 staging: nvec: fix race between power-off callback and driver removal
tegra_nvec_remove() checks pm_power_off against nvec_power_off and then clears it in two separate steps:
if (pm_power_off == nvec_power_off) pm_power_off = NULL;
If a shutdown is triggered between the check and the clear, the system's power-off path can call nvec_power_off() while tegra_nvec_remove() is concurrently tearing down the device (freeing resources via mfd_remove_devices(), cancel_work_sync(), etc.), leading to a use-after-free on nvec_power_handle.
Use cmpxchg() to make the check-and-clear atomic, closing this race window.
Compile-tested (ARM, tegra_defconfig) only; I don't have access to Tegra Paz00 hardware to test this at runtime.
--- drivers/staging/nvec/nvec.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/nvec/nvec.c +1 -2
@@ -906,8 +906,7 @@ static void tegra_nvec_remove(struct platform_device *pdev)nvec_unregister_notifier (nvec, &nvec->nvec_status_notifier);cancel_work_sync (&nvec->rx_work);cancel_work_sync (&nvec->tx_work); -if (pm_power_off == nvec_power_off) - pm_power_off =NULL ; +cmpxchg (&pm_power_off, nvec_power_off,NULL ); }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 12 lines · Hank Yang
tegra_nvec_remove()checkspm_power_offagainstnvec_power_offand then clears it in two separate steps:if (pm_power_off == nvec_power_off) pm_power_off = NULL;If a shutdown is triggered between the check and the clear, the system's power-off path can call
nvec_power_off()whiletegra_nvec_remove()is concurrently tearing down the device (freeing resources viamfd_remove_devices(),cancel_work_sync(), etc.), leading to a use-after-free onnvec_power_handle.
Quoted 7 lines
Use
cmpxchg()to make the check-and-clear atomic, closing this race window.Compile-tested (ARM,
tegra_defconfig) only; I don't have access to Tegra Paz00 hardware to test this at runtime.Assisted-by Claude:claude-sonnet-5
Please read:
https://lore.kernel.org/r/2026080354-skater-urgent-31b2@gregkh
sorry,
greg k-h