[PATCH] drivers-core: nullify private pointer on device-release

From: Guennadi Liakhovetski
Date: Thu Oct 01 2009 - 04:02:18 EST


Device structures can be reused over multiple device_add / device_release
cycles. As the private pointer in that struct is checked for NULL, it has
to be nullified after freeing the private data. Failure to do so causes a
use after free bug.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@xxxxxx>
---
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6bee6af..3c9f449 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -122,6 +122,7 @@ static void device_release(struct kobject *kobj)
WARN(1, KERN_ERR "Device '%s' does not have a release() "
"function, it is broken and must be fixed.\n",
dev_name(dev));
+ dev->p = NULL;
kfree(p);
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/