Skip to contentSkip to conversation

acpi_battery_add(): use-after-free

DISCUSSION Adrian Bunk 2 participants 2 messages Jul 29, 2007 – Jul 30, 2007 ACPI

lore
Share & tools
lore
#0 lore raw

The Coverity checker spotted the following use-after-free in acpi_battery_add():

<-- snip -->

...
static int acpi_battery_add(struct acpi_device *device) {
...

        if (result) {
                acpi_battery_remove_fs(device);
                kfree(battery);
        }

        mutex_unlock(&battery->mutex);

...

<-- snip -->

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#1 lore raw
Quoted 15 lines · On Sun, 29 Jul 2007 17:00:46 +0200 Adrian Bunk <[email protected]> wrote:

The Coverity checker spotted the following use-after-free in acpi_battery_add():

<-- snip -->

...
static int acpi_battery_add(struct acpi_device *device) {
...

        if (result) {
                acpi_battery_remove_fs(device);
                kfree(battery);
        }

        mutex_unlock(&battery->mutex);
Quoted 4 lines

...

<-- snip -->

This?

drivers/acpi/battery.c renamed from drivers/acpi/battery.c~acpi_battery_add-use-after-free +1 -2
@@ -931,13 +931,12 @@ static int acpi_battery_add(struct acpi_
 
       end:
 
+	mutex_unlock(&battery->mutex);
 	if (result) {
 		acpi_battery_remove_fs(device);
 		kfree(battery);
 	}
 
-	mutex_unlock(&battery->mutex);
-
 	return result;
 }
 

_