Skip to content

Commit a0761a3

Browse files
committed
mac80211: drop data frames without key on encrypted links
If we know that we have an encrypted link (based on having had a key configured for TX in the past) then drop all data frames in the key selection handler if there's no key anymore. This fixes an issue with mac80211 internal TXQs - there we can buffer frames for an encrypted link, but then if the key is no longer there when they're dequeued, the frames are sent without encryption. This happens if a station is disconnected while the frames are still on the TXQ. Detecting that a link should be encrypted based on a first key having been configured for TX is fine as there are no use cases for a connection going from with encryption to no encryption. With extended key IDs, however, there is a case of having a key configured for only decryption, so we can't just trigger this behaviour on a key being configured. Cc: [email protected] Reported-by: Jouni Malinen <[email protected]> Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: Luca Coelho <[email protected]> Link: https://lore.kernel.org/r/iwlwifi.20200326150855.6865c7f28a14.I9fb1d911b064262d33e33dfba730cdeef83926ca@changeid Signed-off-by: Johannes Berg <[email protected]>
1 parent 575a97a commit a0761a3

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

net/mac80211/debugfs_sta.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright 2007 Johannes Berg <[email protected]>
66
* Copyright 2013-2014 Intel Mobile Communications GmbH
77
* Copyright(c) 2016 Intel Deutschland GmbH
8-
* Copyright (C) 2018 - 2019 Intel Corporation
8+
* Copyright (C) 2018 - 2020 Intel Corporation
99
*/
1010

1111
#include <linux/debugfs.h>
@@ -78,6 +78,7 @@ static const char * const sta_flag_names[] = {
7878
FLAG(MPSP_OWNER),
7979
FLAG(MPSP_RECIPIENT),
8080
FLAG(PS_DELIVER),
81+
FLAG(USES_ENCRYPTION),
8182
#undef FLAG
8283
};
8384

net/mac80211/key.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright 2007-2008 Johannes Berg <[email protected]>
77
* Copyright 2013-2014 Intel Mobile Communications GmbH
88
* Copyright 2015-2017 Intel Deutschland GmbH
9-
* Copyright 2018-2019 Intel Corporation
9+
* Copyright 2018-2020 Intel Corporation
1010
*/
1111

1212
#include <linux/if_ether.h>
@@ -262,22 +262,29 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
262262
sta ? sta->sta.addr : bcast_addr, ret);
263263
}
264264

265-
int ieee80211_set_tx_key(struct ieee80211_key *key)
265+
static int _ieee80211_set_tx_key(struct ieee80211_key *key, bool force)
266266
{
267267
struct sta_info *sta = key->sta;
268268
struct ieee80211_local *local = key->local;
269269

270270
assert_key_lock(local);
271271

272+
set_sta_flag(sta, WLAN_STA_USES_ENCRYPTION);
273+
272274
sta->ptk_idx = key->conf.keyidx;
273275

274-
if (!ieee80211_hw_check(&local->hw, AMPDU_KEYBORDER_SUPPORT))
276+
if (force || !ieee80211_hw_check(&local->hw, AMPDU_KEYBORDER_SUPPORT))
275277
clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
276278
ieee80211_check_fast_xmit(sta);
277279

278280
return 0;
279281
}
280282

283+
int ieee80211_set_tx_key(struct ieee80211_key *key)
284+
{
285+
return _ieee80211_set_tx_key(key, false);
286+
}
287+
281288
static void ieee80211_pairwise_rekey(struct ieee80211_key *old,
282289
struct ieee80211_key *new)
283290
{
@@ -441,11 +448,8 @@ static int ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
441448
if (pairwise) {
442449
rcu_assign_pointer(sta->ptk[idx], new);
443450
if (new &&
444-
!(new->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)) {
445-
sta->ptk_idx = idx;
446-
clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
447-
ieee80211_check_fast_xmit(sta);
448-
}
451+
!(new->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX))
452+
_ieee80211_set_tx_key(new, true);
449453
} else {
450454
rcu_assign_pointer(sta->gtk[idx], new);
451455
}

net/mac80211/sta_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ enum ieee80211_sta_info_flags {
9898
WLAN_STA_MPSP_OWNER,
9999
WLAN_STA_MPSP_RECIPIENT,
100100
WLAN_STA_PS_DELIVER,
101+
WLAN_STA_USES_ENCRYPTION,
101102

102103
NUM_WLAN_STA_FLAGS,
103104
};

net/mac80211/tx.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,13 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
590590
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
591591
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
592592

593-
if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
593+
if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) {
594594
tx->key = NULL;
595-
else if (tx->sta &&
596-
(key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
595+
return TX_CONTINUE;
596+
}
597+
598+
if (tx->sta &&
599+
(key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
597600
tx->key = key;
598601
else if (ieee80211_is_group_privacy_action(tx->skb) &&
599602
(key = rcu_dereference(tx->sdata->default_multicast_key)))
@@ -654,6 +657,9 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
654657
if (!skip_hw && tx->key &&
655658
tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
656659
info->control.hw_key = &tx->key->conf;
660+
} else if (!ieee80211_is_mgmt(hdr->frame_control) && tx->sta &&
661+
test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) {
662+
return TX_DROP;
657663
}
658664

659665
return TX_CONTINUE;

0 commit comments

Comments
 (0)