Skip to content

Commit 6818266

Browse files
ggreenmajmberg-intel
authored andcommitted
wifi: iwlwifi: mvm: fix access to fw_id_to_mac_id
RCU protected fw_id_to_mac_id can be initialized with either an error code or NULL. Thus, after dereferencing need to check the value with IS_ERR_OR_NULL() and not only that it is not NULL. Fix it. Signed-off-by: Gregory Greenman <[email protected]> Link: https://lore.kernel.org/r/20230514120631.ec5f2880e81c.Ifa8c0f451df2835bde800f5c3670cc46238a3bd8@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent d3ae691 commit 6818266

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

drivers/net/wireless/intel/iwlwifi/mvm/ftm-initiator.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,11 @@ iwl_mvm_ftm_put_target(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
526526
rcu_read_lock();
527527

528528
sta = rcu_dereference(mvm->fw_id_to_mac_id[mvmvif->deflink.ap_sta_id]);
529+
if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
530+
rcu_read_unlock();
531+
return PTR_ERR_OR_ZERO(sta);
532+
}
533+
529534
if (sta->mfp && (peer->ftm.trigger_based || peer->ftm.non_trigger_based))
530535
FTM_PUT_FLAG(PMF);
531536

drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,11 @@ void iwl_mvm_reorder_timer_expired(struct timer_list *t)
691691

692692
rcu_read_lock();
693693
sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]);
694+
if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
695+
rcu_read_unlock();
696+
goto out;
697+
}
698+
694699
mvmsta = iwl_mvm_sta_from_mac80211(sta);
695700

696701
/* SN is set to the last expired frame + 1 */
@@ -712,6 +717,8 @@ void iwl_mvm_reorder_timer_expired(struct timer_list *t)
712717
entries[index].e.reorder_time +
713718
1 + RX_REORDER_BUF_TIMEOUT_MQ);
714719
}
720+
721+
out:
715722
spin_unlock(&buf->lock);
716723
}
717724

drivers/net/wireless/intel/iwlwifi/mvm/sta.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static void iwl_mvm_rx_agg_session_expired(struct timer_list *t)
281281
* A-MDPU and hence the timer continues to run. Then, the
282282
* timer expires and sta is NULL.
283283
*/
284-
if (!sta)
284+
if (IS_ERR_OR_NULL(sta))
285285
goto unlock;
286286

287287
mvm_sta = iwl_mvm_sta_from_mac80211(sta);
@@ -3782,6 +3782,9 @@ static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
37823782
u8 sta_id = mvmvif->deflink.ap_sta_id;
37833783
sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
37843784
lockdep_is_held(&mvm->mutex));
3785+
if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
3786+
return NULL;
3787+
37853788
return sta->addr;
37863789
}
37873790

@@ -3819,6 +3822,11 @@ static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
38193822

38203823
if (keyconf->cipher == WLAN_CIPHER_SUITE_TKIP) {
38213824
addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
3825+
if (!addr) {
3826+
IWL_ERR(mvm, "Failed to find mac address\n");
3827+
return -EINVAL;
3828+
}
3829+
38223830
/* get phase 1 key from mac80211 */
38233831
ieee80211_get_key_rx_seq(keyconf, 0, &seq);
38243832
ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);

drivers/net/wireless/intel/iwlwifi/mvm/tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ static void iwl_mvm_rx_tx_cmd_agg(struct iwl_mvm *mvm,
18751875
mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, sta_id);
18761876

18771877
sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1878-
if (WARN_ON_ONCE(!sta || !sta->wme)) {
1878+
if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta) || !sta->wme)) {
18791879
rcu_read_unlock();
18801880
return;
18811881
}

0 commit comments

Comments
 (0)