]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: phylink: fix NULL pl->pcs dereference during phylink_pcs_poll_start
authorVladimir Oltean <vladimir.oltean@nxp.com>
Wed, 29 Jun 2022 19:33:58 +0000 (22:33 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Jun 2022 19:18:28 +0000 (12:18 -0700)
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: d4fe1494756c ("net: phylink: disable PCS polling over major configuration")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tested-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Tested-by: Michael Walle <michael@walle.cc> # on kontron-kbox-a-230-ls
Tested-by: Nicolas Ferre <nicolas.ferre@microchip.com> # on sam9x60ek
Link: https://lore.kernel.org/r/20220629193358.4007923-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phylink.c

index 1a7550f5fdf566aa1d6e2c3958b162afbe01295c..48f0b9b39491e358a8e917ce36ee80e1d05d2c8e 100644 (file)
@@ -766,7 +766,7 @@ static void phylink_pcs_poll_stop(struct phylink *pl)
 
 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);
 }