All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bryan O'Donoghue" <bryan.odonoghue@linaro.org>
Cc: neil.armstrong@linaro.org, robh@kernel.org,
	devicetree@vger.kernel.org, vkoul@kernel.org, olteanv@gmail.com,
	conor+dt@kernel.org, media-ci@linuxtv.org,
	linux-phy@lists.infradead.org
Subject: Re: [PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node()
Date: Tue, 28 Jul 2026 09:47:17 +0000	[thread overview]
Message-ID: <20260728094717.DD9A61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-2-ae811e2f0799@linaro.org>

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

Pre-existing issues:
- [High] A TOCTOU race condition exists between looking up the PHY and acquiring its module/device references, leading to a Use-After-Free (UAF).
--

--- Patch [2]: [PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node() ---
commit 65a24031fe496953334387cf190f1425a8b31168
Author: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

phy: core: Add devm_phy_get_by_of_node()

Add a devm variant of phy_get_by_of_node() to allow for the familiar
pattern of having devres automatically release resources on the driver's
exit path.

> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index ebfad5325072e..7af24f2f4120f 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c

[ ... ]

> @@ -1029,6 +1029,40 @@ struct phy *phy_get_by_of_node(struct device_node *np)
>  }
>  EXPORT_SYMBOL_GPL(phy_get_by_of_node);
>  
> +/**
> + * devm_phy_get_by_of_node() - devm managed lookup and obtain phy reference by device node
> + * @dev: device requesting the PHY
> + * @np: device_node of the PHY provider
> + *
> + * Returns phy associated with the device_node or ERR_PTR. devres manages
> + * releasing resources.
> + */
> +struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np)
> +{
> +	struct phy **ptr, *phy;
> +	struct device_link *link;
> +
> +	ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
> +	if (!ptr)
> +		return ERR_PTR(-ENOMEM);
> +
> +	phy = phy_get_by_of_node(np);

[Severity: High]
This is a pre-existing issue, but does a TOCTOU race condition exist in the
underlying phy_get_by_of_node() that could lead to a use-after-free here?

Looking at phy_get_by_of_node(), it calls _of_phy_get_with_args() to look up
the PHY. Inside _of_phy_get_with_args(), the function temporarily elevates the
provider's module refcount, calls of_xlate() (which returns a bare phy
pointer without incrementing the device refcount), and then drops the module
refcount and unlocks phy_provider_mutex before returning the raw phy pointer.

The caller then accesses phy->ops->owner and calls get_device(&phy->dev):

drivers/phy/phy-core.c:phy_get_by_of_node() {
    ...
	phy = _of_phy_get_with_args(&args);

	if (IS_ERR(phy))
		return phy;

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

	get_device(&phy->dev);
    ...
}

If the PHY provider module is unloaded or its driver is unbound via sysfs
concurrently in the window between _of_phy_get_with_args() returning and the
try_module_get() call, the phy struct could be unregistered and freed.

Could this cause the subsequent dereferences of phy->ops and phy->dev to
access freed memory?

> +	if (IS_ERR(phy)) {
> +		devres_free(ptr);
> +		return phy;
> +	}
> +
> +	*ptr = phy;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-0-ae811e2f0799@linaro.org?part=2

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

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Bryan O'Donoghue" <bryan.odonoghue@linaro.org>
Cc: neil.armstrong@linaro.org, robh@kernel.org,
	devicetree@vger.kernel.org, vkoul@kernel.org, olteanv@gmail.com,
	conor+dt@kernel.org, media-ci@linuxtv.org,
	linux-phy@lists.infradead.org
