Re: [syzbot] [usb?] KASAN: slab-use-after-free Read in hdm_disconnect

From: Edward Adam Davis
Date: Tue Jul 30 2024 - 02:29:15 EST


move the relase dev to the end

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 933069701c1b


diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 83d352394fdf..02f5aeadd8fd 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1027,6 +1027,8 @@ static int __device_attach(struct device *dev, bool allow_async)

ret = bus_for_each_drv(dev->bus, NULL, &data,
__device_attach_driver);
+ if (!ret)
+ get_device(dev);
if (!ret && allow_async && data.have_async) {
/*
* If we could not find appropriate driver
@@ -1036,7 +1038,6 @@ static int __device_attach(struct device *dev, bool allow_async)
* try them.
*/
dev_dbg(dev, "scheduling asynchronous probe\n");
- get_device(dev);
async = true;
} else {
pm_request_idle(dev);