From b7d78b46d5e8dc77c656c13885d31e931923b915 Mon Sep 17 00:00:00 2001 From: Vladimir Oltean Date: Wed, 29 Jun 2022 22:33:58 +0300 Subject: [PATCH] net: phylink: fix NULL pl->pcs dereference during phylink_pcs_poll_start The current link mode of the phylink instance may not require an attached PCS. However, phylink_major_config() unconditionally dereferences this potentially NULL pointer when restarting the link poll timer, which will panic the kernel. Fix the problem by checking whether a PCS exists in phylink_pcs_poll_start(), otherwise do nothing. The code prior to the blamed patch also only looked at pcs->poll within an "if (pcs)" block. Fixes: bfac8c490d60 ("net: phylink: disable PCS polling over major configuration") Signed-off-by: Vladimir Oltean Reviewed-by: Russell King (Oracle) Tested-by: Gerhard Engleder Tested-by: Michael Walle # on kontron-kbox-a-230-ls Tested-by: Nicolas Ferre # on sam9x60ek Link: https://lore.kernel.org/r/20220629193358.4007923-1-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/phylink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -764,7 +764,7 @@ static void phylink_pcs_poll_stop(struct static void phylink_pcs_poll_start(struct phylink *pl) { - if (pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND) + if (pl->pcs && pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND) mod_timer(&pl->link_poll, jiffies + HZ); }