Skip to contentSkip to conversation

driver core: fix null pointer deref in device_find_child

PATCH In review Soenke Huster 2 participants 2 messages Jan 20, 2022 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver core: fix null pointer deref in device_find_child

Similar to device_for_each_child, device_find_child should not ooops if parent->p is NULL. While fuzzing the Bluetooth subsystem, I got a null pointer dereference in next_device, which is prevented by this change.

---
I found this while fuzzing the bluetooth subsystem and reported this bug in bugzilla. As I feel more like a kernelnewbie, I am not sure whether this needs to be patched in driver core, or is just an issue of the bluetooth subsystem itself. If the latter is the case: sorry for the spam!

A similar fix was applied in 014c90dbb9b6 ("driver core: prevent device_for_each_child from oopsing") for device_for_each_child, which is mentioned in the docstring of device_find_child as similar function.

 drivers/base/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index 7bb957b11861..654d904631f9 100644
@@ -3780,7 +3780,7 @@ struct device *device_find_child(struct device *parent, void *data,
 	struct klist_iter i;
 	struct device *child;
 
-	if (!parent)
+	if (!parent || !parent->p)
 		return NULL;
 
 	klist_iter_init(&parent->p->klist_children, &i);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Soenke Huster

Similar to device_for_each_child, device_find_child should not ooops if parent->p is NULL. While fuzzing the Bluetooth subsystem, I got a null pointer dereference in next_device, which is prevented by this change.

Quoted 8 lines

---
I found this while fuzzing the bluetooth subsystem and reported this bug in bugzilla. As I feel more like a kernelnewbie, I am not sure whether this needs to be patched in driver core, or is just an issue of the bluetooth subsystem itself. If the latter is the case: sorry for the spam!

bluetooth should be fixed, this is an indication that something is using a stale pointer and this would be the least of the problems here.

thanks,

greg k-h