提交 eb88afb2 编写于 作者: schspa's avatar schspa 提交者: Zheng Zengkai

driver: base: fix UAF when driver_attach failed

stable inclusion
from stable-v5.10.122
commit 823f24f2e329babd0330200d0b74882516fe57f4
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5W6OE

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=823f24f2e329babd0330200d0b74882516fe57f4

--------------------------------

[ Upstream commit 310862e5 ]

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: 190888ac ("driver core: fix possible missing of device probe")
Signed-off-by: schspa's avatarSchspa Shi <schspa@gmail.com>
Link: https://lore.kernel.org/r/20220513112444.45112-1-schspa@gmail.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 dc62e1ae
...@@ -621,7 +621,7 @@ int bus_add_driver(struct device_driver *drv) ...@@ -621,7 +621,7 @@ int bus_add_driver(struct device_driver *drv)
if (drv->bus->p->drivers_autoprobe) { if (drv->bus->p->drivers_autoprobe) {
error = driver_attach(drv); error = driver_attach(drv);
if (error) if (error)
goto out_unregister; goto out_del_list;
} }
module_add_driver(drv->owner, drv); module_add_driver(drv->owner, drv);
...@@ -648,6 +648,8 @@ int bus_add_driver(struct device_driver *drv) ...@@ -648,6 +648,8 @@ int bus_add_driver(struct device_driver *drv)
return 0; return 0;
out_del_list:
klist_del(&priv->knode_bus);
out_unregister: out_unregister:
kobject_put(&priv->kobj); kobject_put(&priv->kobj);
/* drv->p is freed in driver_release() */ /* drv->p is freed in driver_release() */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册