Skip to content

Commit bf30ca9

Browse files
committed
mac80211: check defrag PN against current frame
As pointed out by Mathy Vanhoef, we implement the RX PN check on fragmented frames incorrectly - we check against the last received PN prior to the new frame, rather than to the one in this frame itself. Prior patches addressed the security issue here, but in order to be able to reason better about the code, fix it to really compare against the current frame's PN, not the last stored one. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210511200110.bfbc340ff071.Id0b690e581da7d03d76df90bb0e3fd55930bc8a0@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 3a11ce0 commit bf30ca9

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎net/mac80211/ieee80211_i.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,15 @@ struct ieee80211_rx_data {
223223
*/
224224
int security_idx;
225225

226-
u32 tkip_iv32;
227-
u16 tkip_iv16;
226+
union {
227+
struct {
228+
u32 iv32;
229+
u16 iv16;
230+
} tkip;
231+
struct {
232+
u8 pn[IEEE80211_CCMP_PN_LEN];
233+
} ccm_gcm;
234+
};
228235
};
229236

230237
struct ieee80211_csa_settings {

‎net/mac80211/rx.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,6 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
23082308
if (entry->check_sequential_pn) {
23092309
int i;
23102310
u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
2311-
int queue;
23122311

23132312
if (!requires_sequential_pn(rx, fc))
23142313
return RX_DROP_UNUSABLE;
@@ -2323,8 +2322,8 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
23232322
if (pn[i])
23242323
break;
23252324
}
2326-
queue = rx->security_idx;
2327-
rpn = rx->key->u.ccmp.rx_pn[queue];
2325+
2326+
rpn = rx->ccm_gcm.pn;
23282327
if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
23292328
return RX_DROP_UNUSABLE;
23302329
memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);

‎net/mac80211/wpa.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright 2002-2004, Instant802 Networks, Inc.
44
* Copyright 2008, Jouni Malinen <j@w1.fi>
55
* Copyright (C) 2016-2017 Intel Deutschland GmbH
6+
* Copyright (C) 2020-2021 Intel Corporation
67
*/
78

89
#include <linux/netdevice.h>
@@ -167,8 +168,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
167168

168169
update_iv:
169170
/* update IV in key information to be able to detect replays */
170-
rx->key->u.tkip.rx[rx->security_idx].iv32 = rx->tkip_iv32;
171-
rx->key->u.tkip.rx[rx->security_idx].iv16 = rx->tkip_iv16;
171+
rx->key->u.tkip.rx[rx->security_idx].iv32 = rx->tkip.iv32;
172+
rx->key->u.tkip.rx[rx->security_idx].iv16 = rx->tkip.iv16;
172173

173174
return RX_CONTINUE;
174175

@@ -294,8 +295,8 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
294295
key, skb->data + hdrlen,
295296
skb->len - hdrlen, rx->sta->sta.addr,
296297
hdr->addr1, hwaccel, rx->security_idx,
297-
&rx->tkip_iv32,
298-
&rx->tkip_iv16);
298+
&rx->tkip.iv32,
299+
&rx->tkip.iv16);
299300
if (res != TKIP_DECRYPT_OK)
300301
return RX_DROP_UNUSABLE;
301302

@@ -553,6 +554,8 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx,
553554
}
554555

555556
memcpy(key->u.ccmp.rx_pn[queue], pn, IEEE80211_CCMP_PN_LEN);
557+
if (unlikely(ieee80211_is_frag(hdr)))
558+
memcpy(rx->ccm_gcm.pn, pn, IEEE80211_CCMP_PN_LEN);
556559
}
557560

558561
/* Remove CCMP header and MIC */
@@ -781,6 +784,8 @@ ieee80211_crypto_gcmp_decrypt(struct ieee80211_rx_data *rx)
781784
}
782785

783786
memcpy(key->u.gcmp.rx_pn[queue], pn, IEEE80211_GCMP_PN_LEN);
787+
if (unlikely(ieee80211_is_frag(hdr)))
788+
memcpy(rx->ccm_gcm.pn, pn, IEEE80211_CCMP_PN_LEN);
784789
}
785790

786791
/* Remove GCMP header and MIC */

0 commit comments

Comments
 (0)