driver: base: fix UAF when driver_attach failed
authorSchspa Shi <schspa@gmail.com>
Fri, 13 May 2022 11:24:44 +0000 (19:24 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Jun 2022 16:36:09 +0000 (18:36 +0200)
commitcdf1a683a01583bca4b618dd16223cbd6e462e21
treebf530c727daf16eec18f044c8caf7f227fe56e8b
parent40960520a94004a1ceca5470c2efbdc58b6197cc
driver: base: fix UAF when driver_attach failed

[ Upstream commit 310862e574001a97ad02272bac0fd13f75f42a27 ]

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: 190888ac01d0 ("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>
drivers/base/bus.c