Skip to contentSkip to conversation

device property: fix potential NULL pointer dereference

PATCH In review Andy Shevchenko 2 participants 2 messages Aug 5, 2015

Subsystems (2)
lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

PATCH 1/1 device property: fix potential NULL pointer dereference

In device_add_property_set() we check pset parameter for a NULL, but few lines later we do a pointer arithmetic without check that will crash kernel in the set_secondary_fwnode().

Here we check if pset parameter is NULL and return immediately.

Fixes 16ba08d5c9ec (device property: Introduce firmware node type for platform data)
---
 drivers/base/property.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/base/property.c +3 -2
index f3f6d16..37a7bb7 100644
@@ -27,9 +27,10 @@
  */
 void device_add_property_set(struct device *dev, struct property_set *pset)
 {
-	if (pset)
-		pset->fwnode.type = FWNODE_PDATA;
+	if (!pset)
+		return;
 
+	pset->fwnode.type = FWNODE_PDATA;
 	set_secondary_fwnode(dev, &pset->fwnode);
 }
 EXPORT_SYMBOL_GPL(device_add_property_set);
Signature · 1 line
2.4.6
#1 lore raw
Quoted 8 lines · Andy Shevchenko

In device_add_property_set() we check pset parameter for a NULL, but few lines later we do a pointer arithmetic without check that will crash kernel in the set_secondary_fwnode().

Here we check if pset parameter is NULL and return immediately.

Fixes 16ba08d5c9ec (device property: Introduce firmware node type for platform data)

I don't think there are any users of this in 4.2, so I'll queue it up for 4.3.

Thanks!

Quoted 22 lines
---
 drivers/base/property.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/base/property.c +3 -2
index f3f6d16..37a7bb7 100644
@@ -27,9 +27,10 @@
  */
 void device_add_property_set(struct device *dev, struct property_set *pset)
 {
-	if (pset)
-		pset->fwnode.type = FWNODE_PDATA;
+	if (!pset)
+		return;
 
+	pset->fwnode.type = FWNODE_PDATA;
 	set_secondary_fwnode(dev, &pset->fwnode);
 }
 EXPORT_SYMBOL_GPL(device_add_property_set);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.