Skip to content

Commit d8ca16d

Browse files
committed
mac80211: add length check in ieee80211_is_robust_mgmt_frame()
A few places weren't checking that the frame passed to the function actually has enough data even though the function clearly documents it must have a payload byte. Make this safer by changing the function to take an skb and checking the length inside. The old version is preserved for now as the rtl* drivers use it and don't have a correct skb. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent ae811e2 commit d8ca16d

8 files changed

Lines changed: 28 additions & 19 deletions

File tree

‎drivers/net/wireless/rtlwifi/rtl8188ee/trx.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw,
452452
/* During testing, hdr was NULL */
453453
return false;
454454
}
455-
if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
455+
if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
456456
(ieee80211_has_protected(hdr->frame_control)))
457457
rx_status->flag &= ~RX_FLAG_DECRYPTED;
458458
else

‎drivers/net/wireless/rtlwifi/rtl8192ce/trx.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw,
393393
/* In testing, hdr was NULL here */
394394
return false;
395395
}
396-
if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
396+
if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
397397
(ieee80211_has_protected(hdr->frame_control)))
398398
rx_status->flag &= ~RX_FLAG_DECRYPTED;
399399
else

‎drivers/net/wireless/rtlwifi/rtl8192se/trx.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
310310
/* during testing, hdr was NULL here */
311311
return false;
312312
}
313-
if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
313+
if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
314314
(ieee80211_has_protected(hdr->frame_control)))
315315
rx_status->flag &= ~RX_FLAG_DECRYPTED;
316316
else

‎drivers/net/wireless/rtlwifi/rtl8723ae/trx.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool rtl8723ae_rx_query_desc(struct ieee80211_hw *hw,
334334
/* during testing, hdr could be NULL here */
335335
return false;
336336
}
337-
if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
337+
if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
338338
(ieee80211_has_protected(hdr->frame_control)))
339339
rx_status->flag &= ~RX_FLAG_DECRYPTED;
340340
else

‎include/linux/ieee80211.h‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,10 +2192,10 @@ static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
21922192
}
21932193

21942194
/**
2195-
* ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
2195+
* _ieee80211_is_robust_mgmt_frame - check if frame is a robust management frame
21962196
* @hdr: the frame (buffer must include at least the first octet of payload)
21972197
*/
2198-
static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
2198+
static inline bool _ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
21992199
{
22002200
if (ieee80211_is_disassoc(hdr->frame_control) ||
22012201
ieee80211_is_deauth(hdr->frame_control))
@@ -2223,6 +2223,17 @@ static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
22232223
return false;
22242224
}
22252225

2226+
/**
2227+
* ieee80211_is_robust_mgmt_frame - check if skb contains a robust mgmt frame
2228+
* @skb: the skb containing the frame, length will be checked
2229+
*/
2230+
static inline bool ieee80211_is_robust_mgmt_frame(struct sk_buff *skb)
2231+
{
2232+
if (skb->len < 25)
2233+
return false;
2234+
return _ieee80211_is_robust_mgmt_frame((void *)skb->data);
2235+
}
2236+
22262237
/**
22272238
* ieee80211_is_public_action - check if frame is a public action frame
22282239
* @hdr: the frame

‎net/mac80211/rx.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,21 @@ static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
599599
{
600600
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
601601

602-
if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
602+
if (is_multicast_ether_addr(hdr->addr1))
603603
return 0;
604604

605-
return ieee80211_is_robust_mgmt_frame(hdr);
605+
return ieee80211_is_robust_mgmt_frame(skb);
606606
}
607607

608608

609609
static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
610610
{
611611
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
612612

613-
if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
613+
if (!is_multicast_ether_addr(hdr->addr1))
614614
return 0;
615615

616-
return ieee80211_is_robust_mgmt_frame(hdr);
616+
return ieee80211_is_robust_mgmt_frame(skb);
617617
}
618618

619619

@@ -626,7 +626,7 @@ static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
626626
if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
627627
return -1;
628628

629-
if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
629+
if (!ieee80211_is_robust_mgmt_frame(skb))
630630
return -1; /* not a robust management frame */
631631

632632
mmie = (struct ieee80211_mmie *)
@@ -1845,8 +1845,7 @@ static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
18451845
* having configured keys.
18461846
*/
18471847
if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1848-
ieee80211_is_robust_mgmt_frame(
1849-
(struct ieee80211_hdr *) rx->skb->data)))
1848+
ieee80211_is_robust_mgmt_frame(rx->skb)))
18501849
return -EACCES;
18511850
}
18521851

‎net/mac80211/tx.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,7 @@ static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
452452
if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
453453
return 0;
454454

455-
if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
456-
skb->data))
455+
if (!ieee80211_is_robust_mgmt_frame(skb))
457456
return 0;
458457

459458
return 1;
@@ -567,7 +566,7 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
567566
tx->key = key;
568567
else if (ieee80211_is_mgmt(hdr->frame_control) &&
569568
is_multicast_ether_addr(hdr->addr1) &&
570-
ieee80211_is_robust_mgmt_frame(hdr) &&
569+
ieee80211_is_robust_mgmt_frame(tx->skb) &&
571570
(key = rcu_dereference(tx->sdata->default_mgmt_key)))
572571
tx->key = key;
573572
else if (is_multicast_ether_addr(hdr->addr1) &&
@@ -582,12 +581,12 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
582581
tx->key = NULL;
583582
else if (tx->skb->protocol == tx->sdata->control_port_protocol)
584583
tx->key = NULL;
585-
else if (ieee80211_is_robust_mgmt_frame(hdr) &&
584+
else if (ieee80211_is_robust_mgmt_frame(tx->skb) &&
586585
!(ieee80211_is_action(hdr->frame_control) &&
587586
tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))
588587
tx->key = NULL;
589588
else if (ieee80211_is_mgmt(hdr->frame_control) &&
590-
!ieee80211_is_robust_mgmt_frame(hdr))
589+
!ieee80211_is_robust_mgmt_frame(tx->skb))
591590
tx->key = NULL;
592591
else {
593592
I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);

‎net/mac80211/wpa.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
494494
hdrlen = ieee80211_hdrlen(hdr->frame_control);
495495

496496
if (!ieee80211_is_data(hdr->frame_control) &&
497-
!ieee80211_is_robust_mgmt_frame(hdr))
497+
!ieee80211_is_robust_mgmt_frame(skb))
498498
return RX_CONTINUE;
499499

500500
data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN -

0 commit comments

Comments
 (0)