From: sashiko-bot@kernel.org
To: "Joshua Covington" <joshuacov@gmail.com>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH] clk: rp1: allow the clock provider to be probed again
Date: Sat, 21 Nov 2026 16:53:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-227181@kernel.org> (raw)
In-Reply-To: <20261121163915.86681-1-joshuacov@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] clk: rp1: use-after-free in rp1_clk_probe() from stale hw.core
on re-probe
--
commit 0c4e0577acfd5e28d80d2ef3e1cc9693b2d23c01
Author: Joshua Covington <joshuacov@gmail.com>
clk: rp1: allow the clock provider to be probed again
This commit saves and restores the clk_init_data pointer on each static
rp1_clk_desc descriptor in rp1_clk_probe() so the driver can register its
clocks again after an unbind and rebind.
> diff --git a/drivers/clk/clk-rp1.c b/drivers/clk/clk-rp1.c
> index 1dd276dd2bb3e..5c3929e935fce 100644
> --- a/drivers/clk/clk-rp1.c
> +++ b/drivers/clk/clk-rp1.c
> @@ -363,6 +363,7 @@ struct rp1_clk_desc {
> struct rp1_clk_desc *desc);
> const void *data;
> struct clk_hw hw;
> + const struct clk_init_data *init;
> struct rp1_clockman *clockman;
> unsigned long cached_rate;
> struct clk_divider div;
> @@ -2418,8 +2419,15 @@ static int rp1_clk_probe(struct platform_device *pdev)
>
> for (i = 0; i < asize; i++) {
> desc = clk_desc_array[i];
> - if (desc && desc->clk_register && desc->data)
> - hws[i] = desc->clk_register(clockman, desc);
> + if (!desc || !desc->clk_register || !desc->data)
> + continue;
> +
> + /* The clock core clears hw.init of these static descriptors */
> + if (!desc->init)
> + desc->init = desc->hw.init;
> + desc->hw.init = desc->init;
> +
> + hws[i] = desc->clk_register(clockman, desc);
> }
[Severity: High]
Can re-probing cause a use-after-free on a freed struct clk_core when a
clock references a parent at a higher index in clk_desc_array?
When the device is unbound, clk_unregister() frees each clock's struct
clk_core without clearing hw->core on the static descriptors. In
clk_core_fill_parent_index(), the clock core checks entry->hw->core and
assumes a non-NULL pointer is an already-registered parent.
Several descriptors in clk_desc_array reference parents via .hw that sit
at higher array indices, such as clk_mipi0_dpi_desc (RP1_CLK_MIPI0_DPI)
referencing clksrc_mipi0_dsi_byteclk_desc (RP1_CLK_MIPI0_DSI_BYTECLOCK).
Because rp1_clk_probe() registers clocks in a single pass without first
clearing desc->hw.core (and desc->div.hw.core) across clk_desc_array, if
the hardware mux selects one of those higher-indexed parents during
re-probe, __clk_init_parent() -> clk_core_fill_parent_index() returns the
dangling clk_core pointer from the previous bind and __clk_core_init()
links into parent->children on freed memory.
Clearing desc->hw.core and desc->div.hw.core for all descriptors before
the registration loop would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121163915.86681-1-joshuacov@gmail.com?part=1
prev parent reply other threads:[~2026-11-21 16:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 16:39 [PATCH] clk: rp1: allow the clock provider to be probed again Joshua Covington
2026-11-21 16:53 ` sashiko-bot [this message]
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=sashiko-outbox-227181@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=joshuacov@gmail.com \
--cc=linux-clk@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 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.