Skip to content

Commit 9b395bc

Browse files
committed
mac80211: verify that skb data is present
A number of places in the mesh code don't check that the frame data is present and in the skb header when trying to access. Add those checks and the necessary pskb_may_pull() calls. This prevents accessing data that doesn't actually exist. To do this, export ieee80211_get_mesh_hdrlen() to be able to use it in mac80211. Cc: stable@vger.kernel.org Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 4a4f1a5 commit 9b395bc

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎include/net/cfg80211.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,15 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);
26512651
*/
26522652
unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc);
26532653

2654+
/**
2655+
* ieee80211_get_mesh_hdrlen - get mesh extension header length
2656+
* @meshhdr: the mesh extension header, only the flags field
2657+
* (first byte) will be accessed
2658+
* Returns the length of the extension header, which is always at
2659+
* least 6 bytes and at most 18 if address 5 and 6 are present.
2660+
*/
2661+
unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
2662+
26542663
/**
26552664
* DOC: Data path helpers
26562665
*

‎net/mac80211/rx.c‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
531531

532532
if (ieee80211_is_action(hdr->frame_control)) {
533533
u8 category;
534+
535+
/* make sure category field is present */
536+
if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
537+
return RX_DROP_MONITOR;
538+
534539
mgmt = (struct ieee80211_mgmt *)hdr;
535540
category = mgmt->u.action.category;
536541
if (category != WLAN_CATEGORY_MESH_ACTION &&
@@ -1892,6 +1897,20 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
18921897

18931898
hdr = (struct ieee80211_hdr *) skb->data;
18941899
hdrlen = ieee80211_hdrlen(hdr->frame_control);
1900+
1901+
/* make sure fixed part of mesh header is there, also checks skb len */
1902+
if (!pskb_may_pull(rx->skb, hdrlen + 6))
1903+
return RX_DROP_MONITOR;
1904+
1905+
mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1906+
1907+
/* make sure full mesh header is there, also checks skb len */
1908+
if (!pskb_may_pull(rx->skb,
1909+
hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
1910+
return RX_DROP_MONITOR;
1911+
1912+
/* reload pointers */
1913+
hdr = (struct ieee80211_hdr *) skb->data;
18951914
mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
18961915

18971916
/* frame is in RMC, don't forward */
@@ -1915,9 +1934,12 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
19151934
if (is_multicast_ether_addr(hdr->addr1)) {
19161935
mpp_addr = hdr->addr3;
19171936
proxied_addr = mesh_hdr->eaddr1;
1918-
} else {
1937+
} else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
1938+
/* has_a4 already checked in ieee80211_rx_mesh_check */
19191939
mpp_addr = hdr->addr4;
19201940
proxied_addr = mesh_hdr->eaddr2;
1941+
} else {
1942+
return RX_DROP_MONITOR;
19211943
}
19221944

19231945
rcu_read_lock();
@@ -2354,6 +2376,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
23542376
}
23552377
break;
23562378
case WLAN_CATEGORY_SELF_PROTECTED:
2379+
if (len < (IEEE80211_MIN_ACTION_SIZE +
2380+
sizeof(mgmt->u.action.u.self_prot.action_code)))
2381+
break;
2382+
23572383
switch (mgmt->u.action.u.self_prot.action_code) {
23582384
case WLAN_SP_MESH_PEERING_OPEN:
23592385
case WLAN_SP_MESH_PEERING_CLOSE:
@@ -2372,6 +2398,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
23722398
}
23732399
break;
23742400
case WLAN_CATEGORY_MESH_ACTION:
2401+
if (len < (IEEE80211_MIN_ACTION_SIZE +
2402+
sizeof(mgmt->u.action.u.mesh_action.action_code)))
2403+
break;
2404+
23752405
if (!ieee80211_vif_is_mesh(&sdata->vif))
23762406
break;
23772407
if (mesh_action_is_path_sel(mgmt) &&

‎net/wireless/util.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
309309
}
310310
EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
311311

312-
static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
312+
unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
313313
{
314314
int ae = meshhdr->flags & MESH_FLAGS_AE;
315315
/* 802.11-2012, 8.2.4.7.3 */
@@ -323,6 +323,7 @@ static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
323323
return 18;
324324
}
325325
}
326+
EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
326327

327328
int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
328329
enum nl80211_iftype iftype)

0 commit comments

Comments
 (0)