Skip to content

Commit

Permalink
driver: base: fix UAF when driver_attach failed
Browse files Browse the repository at this point in the history
[ Upstream commit 310862e ]

When driver_attach(drv); failed, the driver_private will be freed.
But it has been added to the bus, which caused a UAF.

To fix it, we need to delete it from the bus when failed.

Fixes: 190888a ("driver core: fix possible missing of device probe")
Signed-off-by: Schspa Shi <schspa@gmail.com>
Link: https://lore.kernel.org/r/20220513112444.45112-1-schspa@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
schspa authored and gregkh committed Jun 14, 2022
1 parent 7a6337b commit 823f24f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ int bus_add_driver(struct device_driver *drv)
if (drv->bus->p->drivers_autoprobe) {
error = driver_attach(drv);
if (error)
goto out_unregister;
goto out_del_list;
}
module_add_driver(drv->owner, drv);

Expand All @@ -648,6 +648,8 @@ int bus_add_driver(struct device_driver *drv)

return 0;

out_del_list:
klist_del(&priv->knode_bus);
out_unregister:
kobject_put(&priv->kobj);
/* drv->p is freed in driver_release() */
Expand Down

0 comments on commit 823f24f

Please sign in to comment.