Subject: Re: [PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node()
Date: Tue, 28 Jul 2026 09:47:17 +0000	[thread overview]
Message-ID: <20260728094717.DD9A61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-2-ae811e2f0799@linaro.org>

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

Pre-existing issues:
- [High] A TOCTOU race condition exists between looking up the PHY and acquiring its module/device references, leading to a Use-After-Free (UAF).
--

--- Patch [2]: [PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node() ---
commit 65a24031fe496953334387cf190f1425a8b31168
Author: Bryan O'Donoghue <bryan.odonoghue@linaro.org>

phy: core: Add devm_phy_get_by_of_node()

Add a devm variant of phy_get_by_of_node() to allow for the familiar
pattern of having devres automatically release resources on the driver's
exit path.

> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index ebfad5325072e..7af24f2f4120f 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c

[ ... ]

> @@ -1029,6 +1029,40 @@ struct phy *phy_get_by_of_node(struct device_node *np)
>  }
>  EXPORT_SYMBOL_GPL(phy_get_by_of_node);
>  
> +/**
> + * devm_phy_get_by_of_node() - devm managed lookup and obtain phy reference by device node
> + * @dev: device requesting the PHY
> + * @np: device_node of the PHY provider
> + *
> + * Returns phy associated with the device_node or ERR_PTR. devres manages
> + * releasing resources.
> + */
> +struct phy *devm_phy_get_by_of_node(struct device *dev, struct device_node *np)
> +{
> +	struct phy **ptr, *phy;
> +	struct device_link *link;
> +
> +	ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
> +	if (!ptr)
> +		return ERR_PTR(-ENOMEM);
> +
> +	phy = phy_get_by_of_node(np);

[Severity: High]
This is a pre-existing issue, but does a TOCTOU race condition exist in the
underlying phy_get_by_of_node() that could lead to a use-after-free here?

Looking at phy_get_by_of_node(), it calls _of_phy_get_with_args() to look up
the PHY. Inside _of_phy_get_with_args(), the function temporarily elevates the
provider's module refcount, calls of_xlate() (which returns a bare phy
pointer without incrementing the device refcount), and then drops the module
refcount and unlocks phy_provider_mutex before returning the raw phy pointer.

The caller then accesses phy->ops->owner and calls get_device(&phy->dev):

drivers/phy/phy-core.c:phy_get_by_of_node() {
    ...
	phy = _of_phy_get_with_args(&args);

	if (IS_ERR(phy))
		return phy;

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

	get_device(&phy->dev);
    ...
}

If the PHY provider module is unloaded or its driver is unbound via sysfs
concurrently in the window between _of_phy_get_with_args() returning and the
try_module_get() call, the phy struct could be unregistered and freed.

Could this cause the subsequent dereferences of phy->ops and phy->dev to
access freed memory?

> +	if (IS_ERR(phy)) {
> +		devres_free(ptr);
> +		return phy;
> +	}
> +
> +	*ptr = phy;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-b4-linux-next-25-03-13-dtsi-x1e80100-camss-v13-0-ae811e2f0799@linaro.org?part=2

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

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  9:35 [PATCH v13 0/5] Add dt-bindings and PHY updates for CAMSS on x1e80100 silicon Bryan O'Donoghue
2026-07-28  9:35 ` Bryan O'Donoghue
2026-07-28  9:35 ` [PATCH v13 1/5] phy: core: Add phy_get_by_of_node() Bryan O'Donoghue
2026-07-28  9:35   ` Bryan O'Donoghue
2026-07-28  9:46   ` sashiko-bot
2026-07-28  9:46     ` sashiko-bot
2026-07-28 10:01     ` Bryan O'Donoghue
2026-07-28 10:01       ` Bryan O'Donoghue
2026-07-28  9:35 ` [PATCH v13 2/5] phy: core: Add devm_phy_get_by_of_node() Bryan O'Donoghue
2026-07-28  9:35   ` Bryan O'Donoghue
2026-07-28  9:47   ` sashiko-bot [this message]
2026-07-28  9:47     ` sashiko-bot
2026-07-28 10:21     ` Bryan O'Donoghue
2026-07-28 10:21       ` Bryan O'Donoghue
2026-07-28 10:46   ` Dmitry Baryshkov
2026-07-28 10:46     ` Dmitry Baryshkov
2026-07-28 10:51     ` Bryan O'Donoghue
2026-07-28 10:51       ` Bryan O'Donoghue
2026-07-28  9:35 ` [PATCH v13 3/5] media: qcom: camss: Add support for PHY API devices Bryan O'Donoghue
2026-07-28  9:35   ` Bryan O'Donoghue
2026-07-28  9:51   ` sashiko-bot
2026-07-28  9:51     ` sashiko-bot
2026-07-28 10:48   ` Dmitry Baryshkov
2026-07-28 10:48     ` Dmitry Baryshkov
2026-07-28 11:02   ` Loic Poulain
2026-07-28 11:02     ` Loic Poulain
2026-07-28  9:35 ` [PATCH v13 4/5] dt-bindings: media: qcom,x1e80100-camss: Describe iommu entries Bryan O'Donoghue
2026-07-28  9:35   ` Bryan O'Donoghue
2026-07-28 14:44   ` Rob Herring
2026-07-28 14:44     ` Rob Herring
2026-07-28  9:35 ` [PATCH v13 5/5] dt-bindings: media: qcom,x1e80100-camss: Make vdd-csiphy supplies optional Bryan O'Donoghue
2026-07-28  9:35   ` Bryan O'Donoghue
2026-07-28  9:42   ` sashiko-bot
2026-07-28  9:42     ` sashiko-bot
2026-07-28 10:06     ` Bryan O'Donoghue
2026-07-28 10:06       ` Bryan O'Donoghue

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=20260728094717.DD9A61F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bryan.odonoghue@linaro.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=media-ci@linuxtv.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --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.