From: "Nuno Sá" <nuno.sa@analog.com>
To: <linux-clk@vger.kernel.org>
Cc: Stephen Boyd <sboyd@kernel.org>,
Michael Turquette <mturquette@baylibre.com>
Subject: [PATCH 1/2] clk: fix clk not being unlinked from consumers list
Date: Wed, 12 Jun 2024 11:34:25 +0200 [thread overview]
Message-ID: <20240612-dev-clk-misc-v1-1-7ad8b58f2ea2@analog.com> (raw)
In-Reply-To: <20240612-dev-clk-misc-v1-0-7ad8b58f2ea2@analog.com>
When a clk_hw is registered we add a struct clk handle to it's
consumers list. This handle is created in '__clk_register()' per the
'alloc_clk()' call.
As such, we need to remove this handle when unregistering the
clk_hw. This can actually lead to a use after free if a provider gets
removed before a consumer. When removing the consumer, '__clk_put()' is
called and that will do 'hlist_del(&clk->clks_node)' which will touch in
already freed memory.
Fixes: 1df4046a93e0 ("clk: Combine __clk_get() and __clk_create_clk()")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
drivers/clk/clk.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 8cca52be993f..b11beeca7e55 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -4606,6 +4606,8 @@ void clk_unregister(struct clk *clk)
if (clk->core->protect_count)
pr_warn("%s: unregistering protected clock: %s\n",
__func__, clk->core->name);
+
+ clk_core_unlink_consumer(clk);
clk_prepare_unlock();
kref_put(&clk->core->ref, __clk_release);
--
2.45.2
next prev parent reply other threads:[~2024-06-12 9:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 9:34 [PATCH 0/2] clk: fix possible use after free Nuno Sá
2024-06-12 9:34 ` Nuno Sá [this message]
2024-06-12 9:34 ` [PATCH 2/2] clk: use clk_core_unlink_consumer() helper Nuno Sá
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=20240612-dev-clk-misc-v1-1-7ad8b58f2ea2@analog.com \
--to=nuno.sa@analog.com \
--cc=linux-clk@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=sboyd@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