2
0

838-v6.9-leds-trigger-netdev-Fix-kernel-panic-on-interface-re.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From 12ce20e02e532f101b725d71c52a36c5cc8ad1e6 Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Sun, 4 Feb 2024 00:54:01 +0100
  4. Subject: [PATCH] leds: trigger: netdev: Fix kernel panic on interface rename
  5. trig notify
  6. Commit d5e01266e7f5 ("leds: trigger: netdev: add additional specific link
  7. speed mode") in the various changes, reworked the way to set the LINKUP
  8. mode in commit cee4bd16c319 ("leds: trigger: netdev: Recheck
  9. NETDEV_LED_MODE_LINKUP on dev rename") and moved it to a generic function.
  10. This changed the logic where, in the previous implementation the dev
  11. from the trigger event was used to check if the carrier was ok, but in
  12. the new implementation with the generic function, the dev in
  13. trigger_data is used instead.
  14. This is problematic and cause a possible kernel panic due to the fact
  15. that the dev in the trigger_data still reference the old one as the
  16. new one (passed from the trigger event) still has to be hold and saved
  17. in the trigger_data struct (done in the NETDEV_REGISTER case).
  18. On calling of get_device_state(), an invalid net_dev is used and this
  19. cause a kernel panic.
  20. To handle this correctly, move the call to get_device_state() after the
  21. new net_dev is correctly set in trigger_data (in the NETDEV_REGISTER
  22. case) and correctly parse the new dev.
  23. Fixes: d5e01266e7f5 ("leds: trigger: netdev: add additional specific link speed mode")
  24. Cc: [email protected]
  25. Signed-off-by: Christian Marangi <[email protected]>
  26. Reviewed-by: Andrew Lunn <[email protected]>
  27. Link: https://lore.kernel.org/r/[email protected]
  28. Signed-off-by: Lee Jones <[email protected]>
  29. ---
  30. drivers/leds/trigger/ledtrig-netdev.c | 4 ++--
  31. 1 file changed, 2 insertions(+), 2 deletions(-)
  32. --- a/drivers/leds/trigger/ledtrig-netdev.c
  33. +++ b/drivers/leds/trigger/ledtrig-netdev.c
  34. @@ -489,12 +489,12 @@ static int netdev_trig_notify(struct not
  35. trigger_data->duplex = DUPLEX_UNKNOWN;
  36. switch (evt) {
  37. case NETDEV_CHANGENAME:
  38. - get_device_state(trigger_data);
  39. - fallthrough;
  40. case NETDEV_REGISTER:
  41. dev_put(trigger_data->net_dev);
  42. dev_hold(dev);
  43. trigger_data->net_dev = dev;
  44. + if (evt == NETDEV_CHANGENAME)
  45. + get_device_state(trigger_data);
  46. break;
  47. case NETDEV_UNREGISTER:
  48. dev_put(trigger_data->net_dev);