ACPI: power: Use put_device() in power resource add error path
Subsystems (2)
PATCH 1/1 ACPI: power: Use put_device() in power resource add error path
After device_initialize(), the lifetime of struct device is managed by the driver core through reference counting.
acpi_add_power_resource() initializes device->dev via acpi_init_device_object(), which installs acpi_release_power_resource() as the release callback. If acpi_device_add() fails, however, the error path calls acpi_release_power_resource() directly instead of dropping the device reference with put_device().
This bypasses the normal device lifetime rules and frees the object without releasing the reference acquired by device_initialize(), which may lead to a refcount leak and potentially a use-after-free. Fix it by calling put_device(&device->dev) and let the release callback handle the final cleanup.
--- drivers/acpi/power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/power.c +1 -1
@@ -991,7 +991,7 @@ struct acpi_device *acpi_add_power_resource(acpi_handle handle)return device; err: -acpi_release_power_resource (&device->dev); +put_device (&device->dev);return NULL ; }
Signature · 1 line
2.43.0
Rafael J. Wysocki
maintainerQuoted 28 lines · Guangshuo Li
After
device_initialize(), the lifetime of struct device is managed by the driver core through reference counting.
acpi_add_power_resource()initializesdevice->devviaacpi_init_device_object(), which installsacpi_release_power_resource()as the release callback. Ifacpi_device_add()fails, however, the error path callsacpi_release_power_resource()directly instead of dropping the device reference withput_device().This bypasses the normal device lifetime rules and frees the object without releasing the reference acquired by
device_initialize(), which may lead to a refcount leak and potentially a use-after-free. Fix it by callingput_device(&device->dev)and let the release callback handle the final cleanup.Fixes 781d737c7466 ("ACPI: Drop power resources driver")Signed-off-by Guangshuo Li <[email protected]>--- drivers/acpi/power.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/acpi/power.c +0
-0
drivers/acpi/power.c struct acpi_device *acpi_add_power_resource(acpi_handle handle) · line 994
Quoted 5 lines
drivers/acpi/power.c +1
-1@@ -991,7 +991,7 @@ struct acpi_device *acpi_add_power_resource(acpi_handle handle)return device; err: -acpi_release_power_resource (&device->dev); +put_device (&device->dev);
Please use acpi_dev_put() here.
Also, acpi_add_single_object() has the exact same problem, so it would be good to fix them both together in one patch.
drivers/acpi/power.c struct acpi_device *acpi_add_power_resource(acpi_handle handle)
Quoted 4 lines
drivers/acpi/power.c +0
-1return NULL ; } --
Thanks!