* [PATCH 5.4] driver core: bus: Fix double free in driver API bus_register()
@ 2025-02-12 8:58 Hagar Hemdan
0 siblings, 0 replies; only message in thread
From: Hagar Hemdan @ 2025-02-12 8:58 UTC (permalink / raw)
Cc: stable, Zijun Hu, Hagar Hemdan
From: Zijun Hu <quic_zijuhu@quicinc.com>
commit bfa54a793ba77ef696755b66f3ac4ed00c7d1248 upstream.
For bus_register(), any error which happens after kset_register() will
cause that @priv are freed twice, fixed by setting @priv with NULL after
the first free.
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20240727-bus_register_fix-v1-1-fed8dd0dba7a@quicinc.com
[ hagar : required setting bus->p with NULL instead of priv]
Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
---
drivers/base/bus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index f970a40a2f7a..0b0969e64f5c 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -873,6 +873,8 @@ int bus_register(struct bus_type *bus)
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
kset_unregister(&bus->p->subsys);
+ /* Above kset_unregister() will kfree @bus->p */
+ bus->p = NULL;
out:
kfree(bus->p);
bus->p = NULL;
--
2.47.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-02-12 8:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 8:58 [PATCH 5.4] driver core: bus: Fix double free in driver API bus_register() Hagar Hemdan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox