Skip to content

Commit bddc0c4

Browse files
vanhoefmjmberg-intel
authored andcommitted
mac80211: Fix NULL ptr deref for injected rate info
The commit cb17ed2 ("mac80211: parse radiotap header when selecting Tx queue") moved the code to validate the radiotap header from ieee80211_monitor_start_xmit to ieee80211_parse_tx_radiotap. This made is possible to share more code with the new Tx queue selection code for injected frames. But at the same time, it now required the call of ieee80211_parse_tx_radiotap at the beginning of functions which wanted to handle the radiotap header. And this broke the rate parser for radiotap header parser. The radiotap parser for rates is operating most of the time only on the data in the actual radiotap header. But for the 802.11a/b/g rates, it must also know the selected band from the chandef information. But this information is only written to the ieee80211_tx_info at the end of the ieee80211_monitor_start_xmit - long after ieee80211_parse_tx_radiotap was already called. The info->band information was therefore always 0 (NL80211_BAND_2GHZ) when the parser code tried to access it. For a 5GHz only device, injecting a frame with 802.11a rates would cause a NULL pointer dereference because local->hw.wiphy->bands[NL80211_BAND_2GHZ] would most likely have been NULL when the radiotap parser searched for the correct rate index of the driver. Cc: stable@vger.kernel.org Reported-by: Ben Greear <greearb@candelatech.com> Fixes: cb17ed2 ("mac80211: parse radiotap header when selecting Tx queue") Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@kuleuven.be> [sven@narfation.org: added commit message] Signed-off-by: Sven Eckelmann <sven@narfation.org> Link: https://lore.kernel.org/r/20210530133226.40587-1-sven@narfation.org Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent e298aa3 commit bddc0c4

2 files changed

Lines changed: 42 additions & 17 deletions

File tree

‎include/net/mac80211.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6392,7 +6392,12 @@ bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
63926392

63936393
/**
63946394
* ieee80211_parse_tx_radiotap - Sanity-check and parse the radiotap header
6395-
* of injected frames
6395+
* of injected frames.
6396+
*
6397+
* To accurately parse and take into account rate and retransmission fields,
6398+
* you must initialize the chandef field in the ieee80211_tx_info structure
6399+
* of the skb before calling this function.
6400+
*
63966401
* @skb: packet injected by userspace
63976402
* @dev: the &struct device of this 802.11 device
63986403
*/

‎net/mac80211/tx.c‎

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,26 @@ void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
20142014
ieee80211_tx(sdata, sta, skb, false);
20152015
}
20162016

2017+
static bool ieee80211_validate_radiotap_len(struct sk_buff *skb)
2018+
{
2019+
struct ieee80211_radiotap_header *rthdr =
2020+
(struct ieee80211_radiotap_header *)skb->data;
2021+
2022+
/* check for not even having the fixed radiotap header part */
2023+
if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2024+
return false; /* too short to be possibly valid */
2025+
2026+
/* is it a header version we can trust to find length from? */
2027+
if (unlikely(rthdr->it_version))
2028+
return false; /* only version 0 is supported */
2029+
2030+
/* does the skb contain enough to deliver on the alleged length? */
2031+
if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2032+
return false; /* skb too short for claimed rt header extent */
2033+
2034+
return true;
2035+
}
2036+
20172037
bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
20182038
struct net_device *dev)
20192039
{
@@ -2022,8 +2042,6 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
20222042
struct ieee80211_radiotap_header *rthdr =
20232043
(struct ieee80211_radiotap_header *) skb->data;
20242044
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2025-
struct ieee80211_supported_band *sband =
2026-
local->hw.wiphy->bands[info->band];
20272045
int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
20282046
NULL);
20292047
u16 txflags;
@@ -2036,17 +2054,8 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
20362054
u8 vht_mcs = 0, vht_nss = 0;
20372055
int i;
20382056

2039-
/* check for not even having the fixed radiotap header part */
2040-
if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
2041-
return false; /* too short to be possibly valid */
2042-
2043-
/* is it a header version we can trust to find length from? */
2044-
if (unlikely(rthdr->it_version))
2045-
return false; /* only version 0 is supported */
2046-
2047-
/* does the skb contain enough to deliver on the alleged length? */
2048-
if (unlikely(skb->len < ieee80211_get_radiotap_len(skb->data)))
2049-
return false; /* skb too short for claimed rt header extent */
2057+
if (!ieee80211_validate_radiotap_len(skb))
2058+
return false;
20502059

20512060
info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
20522061
IEEE80211_TX_CTL_DONTFRAG;
@@ -2186,6 +2195,9 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
21862195
return false;
21872196

21882197
if (rate_found) {
2198+
struct ieee80211_supported_band *sband =
2199+
local->hw.wiphy->bands[info->band];
2200+
21892201
info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT;
21902202

21912203
for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
@@ -2199,7 +2211,7 @@ bool ieee80211_parse_tx_radiotap(struct sk_buff *skb,
21992211
} else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) {
22002212
ieee80211_rate_set_vht(info->control.rates, vht_mcs,
22012213
vht_nss);
2202-
} else {
2214+
} else if (sband) {
22032215
for (i = 0; i < sband->n_bitrates; i++) {
22042216
if (rate * 5 != sband->bitrates[i].bitrate)
22052217
continue;
@@ -2236,8 +2248,8 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
22362248
info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
22372249
IEEE80211_TX_CTL_INJECTED;
22382250

2239-
/* Sanity-check and process the injection radiotap header */
2240-
if (!ieee80211_parse_tx_radiotap(skb, dev))
2251+
/* Sanity-check the length of the radiotap header */
2252+
if (!ieee80211_validate_radiotap_len(skb))
22412253
goto fail;
22422254

22432255
/* we now know there is a radiotap header with a length we can use */
@@ -2351,6 +2363,14 @@ netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
23512363
ieee80211_select_queue_80211(sdata, skb, hdr);
23522364
skb_set_queue_mapping(skb, ieee80211_ac_from_tid(skb->priority));
23532365

2366+
/*
2367+
* Process the radiotap header. This will now take into account the
2368+
* selected chandef above to accurately set injection rates and
2369+
* retransmissions.
2370+
*/
2371+
if (!ieee80211_parse_tx_radiotap(skb, dev))
2372+
goto fail_rcu;
2373+
23542374
/* remove the injection radiotap header */
23552375
skb_pull(skb, len_rthdr);
23562376

0 commit comments

Comments
 (0)