driver core: bus: Fix double free in driver API bus_register()

commit bfa54a793b 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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Zijun Hu
2024-07-27 16:34:01 +08:00
committed by Greg Kroah-Hartman
parent 0196802993
commit 87bc3cb23c
+2
View File
@@ -873,6 +873,8 @@ bus_devices_fail:
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;