From: Maxime Chevallier Date: Tue, 10 Sep 2024 17:46:35 +0000 (+0200) Subject: net: ethtool: phy: Check the req_info.pdn field for GET commands X-Git-Tag: v6.12-rc1~232^2~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fce1e9f86af13cbd6696ef0c8775990559108f45;p=thirdparty%2Fkernel%2Flinux.git net: ethtool: phy: Check the req_info.pdn field for GET commands When processing the netlink GET requests to get PHY info, the req_info.pdn pointer is NULL when no PHY matches the requested parameters, such as when the phy_index is invalid, or there's simply no PHY attached to the interface. Therefore, check the req_info.pdn pointer for NULL instead of dereferencing it. Suggested-by: Eric Dumazet Reported-by: Eric Dumazet Closes: https://lore.kernel.org/netdev/CANn89iKRW0WpGAh1tKqY345D8WkYCPm3Y9ym--Si42JZrQAu1g@mail.gmail.com/T/#mfced87d607d18ea32b3b4934dfa18d7b36669285 Fixes: 17194be4c8e1 ("net: ethtool: Introduce a command to list PHYs on an interface") Signed-off-by: Maxime Chevallier Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20240910174636.857352-1-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- diff --git a/net/ethtool/phy.c b/net/ethtool/phy.c index 560dd039c6625..4ef7c6e32d108 100644 --- a/net/ethtool/phy.c +++ b/net/ethtool/phy.c @@ -164,7 +164,7 @@ int ethnl_phy_doit(struct sk_buff *skb, struct genl_info *info) goto err_unlock_rtnl; /* No PHY, return early */ - if (!req_info.pdn->phy) + if (!req_info.pdn) goto err_unlock_rtnl; ret = ethnl_phy_reply_size(&req_info.base, info->extack);