From: Hagar Hemdan <hagarhem@amazon.com>
Cc: <stable@vger.kernel.org>, Zijun Hu <quic_zijuhu@quicinc.com>,
Hagar Hemdan <hagarhem@amazon.com>
Subject: [PATCH 5.4] driver core: bus: Fix double free in driver API bus_register()
Date: Wed, 12 Feb 2025 08:58:03 +0000 [thread overview]
Message-ID: <20250212085806.29119-1-hagarhem@amazon.com> (raw)
From: Zijun Hu <quic_zijuhu@quicinc.com>
commit bfa54a793ba77ef696755b66f3ac4ed00c7d1248 upstream.
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
[ hagar : required setting bus->p with NULL instead of priv]
Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
---
drivers/base/bus.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index f970a40a2f7a..0b0969e64f5c 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -873,6 +873,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.47.1
reply other threads:[~2025-02-12 8:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250212085806.29119-1-hagarhem@amazon.com \
--to=hagarhem@amazon.com \
--cc=quic_zijuhu@quicinc.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox