All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Inochi Amaoto" <inochiama@gmail.com>
Cc: olteanv@gmail.com, vkoul@kernel.org,
	linux-phy@lists.infradead.org, neil.armstrong@linaro.org
Subject: Re: [PATCH v2 1/4] phy: core: Add common helper to add phy phandle device link
Date: Fri, 04 Sep 2026 08:50:50 +0000	[thread overview]
Message-ID: <20260904085050.885081F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904083709.425893-2-inochiama@gmail.com>

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

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a Use-After-Free (UAF) vulnerability in the PHY retrieval paths. Functions like `_of_phy_get()` and `phy_find()` locate a `struct phy` and return a pointer to it without holding any reference counts or locks. The caller then directly dereferences this pointer (e.g., `phy->ops->owner` during `try_module_get()`). If the PHY provider module is concurrently unloaded between the lookup and the dereference, `phy_destroy()` is invoked, freeing the PHY and leading to a Use-After-Free.
--

commit b6f92c42973f2e71067eb982ed22ae38c909d6ea
Author: Inochi Amaoto <inochiama@gmail.com>

phy: core: Add common helper to add phy phandle device link

It is very common for adding a device link for phy phandle
for device managed phy helper functions. So add a common
helper for future reuse.

> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 21aaf2f76e53e..ea79913fbb87f 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c

[ ... ]

> @@ -808,10 +827,7 @@ struct phy *phy_get(struct device *dev, const char *string)
>  
>  	get_device(&phy->dev);
>  

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for the phy
pointer to be freed before we access it in these paths?

Functions like _of_phy_get() and phy_find() locate a struct phy and return a
pointer to it without holding any reference counts or locks.

The caller then directly dereferences this pointer. For example, right before
this diff context in phy_get():

    if (!try_module_get(phy->ops->owner))
        return ERR_PTR(-EPROBE_DEFER);

If the PHY provider module is concurrently unloaded between the lookup and the
dereference, phy_destroy() could be invoked, freeing the PHY and leading to a
use-after-free.

This same pattern appears in of_phy_get() and devm_of_phy_get_by_index() when
accessing phy->ops->owner. Could a reference be taken on the device or module
while still holding the lookup locks?

> -	link = device_link_add(dev, &phy->dev, DL_FLAG_STATELESS);
> -	if (!link)
> -		dev_dbg(dev, "failed to create device link to %s\n",
> -			dev_name(phy->dev.parent));
> +	phy_add_device_link(dev, phy);
>  
>  	return phy;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260904083709.425893-1-inochiama@gmail.com?part=1

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-09-04  8:50 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  8:37 [PATCH v2 0/4] phy: core: Add phy bulk helpers support Inochi Amaoto
2026-09-04  8:37 ` [PATCH v2 1/4] phy: core: Add common helper to add phy phandle device link Inochi Amaoto
2026-09-04  8:50   ` sashiko-bot [this message]
2026-09-05  8:02   ` Andy Shevchenko
2026-09-07 11:01   ` Vladimir Oltean
2026-09-07 11:33     ` Inochi Amaoto
2026-09-04  8:37 ` [PATCH v2 2/4] phy: core: Add common helper for get phy phandle by index Inochi Amaoto
2026-09-04  8:48   ` sashiko-bot
2026-09-05  8:14   ` Andy Shevchenko
2026-09-07 11:03   ` Vladimir Oltean
2026-09-07 11:30     ` Inochi Amaoto
2026-09-04  8:37 ` [PATCH v2 3/4] phy: core: Add phy bulk data helper functions Inochi Amaoto
2026-09-04  8:50   ` sashiko-bot
2026-09-07 10:56   ` Vladimir Oltean
2026-09-07 11:37     ` Inochi Amaoto
2026-09-07 11:48   ` Vladimir Oltean
2026-09-07 12:15     ` Inochi Amaoto
2026-09-07 12:43       ` Vladimir Oltean
2026-09-07 22:20         ` Inochi Amaoto
2026-09-04  8:37 ` [PATCH v2 4/4] phy: core: Add managed " Inochi Amaoto
2026-09-07 10:28 ` [PATCH v2 0/4] phy: core: Add phy bulk helpers support Vladimir Oltean
2026-09-07 11:29   ` Inochi Amaoto
2026-09-07 11:57     ` Vladimir Oltean
2026-09-07 12:05       ` Inochi Amaoto
2026-09-07 12:16         ` Vladimir Oltean
2026-09-07 13:04           ` Vladimir Oltean
2026-09-07 22:28           ` Inochi Amaoto

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=20260904085050.885081F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=inochiama@gmail.com \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@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 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.