Skip to contentSkip to conversation

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

PATCH In review Tomas Krcka 2 participants 2 messages Oct 25, 2024 Stable branch

lore
Share & tools
lore
#0 lore raw

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

From: Zijun Hu <[email protected]>

[ Upstream commit bfa54a793ba77ef696755b66f3ac4ed00c7d1248 ]

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.

---
 drivers/base/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/base/bus.c +2 -0
index 339a9edcde5f..8fae7c700cc9 100644
@@ -853,6 +853,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 @priv */
+	priv = NULL;
 out:
 	kfree(bus->p);
 	bus->p = NULL;
Signature · 1 line
2.40.1
#1 lore raw

It’s not correct patch - you can discarded.
Sorry for noise.
Tomas

Quoted 33 lines · Tomas Krcka

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

From: Zijun Hu <[email protected]>

[ Upstream commit bfa54a793ba77ef696755b66f3ac4ed00c7d1248 ]

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.

---
drivers/base/bus.c | 2 ++

1 file changed, 2 insertions(+)
drivers/base/bus.c +0 -0
index 339a9edcde5f..8fae7c700cc9 100644
@@ -853,6 +853,8 @@ int bus_register(struct bus_type *bus)
       bus_remove_file(bus, &bus_attr_uevent);

bus_uevent_fail:

       kset_unregister(&bus->p->subsys);
drivers/base/bus.c +2 -0
+       /* Above kset_unregister() will kfree @priv */
+       priv = NULL;

out:

Quoted 5 lines
       kfree(bus->p);
       bus->p = NULL;

--
2.40.1

Amazon Web Services Development Center Germany GmbH Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597