390-mac80211-fix-a-race-between-restart-and-CSA-flows.patch 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From: Emmanuel Grumbach <[email protected]>
  2. Date: Fri, 31 Aug 2018 11:31:06 +0300
  3. Subject: [PATCH] mac80211: fix a race between restart and CSA flows
  4. We hit a problem with iwlwifi that was caused by a bug in
  5. mac80211. A bug in iwlwifi caused the firwmare to crash in
  6. certain cases in channel switch. Because of that bug,
  7. drv_pre_channel_switch would fail and trigger the restart
  8. flow.
  9. Now we had the hw restart worker which runs on the system's
  10. workqueue and the csa_connection_drop_work worker that runs
  11. on mac80211's workqueue that can run together. This is
  12. obviously problematic since the restart work wants to
  13. reconfigure the connection, while the csa_connection_drop_work
  14. worker does the exact opposite: it tries to disconnect.
  15. Fix this by cancelling the csa_connection_drop_work worker
  16. in the restart worker.
  17. Note that this can sound racy: we could have:
  18. driver iface_work CSA_work restart_work
  19. +++++++++++++++++++++++++++++++++++++++++++++
  20. |
  21. <--drv_cs ---|
  22. <FW CRASH!>
  23. -CS FAILED-->
  24. | |
  25. | cancel_work(CSA)
  26. schedule |
  27. CSA work |
  28. | |
  29. Race between those 2
  30. But this is not possible because we flush the workqueue
  31. in the restart worker before we cancel the CSA worker.
  32. That would be bullet proof if we could guarantee that
  33. we schedule the CSA worker only from the iface_work
  34. which runs on the workqueue (and not on the system's
  35. workqueue), but unfortunately we do have an instance
  36. in which we schedule the CSA work outside the context
  37. of the workqueue (ieee80211_chswitch_done).
  38. Note also that we should probably cancel other workers
  39. like beacon_connection_loss_work and possibly others
  40. for different types of interfaces, at the very least,
  41. IBSS should suffer from the exact same problem, but for
  42. now, do the minimum to fix the actual bug that was actually
  43. experienced and reproduced.
  44. Signed-off-by: Emmanuel Grumbach <[email protected]>
  45. Signed-off-by: Luca Coelho <[email protected]>
  46. Signed-off-by: Johannes Berg <[email protected]>
  47. ---
  48. --- a/net/mac80211/main.c
  49. +++ b/net/mac80211/main.c
  50. @@ -255,8 +255,27 @@ static void ieee80211_restart_work(struc
  51. flush_work(&local->radar_detected_work);
  52. rtnl_lock();
  53. - list_for_each_entry(sdata, &local->interfaces, list)
  54. + list_for_each_entry(sdata, &local->interfaces, list) {
  55. + /*
  56. + * XXX: there may be more work for other vif types and even
  57. + * for station mode: a good thing would be to run most of
  58. + * the iface type's dependent _stop (ieee80211_mg_stop,
  59. + * ieee80211_ibss_stop) etc...
  60. + * For now, fix only the specific bug that was seen: race
  61. + * between csa_connection_drop_work and us.
  62. + */
  63. + if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  64. + /*
  65. + * This worker is scheduled from the iface worker that
  66. + * runs on mac80211's workqueue, so we can't be
  67. + * scheduling this worker after the cancel right here.
  68. + * The exception is ieee80211_chswitch_done.
  69. + * Then we can have a race...
  70. + */
  71. + cancel_work_sync(&sdata->u.mgd.csa_connection_drop_work);
  72. + }
  73. flush_delayed_work(&sdata->dec_tailroom_needed_wk);
  74. + }
  75. ieee80211_scan_cancel(local);
  76. /* make sure any new ROC will consider local->in_reconfig */