From: sashiko-bot@kernel.org
To: "Guangshuo Li" <liguangshuo@mail.sdu.edu.cn>
Cc: linux-clk@vger.kernel.org
Subject: Re: [PATCH] clk: microchip: Unregister the PIC32MZDA OF clock provider
Date: Sat, 28 Nov 2026 09:53:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-238613@kernel.org> (raw)
In-Reply-To: <20261128-f81b700d6c-u16-0@mail.sdu.edu.cn>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] clk: microchip: UAF and incomplete teardown in
pic32mzda_clk_remove()
- [Medium] clk: microchip: incomplete error unwind in
pic32mzda_clk_probe()
--
commit 6d31002c60a71977bbe0f0b53f73dd0c80ec6ed3
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
clk: microchip: Unregister the PIC32MZDA OF clock provider
This commit removes the OF clock provider when register_nmi_notifier()
fails during probe and adds a platform driver remove callback to delete the
provider on unbind.
> diff --git a/drivers/clk/microchip/clk-pic32mzda.c b/drivers/clk/microchip/clk-pic32mzda.c
> index fc4357ec7103d..e889cb8130169 100644
> --- a/drivers/clk/microchip/clk-pic32mzda.c
> +++ b/drivers/clk/microchip/clk-pic32mzda.c
> @@ -241,7 +241,16 @@ static int pic32mzda_clk_probe(struct platform_device *pdev)
>
> /* register NMI for failsafe clock monitor */
> cd->failsafe_notifier.notifier_call = pic32_fscm_nmi;
> - return register_nmi_notifier(&cd->failsafe_notifier);
> + ret = register_nmi_notifier(&cd->failsafe_notifier);
> + if (ret)
> + of_clk_del_provider(np);
> +
> + return ret;
> +}
[Severity: Medium]
Does returning an error here leave non-devm resources and dangling
references behind when devres frees cd and the devm-registered clocks?
pic32mzda_clk_probe() allocates cd with devm_kzalloc_obj() and registers
most clocks via devm_clk_register(), but also performs several non-devm
registrations:
drivers/clk/microchip/clk-pic32mzda.c:pic32mzda_clk_probe() {
...
core->iobase = of_io_request_and_map(np, 0, of_node_full_name(np));
...
clks[FRCDIVCLK] = clk_register_divider(&pdev->dev, "frcdiv_clk",
"frc_clk", 0,
core->iobase,
OSC_FRCDIV_SHIFT,
OSC_FRCDIV_MASK,
CLK_DIVIDER_POWER_OF_TWO,
&core->reg_lock);
/* PLL ICLK mux */
pll_mux_clk = clk_register_mux(&pdev->dev, "spll_mux_clk",
pll_mux_parents, 2, 0,
core->iobase + 0x020,
PLL_ICLK_SHIFT, 1, 0, &core->reg_lock);
...
for (i = 0; i < MAXCLKS; i++) {
if (IS_ERR(clks[i]))
continue;
clk_register_clkdev(clks[i], NULL, __clk_get_name(clks[i]));
}
}
If register_nmi_notifier() fails, devres frees cd and the devm-allocated
clk_hw objects while the clk_lookup entries registered with
clk_register_clkdev() remain on the global clkdev list pointing to freed
clk_hw memory (causing a use-after-free on clk_get()), and frcdiv_clk and
spll_mux_clk remain registered with spinlock pointers to &cd->core.reg_lock
in freed cd. In addition, the critical clocks enabled just above are not
disabled/unprepared, the fixed-rate clocks are not unregistered, and
core->iobase from of_io_request_and_map() is neither unmapped nor released.
> +
> +static void pic32mzda_clk_remove(struct platform_device *pdev)
> +{
> + of_clk_del_provider(pdev->dev.of_node);
> }
[Severity: High]
Can unbinding this driver corrupt the global MIPS nmi_chain and cause a
use-after-free?
pic32mzda_clk_probe() registers &cd->failsafe_notifier with
register_nmi_notifier(), which links the embedded notifier_block into the
global nmi_chain in arch/mips/kernel/traps.c (and MIPS provides no
unregister_nmi_notifier() helper). When pic32mzda_clk_remove() returns,
devres frees cd while &cd->failsafe_notifier is still linked in nmi_chain,
so a subsequent NMI or register_nmi_notifier() call walks freed memory.
Unbinding also suffers from the same incomplete teardown as the probe error
path above: the non-devm clkdev lookup entries, non-devm clocks referencing
&cd->core.reg_lock, enabled critical clocks, and the of_io_request_and_map()
mapping and memory region are all left behind. Since this is a core SoC
clock controller, should pic32mzda_clk_driver set .suppress_bind_attrs =
true instead of providing an incomplete .remove callback?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-f81b700d6c-u16-0@mail.sdu.edu.cn?part=1
prev parent reply other threads:[~2026-11-28 9:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 9:40 [PATCH] clk: microchip: Unregister the PIC32MZDA OF clock provider Guangshuo Li
2026-11-28 9: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-238613@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=liguangshuo@mail.sdu.edu.cn \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox