diff options
| author | Johannes Berg <johannes.berg@intel.com> | 2014-01-23 10:20:29 -0500 |
|---|---|---|
| committer | Johannes Berg <johannes.berg@intel.com> | 2014-02-04 15:58:07 -0500 |
| commit | d8ca16db6bb23d03fcb794df44bae64ae976f27c (patch) | |
| tree | f577a829374c0f9daba8bf70e1ea3d6ac107089c | |
| parent | ae811e21df28deb4c2adab0a47fc3da4f56d777b (diff) | |
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>
| -rw-r--r-- | drivers/net/wireless/rtlwifi/rtl8188ee/trx.c | 2 | ||||
| -rw-r--r-- | drivers/net/wireless/rtlwifi/rtl8192ce/trx.c | 2 | ||||
| -rw-r--r-- | drivers/net/wireless/rtlwifi/rtl8192se/trx.c | 2 | ||||
| -rw-r--r-- | drivers/net/wireless/rtlwifi/rtl8723ae/trx.c | 2 | ||||
| -rw-r--r-- | include/linux/ieee80211.h | 15 | ||||
| -rw-r--r-- | net/mac80211/rx.c | 13 | ||||
| -rw-r--r-- | net/mac80211/tx.c | 9 | ||||
| -rw-r--r-- | net/mac80211/wpa.c | 2 |
8 files changed, 28 insertions, 19 deletions
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c index aece6c9cccf1..27ace3054d56 100644 --- a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c +++ b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c | |||
| @@ -452,7 +452,7 @@ bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw, | |||
| 452 | /* During testing, hdr was NULL */ | 452 | /* During testing, hdr was NULL */ |
| 453 | return false; | 453 | return false; |
| 454 | } | 454 | } |
| 455 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && | 455 | if ((_ieee80211_is_robust_mgmt_frame(hdr)) && |
| 456 | (ieee80211_has_protected(hdr->frame_control))) | 456 | (ieee80211_has_protected(hdr->frame_control))) |
| 457 | rx_status->flag &= ~RX_FLAG_DECRYPTED; | 457 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
| 458 | else | 458 | else |
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c index 52abf0a862fa..114858d46158 100644 --- a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c +++ b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c | |||
| @@ -393,7 +393,7 @@ bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw, | |||
| 393 | /* In testing, hdr was NULL here */ | 393 | /* In testing, hdr was NULL here */ |
| 394 | return false; | 394 | return false; |
| 395 | } | 395 | } |
| 396 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && | 396 | if ((_ieee80211_is_robust_mgmt_frame(hdr)) && |
| 397 | (ieee80211_has_protected(hdr->frame_control))) | 397 | (ieee80211_has_protected(hdr->frame_control))) |
| 398 | rx_status->flag &= ~RX_FLAG_DECRYPTED; | 398 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
| 399 | else | 399 | else |
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/trx.c b/drivers/net/wireless/rtlwifi/rtl8192se/trx.c index 27efbcdac6a9..163a681962c6 100644 --- a/drivers/net/wireless/rtlwifi/rtl8192se/trx.c +++ b/drivers/net/wireless/rtlwifi/rtl8192se/trx.c | |||
| @@ -310,7 +310,7 @@ bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats, | |||
| 310 | /* during testing, hdr was NULL here */ | 310 | /* during testing, hdr was NULL here */ |
| 311 | return false; | 311 | return false; |
| 312 | } | 312 | } |
| 313 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && | 313 | if ((_ieee80211_is_robust_mgmt_frame(hdr)) && |
| 314 | (ieee80211_has_protected(hdr->frame_control))) | 314 | (ieee80211_has_protected(hdr->frame_control))) |
| 315 | rx_status->flag &= ~RX_FLAG_DECRYPTED; | 315 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
| 316 | else | 316 | else |
diff --git a/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c b/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c index 50b7be3f3a60..721162cacc3a 100644 --- a/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c +++ b/drivers/net/wireless/rtlwifi/rtl8723ae/trx.c | |||
| @@ -334,7 +334,7 @@ bool rtl8723ae_rx_query_desc(struct ieee80211_hw *hw, | |||
| 334 | /* during testing, hdr could be NULL here */ | 334 | /* during testing, hdr could be NULL here */ |
| 335 | return false; | 335 | return false; |
| 336 | } | 336 | } |
| 337 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && | 337 | if ((_ieee80211_is_robust_mgmt_frame(hdr)) && |
| 338 | (ieee80211_has_protected(hdr->frame_control))) | 338 | (ieee80211_has_protected(hdr->frame_control))) |
| 339 | rx_status->flag &= ~RX_FLAG_DECRYPTED; | 339 | rx_status->flag &= ~RX_FLAG_DECRYPTED; |
| 340 | else | 340 | else |
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h index e526a8cecb70..923c478030a3 100644 --- a/include/linux/ieee80211.h +++ b/include/linux/ieee80211.h | |||
| @@ -2192,10 +2192,10 @@ static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr) | |||
| 2192 | } | 2192 | } |
| 2193 | 2193 | ||
| 2194 | /** | 2194 | /** |
| 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 |
| 2196 | * @hdr: the frame (buffer must include at least the first octet of payload) | 2196 | * @hdr: the frame (buffer must include at least the first octet of payload) |
| 2197 | */ | 2197 | */ |
| 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) |
| 2199 | { | 2199 | { |
| 2200 | if (ieee80211_is_disassoc(hdr->frame_control) || | 2200 | if (ieee80211_is_disassoc(hdr->frame_control) || |
| 2201 | ieee80211_is_deauth(hdr->frame_control)) | 2201 | ieee80211_is_deauth(hdr->frame_control)) |
| @@ -2224,6 +2224,17 @@ static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr) | |||
| 2224 | } | 2224 | } |
| 2225 | 2225 | ||
| 2226 | /** | 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 | |||
| 2237 | /** | ||
| 2227 | * ieee80211_is_public_action - check if frame is a public action frame | 2238 | * ieee80211_is_public_action - check if frame is a public action frame |
| 2228 | * @hdr: the frame | 2239 | * @hdr: the frame |
| 2229 | * @len: length of the frame | 2240 | * @len: length of the frame |
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index c24ca0d0f469..3b7a750ebc70 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c | |||
| @@ -599,10 +599,10 @@ static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb) | |||
| 599 | { | 599 | { |
| 600 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 600 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 601 | 601 | ||
| 602 | if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1)) | 602 | if (is_multicast_ether_addr(hdr->addr1)) |
| 603 | return 0; | 603 | return 0; |
| 604 | 604 | ||
| 605 | return ieee80211_is_robust_mgmt_frame(hdr); | 605 | return ieee80211_is_robust_mgmt_frame(skb); |
| 606 | } | 606 | } |
| 607 | 607 | ||
| 608 | 608 | ||
| @@ -610,10 +610,10 @@ static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb) | |||
| 610 | { | 610 | { |
| 611 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | 611 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 612 | 612 | ||
| 613 | if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1)) | 613 | if (!is_multicast_ether_addr(hdr->addr1)) |
| 614 | return 0; | 614 | return 0; |
| 615 | 615 | ||
| 616 | return ieee80211_is_robust_mgmt_frame(hdr); | 616 | return ieee80211_is_robust_mgmt_frame(skb); |
| 617 | } | 617 | } |
| 618 | 618 | ||
| 619 | 619 | ||
| @@ -626,7 +626,7 @@ static int ieee80211_get_mmie_keyidx(struct sk_buff *skb) | |||
| 626 | if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da)) | 626 | if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da)) |
| 627 | return -1; | 627 | return -1; |
| 628 | 628 | ||
| 629 | if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr)) | 629 | if (!ieee80211_is_robust_mgmt_frame(skb)) |
| 630 | return -1; /* not a robust management frame */ | 630 | return -1; /* not a robust management frame */ |
| 631 | 631 | ||
| 632 | mmie = (struct ieee80211_mmie *) | 632 | mmie = (struct ieee80211_mmie *) |
| @@ -1845,8 +1845,7 @@ static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx) | |||
| 1845 | * having configured keys. | 1845 | * having configured keys. |
| 1846 | */ | 1846 | */ |
| 1847 | if (unlikely(ieee80211_is_action(fc) && !rx->key && | 1847 | if (unlikely(ieee80211_is_action(fc) && !rx->key && |
| 1848 | ieee80211_is_robust_mgmt_frame( | 1848 | ieee80211_is_robust_mgmt_frame(rx->skb))) |
| 1849 | (struct ieee80211_hdr *) rx->skb->data))) | ||
| 1850 | return -EACCES; | 1849 | return -EACCES; |
| 1851 | } | 1850 | } |
| 1852 | 1851 | ||
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index bb990ecfa655..07a7f38dc348 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c | |||
| @@ -452,8 +452,7 @@ static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta, | |||
| 452 | if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP)) | 452 | if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP)) |
| 453 | return 0; | 453 | return 0; |
| 454 | 454 | ||
| 455 | if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) | 455 | if (!ieee80211_is_robust_mgmt_frame(skb)) |
| 456 | skb->data)) | ||
| 457 | return 0; | 456 | return 0; |
| 458 | 457 | ||
| 459 | return 1; | 458 | return 1; |
| @@ -567,7 +566,7 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) | |||
| 567 | tx->key = key; | 566 | tx->key = key; |
| 568 | else if (ieee80211_is_mgmt(hdr->frame_control) && | 567 | else if (ieee80211_is_mgmt(hdr->frame_control) && |
| 569 | is_multicast_ether_addr(hdr->addr1) && | 568 | is_multicast_ether_addr(hdr->addr1) && |
| 570 | ieee80211_is_robust_mgmt_frame(hdr) && | 569 | ieee80211_is_robust_mgmt_frame(tx->skb) && |
| 571 | (key = rcu_dereference(tx->sdata->default_mgmt_key))) | 570 | (key = rcu_dereference(tx->sdata->default_mgmt_key))) |
| 572 | tx->key = key; | 571 | tx->key = key; |
| 573 | else if (is_multicast_ether_addr(hdr->addr1) && | 572 | else if (is_multicast_ether_addr(hdr->addr1) && |
| @@ -582,12 +581,12 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) | |||
| 582 | tx->key = NULL; | 581 | tx->key = NULL; |
| 583 | else if (tx->skb->protocol == tx->sdata->control_port_protocol) | 582 | else if (tx->skb->protocol == tx->sdata->control_port_protocol) |
| 584 | tx->key = NULL; | 583 | tx->key = NULL; |
| 585 | else if (ieee80211_is_robust_mgmt_frame(hdr) && | 584 | else if (ieee80211_is_robust_mgmt_frame(tx->skb) && |
| 586 | !(ieee80211_is_action(hdr->frame_control) && | 585 | !(ieee80211_is_action(hdr->frame_control) && |
| 587 | tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP))) | 586 | tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP))) |
| 588 | tx->key = NULL; | 587 | tx->key = NULL; |
| 589 | else if (ieee80211_is_mgmt(hdr->frame_control) && | 588 | else if (ieee80211_is_mgmt(hdr->frame_control) && |
| 590 | !ieee80211_is_robust_mgmt_frame(hdr)) | 589 | !ieee80211_is_robust_mgmt_frame(tx->skb)) |
| 591 | tx->key = NULL; | 590 | tx->key = NULL; |
| 592 | else { | 591 | else { |
| 593 | I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted); | 592 | I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted); |
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c index 4aed45c8ee3b..b8600e3c29c8 100644 --- a/net/mac80211/wpa.c +++ b/net/mac80211/wpa.c | |||
| @@ -494,7 +494,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx) | |||
| 494 | hdrlen = ieee80211_hdrlen(hdr->frame_control); | 494 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 495 | 495 | ||
| 496 | if (!ieee80211_is_data(hdr->frame_control) && | 496 | if (!ieee80211_is_data(hdr->frame_control) && |
| 497 | !ieee80211_is_robust_mgmt_frame(hdr)) | 497 | !ieee80211_is_robust_mgmt_frame(skb)) |
| 498 | return RX_CONTINUE; | 498 | return RX_CONTINUE; |
| 499 | 499 | ||
| 500 | data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN - | 500 | data_len = skb->len - hdrlen - IEEE80211_CCMP_HDR_LEN - |
