Protect vif->scan_req with a spinlock to serialize scan submission, completion, disconnect, and interface-stop paths. This prevents scan completion and abort handling from notifying cfg80211 more than once or accessing a cleared scan request. Without synchronization, one thread can set scan_req to NULL while another dereferences it, causing a kernel panic. Signed-off-by: Vishal Gupta Signed-off-by: Uwe Schnick --- drivers/net/wireless/ath/ath6kl/cfg80211.c | 45 ++++++++++++++++------ drivers/net/wireless/ath/ath6kl/core.h | 2 + 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c index 8bbe554a9b364..19934c357a98b 100644 --- a/drivers/net/wireless/ath/ath6kl/cfg80211.c +++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c @@ -866,14 +866,20 @@ void ath6kl_cfg80211_disconnect_event(struct ath6kl_vif *vif, u8 reason, u8 *assoc_info, u16 proto_reason) { struct ath6kl *ar = vif->ar; + struct cfg80211_scan_request *req; - if (vif->scan_req) { + spin_lock_bh(&vif->scan_req_lock); + req = vif->scan_req; + vif->scan_req = NULL; + spin_unlock_bh(&vif->scan_req_lock); + + if (req) { struct cfg80211_scan_info info = { .aborted = true, }; - cfg80211_scan_done(vif->scan_req, &info); - vif->scan_req = NULL; + cfg80211_scan_done(req, &info); + req = NULL; } if (vif->nw_type & ADHOC_NETWORK) { @@ -1060,7 +1066,9 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, if (test_bit(CONNECTED, &vif->flags)) force_fg_scan = 1; + spin_lock_bh(&vif->scan_req_lock); vif->scan_req = request; + spin_unlock_bh(&vif->scan_req_lock); ret = ath6kl_wmi_beginscan_cmd(ar->wmi, vif->fw_vif_idx, WMI_LONG_SCAN, force_fg_scan, @@ -1071,7 +1079,9 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, request->rates); if (ret) { ath6kl_err("failed to start scan: %d\n", ret); + spin_lock_bh(&vif->scan_req_lock); vif->scan_req = NULL; + spin_unlock_bh(&vif->scan_req_lock); } kfree(channels); @@ -1082,6 +1092,7 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted) { struct ath6kl *ar = vif->ar; + struct cfg80211_scan_request *req; struct cfg80211_scan_info info = { .aborted = aborted, }; @@ -1090,14 +1101,19 @@ void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted) ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: status%s\n", __func__, aborted ? " aborted" : ""); - if (!vif->scan_req) + spin_lock_bh(&vif->scan_req_lock); + req = vif->scan_req; + vif->scan_req = NULL; + spin_unlock_bh(&vif->scan_req_lock); + + if (!req) return; if (aborted) goto out; - if (vif->scan_req->n_ssids && vif->scan_req->ssids[0].ssid_len) { - for (i = 0; i < vif->scan_req->n_ssids; i++) { + if (req->n_ssids && req->ssids[0].ssid_len) { + for (i = 0; i < req->n_ssids; i++) { ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx, i, DISABLE_SSID_FLAG, 0, NULL); @@ -1105,8 +1121,8 @@ void ath6kl_cfg80211_scan_complete_event(struct ath6kl_vif *vif, bool aborted) } out: - cfg80211_scan_done(vif->scan_req, &info); - vif->scan_req = NULL; + cfg80211_scan_done(req, &info); + req = NULL; } void ath6kl_cfg80211_ch_switch_notify(struct ath6kl_vif *vif, int freq, @@ -3599,6 +3615,7 @@ static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif) set_bit(WMM_ENABLED, &vif->flags); spin_lock_init(&vif->if_lock); + spin_lock_init(&vif->scan_req_lock); INIT_LIST_HEAD(&vif->mc_filter); @@ -3607,6 +3624,7 @@ static int ath6kl_cfg80211_vif_init(struct ath6kl_vif *vif) void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready) { + struct cfg80211_scan_request *req; static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; bool discon_issued; @@ -3627,13 +3645,18 @@ void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready) 0, NULL, 0); } - if (vif->scan_req) { + spin_lock_bh(&vif->scan_req_lock); + req = vif->scan_req; + vif->scan_req = NULL; + spin_unlock_bh(&vif->scan_req_lock); + + if (req) { struct cfg80211_scan_info info = { .aborted = true, }; - cfg80211_scan_done(vif->scan_req, &info); - vif->scan_req = NULL; + cfg80211_scan_done(req, &info); + req = NULL; } /* need to clean up enhanced bmiss detection fw state */ diff --git a/drivers/net/wireless/ath/ath6kl/core.h b/drivers/net/wireless/ath/ath6kl/core.h index a0b236eeeab54..522844e758202 100644 --- a/drivers/net/wireless/ath/ath6kl/core.h +++ b/drivers/net/wireless/ath/ath6kl/core.h @@ -647,6 +647,8 @@ struct ath6kl_vif { u16 rsn_capab; struct list_head mc_filter; + /* Lock to protect scan_req */ + spinlock_t scan_req_lock; }; static inline struct ath6kl_vif *ath6kl_vif_from_wdev(struct wireless_dev *wdev) -- 2.43.0