[PATCH v10 01/11] spmi: Fix potential use-after-free by grabbing of_node reference
Andy Shevchenko
andriy.shevchenko at intel.com
Tue Jul 7 02:07:00 PDT 2026
On Tue, Jul 07, 2026 at 10:37:20AM +0200, AngeloGioacchino Del Regno wrote:
> As noticed by Sashiko during a review run of an unrelated patch,
> in of_spmi_register_devices(), for_each_available_child_of_node()
> is used to loop through children, and to also assign a node to a
> newly created SPMI child device.
>
> Problem is that the refcount is dropped at every iteration so, in
> the specific case of DT overlays, a use-after-free may occur when
> an overlay is dynamically unloaded!
>
> To resolve this, increase the of_node refcount when assigning (in
> function of_spmi_register_devices) and release the reference in
> spmi_device_remove().
...
> void spmi_device_remove(struct spmi_device *sdev)
> {
> + if (IS_ENABLED(CONFIG_OF))
Unneeded check.
> + of_node_put(sdev->dev.of_node);
> +
> device_unregister(&sdev->dev);
> }
--
With Best Regards,
Andy Shevchenko
More information about the linux-phy
mailing list