summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2016-11-07 09:19:04 +0000
committerhselasky <hselasky@FreeBSD.org>2016-11-07 09:19:04 +0000
commit39dc586d6a207e41169d213009f997003f14357b (patch)
tree26d7958fa22152e4c57ce0b7e74e168fffdd92a8 /sys/kern
parentcc0a1cf3aac0e8112921791de41caab31bcd70bd (diff)
downloadFreeBSD-src-39dc586d6a207e41169d213009f997003f14357b.zip
FreeBSD-src-39dc586d6a207e41169d213009f997003f14357b.tar.gz
MFC r307518:
Fix device delete child function. When detaching device trees parent devices must be detached prior to detaching its children. This is because parent devices can have pointers to the child devices in their softcs which are not invalidated by device_delete_child(). This can cause use after free issues and panic(). Device drivers implementing trees, must ensure its detach function detaches or deletes all its children before returning. While at it remove now redundant device_detach() calls before device_delete_child() and device_delete_children(), mostly in the USB controller drivers. Tested by: Jan Henrik Sylvester <me@janh.de> Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D8070
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/subr_bus.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 1a22efe..0e949f8 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -1923,15 +1923,17 @@ device_delete_child(device_t dev, device_t child)
PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev)));
- /* remove children first */
+ /* detach parent before deleting children, if any */
+ if ((error = device_detach(child)) != 0)
+ return (error);
+
+ /* remove children second */
while ((grandchild = TAILQ_FIRST(&child->children)) != NULL) {
error = device_delete_child(child, grandchild);
if (error)
return (error);
}
- if ((error = device_detach(child)) != 0)
- return (error);
if (child->devclass)
devclass_delete_device(child->devclass, child);
if (child->parent)
OpenPOWER on IntegriCloud