* [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register()
@ 2024-12-11 10:13 jianqi.ren.cn
2024-12-11 16:32 ` Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: jianqi.ren.cn @ 2024-12-11 10:13 UTC (permalink / raw)
To: quic_zijuhu, jianqi.ren.cn, gregkh; +Cc: patches, stable, rafael, linux-kernel
From: Zijun Hu <quic_zijuhu@quicinc.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@quicinc.com>
Link: https://lore.kernel.org/r/20240727-bus_register_fix-v1-1-fed8dd0dba7a@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ Using bus->p instead of priv which will be consistent with the context ]
Signed-off-by: Jianqi Ren <jianqi.ren.cn@windriver.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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register()
2024-12-11 10:13 [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register() jianqi.ren.cn
@ 2024-12-11 16:32 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2024-12-11 16:32 UTC (permalink / raw)
To: stable; +Cc: jianqi.ren.cn, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: bfa54a793ba77ef696755b66f3ac4ed00c7d1248
WARNING: Author mismatch between patch and upstream commit:
Backport author: <jianqi.ren.cn@windriver.com>
Commit author: Zijun Hu <quic_zijuhu@quicinc.com>
Status in newer kernel trees:
6.12.y | Present (exact SHA1)
6.6.y | Present (different SHA1: d885c464c250)
6.1.y | Present (different SHA1: 25d339a6e63b)
Note: The patch differs from the upstream commit:
---
1: bfa54a793ba77 < -: ------------- driver core: bus: Fix double free in driver API bus_register()
-: ------------- > 1: eda23201cf4ef driver core: bus: Fix double free in driver API bus_register()
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.1.y | Success | Success |
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register()
@ 2024-12-10 9:49 jianqi.ren.cn
2024-12-10 19:25 ` Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: jianqi.ren.cn @ 2024-12-10 9:49 UTC (permalink / raw)
To: jianqi.ren.cn, quic_zijuhu, gregkh; +Cc: stable, rafael, linux-kernel
From: Zijun Hu <quic_zijuhu@quicinc.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@quicinc.com>
Link: https://lore.kernel.org/r/20240727-bus_register_fix-v1-1-fed8dd0dba7a@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ Using bus->p instead of priv which will be consistent with the context ]
Signed-off-by: Jianqi Ren <jianqi.ren.cn@windriver.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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register()
2024-12-10 9:49 jianqi.ren.cn
@ 2024-12-10 19:25 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2024-12-10 19:25 UTC (permalink / raw)
To: stable; +Cc: jianqi.ren.cn, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: bfa54a793ba77ef696755b66f3ac4ed00c7d1248
WARNING: Author mismatch between patch and upstream commit:
Backport author: <jianqi.ren.cn@windriver.com>
Commit author: Zijun Hu <quic_zijuhu@quicinc.com>
Status in newer kernel trees:
6.12.y | Present (exact SHA1)
6.6.y | Present (different SHA1: d885c464c250)
6.1.y | Present (different SHA1: cb6ae5642a3b)
Note: The patch differs from the upstream commit:
---
1: bfa54a793ba77 < -: ------------- driver core: bus: Fix double free in driver API bus_register()
-: ------------- > 1: 554a31ffcf40a driver core: bus: Fix double free in driver API bus_register()
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.1.y | Success | Success |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-11 16:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 10:13 [PATCH 6.1.y] driver core: bus: Fix double free in driver API bus_register() jianqi.ren.cn
2024-12-11 16:32 ` Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2024-12-10 9:49 jianqi.ren.cn
2024-12-10 19:25 ` Sasha Levin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.