[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20241210094942.408718-1-jianqi.ren.cn@windriver.com>
Date: Tue, 10 Dec 2024 17:49:42 +0800
From: <jianqi.ren.cn@...driver.com>
To: <jianqi.ren.cn@...driver.com>, <quic_zijuhu@...cinc.com>,
<gregkh@...uxfoundation.org>
CC: <stable@...r.kernel.org>, <rafael@...nel.org>,
<linux-kernel@...r.kernel.org>
Subject: [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register()
From: Zijun Hu <quic_zijuhu@...cinc.com>
[ 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.
Signed-off-by: Zijun Hu <quic_zijuhu@...cinc.com>
Link: https://lore.kernel.org/r/20240727-bus_register_fix-v1-1-fed8dd0dba7a@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
[ Using bus->p instead of priv which will be consistent with the context ]
Signed-off-by: Jianqi Ren <jianqi.ren.cn@...driver.com>
---
drivers/base/bus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 339a9edcde5f..028e45d2f7fe 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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 */
+ bus->p = NULL;
out:
kfree(bus->p);
bus->p = NULL;
--
2.25.1
Powered by blists - more mailing lists