public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] phy: core: fix potential UAF in of_phy_simple_xlate()
@ 2026-02-19 23:57 Dmitry Torokhov
  2026-02-20  0:11 ` Dmitry Torokhov
  2026-02-28  3:44 ` Zijun Hu
  0 siblings, 2 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-02-19 23:57 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Neil Armstrong, Rafael J. Wysocki, Geert Uytterhoeven,
	Johan Hovold, Claudiu Beznea, Dr. David Alan Gilbert,
	Peter Griffin, Dmitry Baryshkov, Krzysztof Kozlowski, Zijun Hu,
	linux-phy, linux-kernel

The implementation put_device()s located device and then uses
container_of() on the pointer. The device may disappear by that time,
resulting in UAF.

Fix the problem by keeping the reference to the framer device,
avoiding getting an extra reference to it in framer_get(), and making
sure to drop the reference in error path when we fail to get the module.

Fixes: e6625db66212 ("phy: core: Simplify API of_phy_simple_xlate() implementation")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/phy/phy-core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 4ad396214d0c..cf62eb9ddca9 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -682,10 +682,10 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id)
 	if (IS_ERR(phy))
 		return phy;
 
-	if (!try_module_get(phy->ops->owner))
+	if (!try_module_get(phy->ops->owner)) {
+		put_device(&phy->dev);
 		return ERR_PTR(-EPROBE_DEFER);
-
-	get_device(&phy->dev);
+	}
 
 	return phy;
 }
@@ -765,7 +765,6 @@ struct phy *of_phy_simple_xlate(struct device *dev,
 	if (!target_dev)
 		return ERR_PTR(-ENODEV);
 
-	put_device(target_dev);
 	return to_phy(target_dev);
 }
 EXPORT_SYMBOL_GPL(of_phy_simple_xlate);
-- 
2.53.0.345.g96ddfc5eaa-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-02-28  3:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-19 23:57 [PATCH] phy: core: fix potential UAF in of_phy_simple_xlate() Dmitry Torokhov
2026-02-20  0:11 ` Dmitry Torokhov
2026-02-21  1:01   ` Dmitry Torokhov
2026-02-23 23:15     ` Vladimir Oltean
2026-02-24  0:37       ` Dmitry Torokhov
2026-02-24 15:47         ` Vladimir Oltean
2026-02-24 20:38           ` Dmitry Torokhov
2026-02-25 23:50             ` Vladimir Oltean
2026-02-28  3:44 ` Zijun Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox