[PATCH] driver core: bus: Fix double free in driver API bus_register()
From: Zijun Hu
Date: Sat Jul 27 2024 - 04:34:32 EST
From: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>
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@xxxxxxxxxxx>
---
drivers/base/bus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index ffea0728b8b2..08362ecec0ec 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -920,6 +920,8 @@ int bus_register(const struct bus_type *bus)
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
kset_unregister(&priv->subsys);
+ /* Above kset_unregister() will kfree @priv */
+ priv = NULL;
out:
kfree(priv);
return retval;
---
base-commit: 1722389b0d863056d78287a120a1d6cadb8d4f7b
change-id: 20240727-bus_register_fix-4451ccf01707
Best regards,
--
Zijun Hu <quic_zijuhu@xxxxxxxxxxx>