Skip to content

Commit 94034c4

Browse files
vanhoefmjmberg-intel
authored andcommitted
mac80211: prevent mixed key and fragment cache attacks
Simultaneously prevent mixed key attacks (CVE-2020-24587) and fragment cache attacks (CVE-2020-24586). This is accomplished by assigning a unique color to every key (per interface) and using this to track which key was used to decrypt a fragment. When reassembling frames, it is now checked whether all fragments were decrypted using the same key. To assure that fragment cache attacks are also prevented, the ID that is assigned to keys is unique even over (re)associations and (re)connects. This means fragments separated by a (re)association or (re)connect will not be reassembled. Because mac80211 now also prevents the reassembly of mixed encrypted and plaintext fragments, all cache attacks are prevented. Cc: stable@vger.kernel.org Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@kuleuven.be> Link: https://lore.kernel.org/r/20210511200110.3f8290e59823.I622a67769ed39257327a362cfc09c812320eb979@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 965a7d7 commit 94034c4

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎net/mac80211/ieee80211_i.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ struct ieee80211_fragment_entry {
9797
u8 rx_queue;
9898
bool check_sequential_pn; /* needed for CCMP/GCMP */
9999
u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
100+
unsigned int key_color;
100101
};
101102

102103

‎net/mac80211/key.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
799799
struct ieee80211_sub_if_data *sdata,
800800
struct sta_info *sta)
801801
{
802+
static atomic_t key_color = ATOMIC_INIT(0);
802803
struct ieee80211_key *old_key;
803804
int idx = key->conf.keyidx;
804805
bool pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
@@ -850,6 +851,12 @@ int ieee80211_key_link(struct ieee80211_key *key,
850851
key->sdata = sdata;
851852
key->sta = sta;
852853

854+
/*
855+
* Assign a unique ID to every key so we can easily prevent mixed
856+
* key and fragment cache attacks.
857+
*/
858+
key->color = atomic_inc_return(&key_color);
859+
853860
increment_tailroom_need_count(sdata);
854861

855862
ret = ieee80211_key_replace(sdata, sta, pairwise, old_key, key);

‎net/mac80211/key.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ struct ieee80211_key {
128128
} debugfs;
129129
#endif
130130

131+
unsigned int color;
132+
131133
/*
132134
* key config, must be last because it contains key
133135
* material as variable length member

‎net/mac80211/rx.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
22552255
* next fragment has a sequential PN value.
22562256
*/
22572257
entry->check_sequential_pn = true;
2258+
entry->key_color = rx->key->color;
22582259
memcpy(entry->last_pn,
22592260
rx->key->u.ccmp.rx_pn[queue],
22602261
IEEE80211_CCMP_PN_LEN);
@@ -2292,6 +2293,11 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
22922293

22932294
if (!requires_sequential_pn(rx, fc))
22942295
return RX_DROP_UNUSABLE;
2296+
2297+
/* Prevent mixed key and fragment cache attacks */
2298+
if (entry->key_color != rx->key->color)
2299+
return RX_DROP_UNUSABLE;
2300+
22952301
memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
22962302
for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
22972303
pn[i]++;

0 commit comments

Comments
 (0)