792-02-v6.0-net-phylink-fix-NULL-pl-pcs-dereference-during-phyli.patch 1.6 KB

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