Re: [PATCH v2 1/8] driver core: platform: fix swnode use-after-free on device release

From: Rafael J. Wysocki (Intel)

Date: Fri Nov 13 2026 - 12:42:09 EST


On Tue, Nov 10, 2026 at 9:52 AM Johan Hovold <johan@xxxxxxxxxx> wrote:
>
> When a device has a software node, device_remove_software_node() may
> drop the last reference and free it during platform_device_release().
> If the software node is the also the primary node then the device fwnode

s/is the also/is also/

> pointer is never cleared.
>
> Use a temporary variable to track whether the firmware node is a
> software node to avoid a use-after-free in is_software_node() and having
> fwnode_handle_put() call a function pointer via poisoned or reallocated
> memory when the primary node is a software node.
>
> This issue was flagged by Sashiko when reviewing a related fix.
>
> Fixes: 7d80509ff0da ("driver core: platform: unify release path")
> Closes: https://sashiko.dev/#/bug/linux-b860000b-f1d0-46a0-ab52-d47cec8eab99
> Cc: stable@xxxxxxxxxxxxxxx # 7.3
> Cc: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>
> Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>

I have not found any issues in it apart from the above, so

Reviewed-by: Rafael J. Wysocki (Intel) <rafael@xxxxxxxxxx>

> ---
> drivers/base/platform.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 979593e5cca1..be5d2f315fdb 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -598,13 +598,14 @@ static void platform_device_release(struct device *dev)
> {
> struct platform_object *pa = container_of(dev, struct platform_object,
> pdev.dev);
> + bool fwnode_is_software_node = is_software_node(dev_fwnode(dev));
>
> device_remove_software_node(dev);
> /*
> - * If the primary firmware node is a software node, its reference count
> - * was already decreased by the call to device_remove_software_node().
> + * If the firmware node is a software node, its reference count
> + * was decremented by device_remove_software_node().
> */
> - if (!is_software_node(dev_fwnode(dev)))
> + if (!fwnode_is_software_node)
> fwnode_handle_put(pa->pdev.dev.fwnode);
> kfree(pa->pdev.dev.platform_data);
> kfree(pa->pdev.mfd_cell);
> --
> 2.56.0
>