Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Miquel Raynal (Schneider Electric)" <miquel.raynal@bootlin.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v3 2/7] clk: tests: Add clk_parse_clkspec() Kunit testing
Date: Thu, 16 Jul 2026 11:04:31 +0000	[thread overview]
Message-ID: <20260716110432.03D171F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716-schneider-v7-2-rc1-eip201-upstream-v3-2-98454e83845c@bootlin.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Pre-existing race condition in `__of_clk_get()` exposing a time-of-check to time-of-use (TOCTOU) use-after-free vulnerability during concurrent clock provider unregistration.
--

--- Patch [2]: [PATCH v3 2/7] clk: tests: Add clk_parse_clkspec() Kunit testing ---
commit b17a28133ab40253da7bfbaf67521eac37a7e21a
Author: Miquel Raynal (Schneider Electric) <miquel.raynal@bootlin.com>

clk: tests: Add clk_parse_clkspec() Kunit testing

Create a new set of kunit tests to make sure clk_parse_clkspec() is
working as expected. We currently verify if we get a proper device when
using indexes and names.

> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 048adfa86a5d0..08874cf9b5617 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c

[ ... ]

> @@ -5300,6 +5301,7 @@ struct clk_hw *of_clk_get_hw(struct device_node *np, int index,
>  
>  	return hw;
>  }
> +EXPORT_SYMBOL_IF_KUNIT(of_clk_get_hw);
>  
>  static struct clk *__of_clk_get(struct device_node *np,
>  				int index, const char *dev_id,

[Severity: High]
This is a pre-existing issue, but exposing of_clk_get_hw() brings attention
to how the returned pointer is managed in the surrounding code.

Could a concurrent clock provider unregistration cause a use-after-free
vulnerability here?

Looking at how __of_clk_get() uses the hardware pointer:

__of_clk_get() {
    ...
    hw = of_clk_get_hw(np, index, con_id);
    return clk_hw_create_clk(NULL, hw, dev_id, con_id);
}

When of_clk_get_hw() calls of_clk_get_hw_from_clkspec(), it retrieves the hw
pointer under of_clk_mutex but returns it without incrementing any
underlying reference count.

Once the mutex is released, another thread could unregister the clock
provider, freeing both hw and hw->core.

If that happens before clk_hw_create_clk() executes, does it dereference
the freed pointer when evaluating hw->core and attempting try_module_get()
on core->owner?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716-schneider-v7-2-rc1-eip201-upstream-v3-0-98454e83845c@bootlin.com?part=2

  reply	other threads:[~2026-07-16 11:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 10:44 [PATCH v3 0/7] clk: Add support for clock nexus Miquel Raynal (Schneider Electric)
2026-07-16 10:44 ` [PATCH v3 1/7] dt-bindings: clock: Introduce nexus nodes Miquel Raynal (Schneider Electric)
2026-07-16 10:51   ` sashiko-bot
2026-07-16 10:44 ` [PATCH v3 2/7] clk: tests: Add clk_parse_clkspec() Kunit testing Miquel Raynal (Schneider Electric)
2026-07-16 11:04   ` sashiko-bot [this message]
2026-07-16 10:44 ` [PATCH v3 3/7] clk: tests: Add Kunit testing for of_clk_get_parent_name() Miquel Raynal (Schneider Electric)
2026-07-16 10:44 ` [PATCH v3 4/7] clk: Improve a couple of comments Miquel Raynal (Schneider Electric)
2026-07-16 10:44 ` [PATCH v3 5/7] clk: Use the generic OF phandle parsing in only one place Miquel Raynal (Schneider Electric)
2026-07-16 10:44 ` [PATCH v3 6/7] clk: Add support for clock nexus dt bindings Miquel Raynal (Schneider Electric)
2026-07-16 11:37   ` sashiko-bot
2026-07-16 10:44 ` [PATCH v3 7/7] clk: tests: Add Kunit testing for nexus nodes Miquel Raynal (Schneider Electric)
2026-07-16 11:42   ` sashiko-bot

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=20260716110432.03D171F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=robh@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