ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guangshuo Li" <liguangshuo@mail.sdu.edu.cn>
Cc: linux-clk@vger.kernel.org, linux-sunxi@lists.linux.dev
Subject: Re: [PATCH 3/3] clk: sunxi: Fix potential use-after-free of APB0 provider data
Date: Sat, 28 Nov 2026 09:47:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-238604@kernel.org> (raw)
In-Reply-To: <20261128-f81b700d6c-u17-3@mail.sdu.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] clk: sunxi: unmapped MMIO use-after-free in
  sun6i_a31_apb0_gates_clk_remove()
--

commit dc78e25adc6746add0b39ad7479959e1a2f6206a
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

clk: sunxi: Fix potential use-after-free of APB0 provider data

This commit adds a remove callback to sun6i_a31_apb0_gates_clk_driver to
delete the OF clock provider before devres frees the managed onecell data.

> diff --git a/drivers/clk/sunxi/clk-sun6i-apb0-gates.c b/drivers/clk/sunxi/clk-sun6i-apb0-gates.c
> index a10ebd1998fbf..9d1fef8c520e9 100644
> --- a/drivers/clk/sunxi/clk-sun6i-apb0-gates.c
> +++ b/drivers/clk/sunxi/clk-sun6i-apb0-gates.c
> @@ -87,11 +87,17 @@ static int sun6i_a31_apb0_gates_clk_probe(struct platform_device *pdev)
>  	return of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
>  }
>  
> +static void sun6i_a31_apb0_gates_clk_remove(struct platform_device *pdev)
> +{
> +	of_clk_del_provider(pdev->dev.of_node);
> +}
> +
>  static struct platform_driver sun6i_a31_apb0_gates_clk_driver = {
>  	.driver = {
>  		.name = "sun6i-a31-apb0-gates-clk",
>  		.of_match_table = sun6i_a31_apb0_gates_clk_dt_ids,
>  	},
>  	.probe = sun6i_a31_apb0_gates_clk_probe,
> +	.remove = sun6i_a31_apb0_gates_clk_remove,
>  };
>  builtin_platform_driver(sun6i_a31_apb0_gates_clk_driver);

[Severity: High]
Does sun6i_a31_apb0_gates_clk_remove() leave the gate clocks registered
after reg is unmapped?

sun6i_a31_apb0_gates_clk_probe() maps reg with
devm_platform_ioremap_resource() and registers each gate clock with the
unmanaged clk_register_gate().  When the driver is unbound, devres unmaps
reg right after sun6i_a31_apb0_gates_clk_remove() returns, leaving the
registered struct clk_gate objects pointing at an unmapped MMIO address.
Any later access to those clocks (such as clk_enable() or reading
/sys/kernel/debug/clk/clk_summary) will fault on gate->reg, and rebinding
the driver will fail with -EEXIST.

Registering the gates with devm_clk_hw_register_gate() (or unregistering
them in remove) would release them before reg is unmapped.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-f81b700d6c-u17-0@mail.sdu.edu.cn?part=3

      reply	other threads:[~2026-11-28  9:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  9:39 [PATCH 0/3] clk: sunxi: Pair platform clock setup with teardown Guangshuo Li
2026-11-28  9:39 ` [PATCH 1/3] clk: sunxi: Release the platform mod0 clock before unmapping it Guangshuo Li
2026-11-28  9:39 ` [PATCH 2/3] clk: sunxi: Unregister the A31 and A23 APB0 platform clocks Guangshuo Li
2026-11-28  9:39 ` [PATCH 3/3] clk: sunxi: Fix potential use-after-free of APB0 provider data Guangshuo Li
2026-11-28  9:47   ` 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-238604@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=liguangshuo@mail.sdu.edu.cn \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --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