Patch "power_supply: Fix NULL pointer dereference during bq27x00_battery probe" has been added to the 4.1-stable tree
This is a note to let you know that I've just added the patch titled
power_supply: Fix NULL pointer dereference during bq27x00_battery probe
to the 4.1-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
power_supply-fix-null-pointer-dereference-during-bq27x00_battery-probe.patch
and it can be found in the queue-4.1 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
8e59c7f23410d5ca6b350a178b861a3d68c49edfMon Sep 17 00:00:00 2001
From: Krzysztof Kozlowski <[email protected]>
Date: Tue, 19 May 2015 16:13:01 +0900
Subject: power_supply: Fix NULL pointer dereference during bq27x00_battery probe
From: Krzysztof Kozlowski <[email protected]>
commit 8e59c7f23410d5ca6b350a178b861a3d68c49edf upstream.
Power supply is often registered during probe of a driver. The power_supply_register() returns pointer to newly allocated structure as return value. However before returning the power_supply_register() calls back the get_property() method provided by the driver through uevent.
In that time the driver probe is still in progress and driver did not assigned pointer to power supply to its local variables. This leads to NULL pointer dereference from get_property() function. Starting from bq27x00_battery_probe():
di->bat = power_supply_register()
device_add()
kobject_uevent()
power_supply_uevent()
power_supply_show_property()
power_supply_get_property()
bq27x00_battery_get_property()
dereference of (di->bat) which is NULL hereThe first uevent of power supply (the one coming from device creation) should not call back to the driver. To prevent that from happening, increment the atomic use counter at the end of power_supply_register(). This means that power_supply_get_property() will return -ENODEV.
IMPORTANT:
The patch has impact on this first uevent sent from power supply because it will not contain properties from power supply.
The uevent with properties will be sent later after indicating that power supply has changed. This also has a race now, but will be fixed in other patches.
--- drivers/power/power_supply_core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/power/power_supply_core.c +10 -1
@@ -659,7 +659,6 @@ __power_supply_register(struct device *p dev->release = power_supply_dev_release;dev_set_drvdata (dev, psy); psy->desc = desc; -atomic_inc (&psy->use_cnt);if (cfg) { psy->drv_data = cfg->drv_data; psy->of_node = cfg->of_node;
@@ -700,6 +699,16 @@ __power_supply_register(struct device *pif (rc) goto create_triggers_failed; +/* +* Update use_cnt after any uevents (most notably from device_add()). +* We are here still during driver's probe but +* the power_supply_uevent() calls back driver's get_property +* method so: +* 1. Driver did not assigned the returned struct power_supply, +* 2. Driver could not finish initialization (anything in its probe +* after calling power_supply_register()). +*/ +atomic_inc (&psy->use_cnt);power_supply_changed (psy);return psy;
Patches currently in stable-queue which might be from [email protected] are
queue-4.1/power_supply-fix-null-pointer-dereference-during-bq27x00_battery-probe.patch queue-4.1/power_supply-fix-possible-null-pointer-dereference-on-early-uevent.patch