diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-01-24 06:49:49 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-01-24 06:49:49 -0500 |
commit | cf860be639d86ed77af179c925085ae0721ae602 (patch) | |
tree | 3acb93b90f48f2bc4838ba80cd66dce60a40825a /drivers | |
parent | e5656271b0221a53e9f74856385112fdcec0dd60 (diff) |
ACPI / scan: Prevent device add uevents from racing with user space
ACPI core adds sysfs device files after the given devices have been
registered with device_register(), which is not appropriate, because
it may lead to race conditions with user space tools using those
files.
Fix the problem by delaying the KOBJ_ADD uevent for ACPI devices
until after all of the devices' sysfs files have been created.
This also fixes a use-after-free in acpi_device_unregister().
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/acpi/internal.h | 5 | ||||
-rw-r--r-- | drivers/acpi/power.c | 3 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 20 |
3 files changed, 20 insertions, 8 deletions
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 1f004f35bc67..c5a61cd6c1a5 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h | |||
@@ -40,10 +40,11 @@ static inline void acpi_debugfs_init(void) { return; } | |||
40 | #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ | 40 | #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ |
41 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) | 41 | ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) |
42 | 42 | ||
43 | int acpi_device_register(struct acpi_device *device, | 43 | int acpi_device_add(struct acpi_device *device, |
44 | void (*release)(struct device *)); | 44 | void (*release)(struct device *)); |
45 | void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, | 45 | void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, |
46 | int type, unsigned long long sta); | 46 | int type, unsigned long long sta); |
47 | void acpi_device_add_finalize(struct acpi_device *device); | ||
47 | void acpi_free_ids(struct acpi_device *device); | 48 | void acpi_free_ids(struct acpi_device *device); |
48 | 49 | ||
49 | /* -------------------------------------------------------------------------- | 50 | /* -------------------------------------------------------------------------- |
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index 6db261c237d4..3f16dd4db23e 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
@@ -721,13 +721,14 @@ int acpi_add_power_resource(acpi_handle handle) | |||
721 | acpi_device_bid(device), state ? "on" : "off"); | 721 | acpi_device_bid(device), state ? "on" : "off"); |
722 | 722 | ||
723 | device->flags.match_driver = true; | 723 | device->flags.match_driver = true; |
724 | result = acpi_device_register(device, acpi_release_power_resource); | 724 | result = acpi_device_add(device, acpi_release_power_resource); |
725 | if (result) | 725 | if (result) |
726 | goto err; | 726 | goto err; |
727 | 727 | ||
728 | mutex_lock(&power_resource_list_lock); | 728 | mutex_lock(&power_resource_list_lock); |
729 | list_add(&resource->list_node, &acpi_power_resource_list); | 729 | list_add(&resource->list_node, &acpi_power_resource_list); |
730 | mutex_unlock(&power_resource_list_lock); | 730 | mutex_unlock(&power_resource_list_lock); |
731 | acpi_device_add_finalize(device); | ||
731 | return 0; | 732 | return 0; |
732 | 733 | ||
733 | err: | 734 | err: |
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1fc57a349a3c..8b3b18846c8c 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -634,8 +634,8 @@ struct bus_type acpi_bus_type = { | |||
634 | .uevent = acpi_device_uevent, | 634 | .uevent = acpi_device_uevent, |
635 | }; | 635 | }; |
636 | 636 | ||
637 | int acpi_device_register(struct acpi_device *device, | 637 | int acpi_device_add(struct acpi_device *device, |
638 | void (*release)(struct device *)) | 638 | void (*release)(struct device *)) |
639 | { | 639 | { |
640 | int result; | 640 | int result; |
641 | struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; | 641 | struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; |
@@ -705,7 +705,7 @@ int acpi_device_register(struct acpi_device *device, | |||
705 | device->dev.parent = &device->parent->dev; | 705 | device->dev.parent = &device->parent->dev; |
706 | device->dev.bus = &acpi_bus_type; | 706 | device->dev.bus = &acpi_bus_type; |
707 | device->dev.release = release; | 707 | device->dev.release = release; |
708 | result = device_register(&device->dev); | 708 | result = device_add(&device->dev); |
709 | if (result) { | 709 | if (result) { |
710 | dev_err(&device->dev, "Error registering device\n"); | 710 | dev_err(&device->dev, "Error registering device\n"); |
711 | goto err; | 711 | goto err; |
@@ -744,12 +744,13 @@ static void acpi_device_unregister(struct acpi_device *device) | |||
744 | 744 | ||
745 | acpi_power_add_remove_device(device, false); | 745 | acpi_power_add_remove_device(device, false); |
746 | acpi_device_remove_files(device); | 746 | acpi_device_remove_files(device); |
747 | device_unregister(&device->dev); | 747 | device_del(&device->dev); |
748 | /* | 748 | /* |
749 | * Drop the reference counts of all power resources the device depends | 749 | * Drop the reference counts of all power resources the device depends |
750 | * on and turn off the ones that have no more references. | 750 | * on and turn off the ones that have no more references. |
751 | */ | 751 | */ |
752 | acpi_power_transition(device, ACPI_STATE_D3_COLD); | 752 | acpi_power_transition(device, ACPI_STATE_D3_COLD); |
753 | put_device(&device->dev); | ||
753 | } | 754 | } |
754 | 755 | ||
755 | /* -------------------------------------------------------------------------- | 756 | /* -------------------------------------------------------------------------- |
@@ -1391,6 +1392,14 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, | |||
1391 | acpi_device_get_busid(device); | 1392 | acpi_device_get_busid(device); |
1392 | acpi_device_set_id(device); | 1393 | acpi_device_set_id(device); |
1393 | acpi_bus_get_flags(device); | 1394 | acpi_bus_get_flags(device); |
1395 | device_initialize(&device->dev); | ||
1396 | dev_set_uevent_suppress(&device->dev, true); | ||
1397 | } | ||
1398 | |||
1399 | void acpi_device_add_finalize(struct acpi_device *device) | ||
1400 | { | ||
1401 | dev_set_uevent_suppress(&device->dev, false); | ||
1402 | kobject_uevent(&device->dev.kobj, KOBJ_ADD); | ||
1394 | } | 1403 | } |
1395 | 1404 | ||
1396 | static int acpi_add_single_object(struct acpi_device **child, | 1405 | static int acpi_add_single_object(struct acpi_device **child, |
@@ -1412,13 +1421,14 @@ static int acpi_add_single_object(struct acpi_device **child, | |||
1412 | acpi_bus_get_wakeup_device_flags(device); | 1421 | acpi_bus_get_wakeup_device_flags(device); |
1413 | 1422 | ||
1414 | device->flags.match_driver = match_driver; | 1423 | device->flags.match_driver = match_driver; |
1415 | result = acpi_device_register(device, acpi_device_release); | 1424 | result = acpi_device_add(device, acpi_device_release); |
1416 | if (result) { | 1425 | if (result) { |
1417 | acpi_device_release(&device->dev); | 1426 | acpi_device_release(&device->dev); |
1418 | return result; | 1427 | return result; |
1419 | } | 1428 | } |
1420 | 1429 | ||
1421 | acpi_power_add_remove_device(device, true); | 1430 | acpi_power_add_remove_device(device, true); |
1431 | acpi_device_add_finalize(device); | ||
1422 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | 1432 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
1423 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n", | 1433 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n", |
1424 | dev_name(&device->dev), (char *) buffer.pointer, | 1434 | dev_name(&device->dev), (char *) buffer.pointer, |