net: phylink: correctly validate returned PCS in phylink_inband_caps
Subsystems (5)
PATCH 1/1 net: phylink: correctly validate returned PCS in phylink_inband_caps
In phylink_inband_caps(), the PCS returned by mac_select_pcs is only checked if NULL but mac_select_pcs can also return an error pointer.
This can cause a kernel panic as phylink_pcs_inband_caps() only checks if passed PCS is not NULL and directly dereference ops from the phylink_pcs struct.
Use the IS_ERR_OR_NULL macro to address both case where the returned PCS can be NULL or an error pointer and prevent a kernel panic.
--- drivers/net/phy/phylink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/phylink.c +1 -1
@@ -964,7 +964,7 @@ static unsigned int phylink_inband_caps(struct phylink *pl,return 0 ; pcs = pl->mac_ops->mac_select_pcs (pl->config, interface); -if (!pcs) +if (IS_ERR_OR_NULL (pcs))return 0 ;return phylink_pcs_inband_caps (pcs, interface);
Signature · 1 line
2.53.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 17 Aug 2026 23:30:03 +0200 you wrote:
In
phylink_inband_caps(), the PCS returned bymac_select_pcsis only checked if NULL butmac_select_pcscan also return an error pointer.This can cause a kernel panic as
phylink_pcs_inband_caps()only checks if passed PCS is not NULL and directly dereference ops from thephylink_pcsstruct.[...]
Here is the summary with links:
- [net] net: phylink: correctly validate returned PCS in phylink_inband_caps
https://git.kernel.org/netdev/net/c/f2849b1fd059
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html