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@quicin... Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: Sasha Levin sashal@kernel.org [ Brennan : Backport requires bus->p = NULL instead of priv = NULL ] Signed-off-by: Brennan Lamoreaux brennan.lamoreaux@broadcom.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..941532ddfdc6 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 @bus->p */ + bus->p = NULL; out: kfree(bus->p); bus->p = NULL; -- 2.39.4
[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: bfa54a793ba77ef696755b66f3ac4ed00c7d1248
WARNING: Author mismatch between patch and upstream commit: Backport author: Brennan Lamoreaux brennan.lamoreaux@broadcom.com Commit author: Zijun Hu quic_zijuhu@quicinc.com
Status in newer kernel trees: 6.12.y | Present (exact SHA1) 6.11.y | Present (different SHA1: 9ce15f68abed) 6.6.y | Present (different SHA1: d885c464c250) 6.1.y | Not found
Note: The patch differs from the upstream commit: --- 1: bfa54a793ba77 < -: ------------- driver core: bus: Fix double free in driver API bus_register() -: ------------- > 1: 488cd01e46650 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 | | stable/linux-5.10.y | Success | Success |
linux-stable-mirror@lists.linaro.org