Skip to contentSkip to conversation

mac80211: check A-MSDU inner frame source address on AP interfaces

PATCH Superseded Michael Braun 2 participants 4 messages Sep 25, 2016 – Sep 27, 2016 802.11 (including cfg80211/NL80211)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mac80211: check A-MSDU inner frame source address on AP interfaces

When using WPA security, the station and thus the required key is identified by its mac address when packets are received. So a station usually cannot spoof its source mac address.

But when a station sends an A-MSDU frame, port control and crypto is done using the outer mac address, while the packets delivered and forwarded use the inner mac address.

IEEE 802.11-2012 mandates that the outer source mac address should match the inner source address (section 8.3.2.2). For the destination mac address, matching is not required (section 10.23.15).

--
v2: fix typo inversed source mac address check

---
 net/wireless/util.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
net/wireless/util.c +9 -2
index b7d1592..86ca5d2 100644
@@ -747,13 +747,13 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
 	u16 ethertype;
 	u8 *payload;
 	int offset = 0, remaining, err;
-	struct ethhdr eth;
+	struct ethhdr eth, eth_80211;
 	bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb);
 	bool reuse_skb = false;
 	bool last = false;
 
 	if (has_80211_header) {
-		err = __ieee80211_data_to_8023(skb, &eth, addr, iftype);
+		err = __ieee80211_data_to_8023(skb, &eth_80211, addr, iftype);
 		if (err)
 			goto out;
 	}
@@ -768,6 +768,13 @@ void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
 		subframe_len = sizeof(struct ethhdr) + len;
 		padding = (4 - subframe_len) & 0x3;
 
+		if (unlikely(has_80211_header &&
+			     (iftype == NL80211_IFTYPE_AP ||
+			      iftype == NL80211_IFTYPE_AP_VLAN) &&
+			     !ether_addr_equal(eth_80211.h_source, eth.h_source)
+		   ))
+			goto purge;
+
 		/* the last MSDU has no padding */
 		remaining = skb->len - offset;
 		if (subframe_len > remaining)
Signature · 1 line
2.1.4
maintainer
#1 lore raw

Huh. I know this bug, I thought we fixed it a long time ago. Oops.

Quoted 10 lines
net/wireless/util.c +1 -1
-	struct ethhdr eth;
+	struct ethhdr eth, eth_80211;

  bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb); bool reuse_skb = false;
  bool last = false;

  if (has_80211_header) {

(quoted diff) +0 -1
-		err = __ieee80211_data_to_8023(skb, &eth, addr,

iftype);

(quoted diff) +1 -0
+		err = __ieee80211_data_to_8023(skb, &eth_80211,
Quoted 4 lines

addr, iftype);
  if (err)
  goto out;
  }

This leaves "eth_80211" uninitialized if has_80211_header is false.

net/wireless/util.c void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, · line 776

Quoted 12 lines
net/wireless/util.c +0 -0
@@ -768,6 +768,13 @@ void ieee80211_amsdu_to_8023s(struct sk_buff
 *skb, struct sk_buff_head *list,
  		subframe_len = sizeof(struct ethhdr) + len;
  		padding = (4 - subframe_len) & 0x3;

net/wireless/util.c +4 -0
+		if (unlikely(has_80211_header &&
+			     (iftype == NL80211_IFTYPE_AP ||
+			      iftype == NL80211_IFTYPE_AP_VLAN) &&
+			     !ether_addr_equal(eth_80211.h_source,

eth.h_source)

net/wireless/util.c +2 -0
+		   ))
+			goto purge;

And this then compares against uninitialized data, so this won't work.

I'd suggest removing the "has_80211_header" argument entirely, and replacing it with a "const u8 *sa" argument, but that complicates mac80211 significantly since all the checks
in __ieee80211_data_to_8023() would have to be replicated.

Maybe we can still do this, and say that it must be NULL when an 802.11 header is present, and be the SA when not. However, mwifiex doesn't seem to be able to easily provide the SA (at least I don't see it, perhaps it can), so that we'd have to allow some kind of ERR_PTR() or something for that special case ... Actually it'd be better to just fix mwifiex though :)

The staging driver using this (rtl8712) can easily provide the SA, afaict.

johannes

maintainer
#3 lore raw
In reply to michael-dev
Quoted 24 lines · michael-dev

Am 27.09.2016 10:01, schrieb Johannes Berg:

Quoted 15 lines

...

This leaves "eth_80211" uninitialized if has_80211_header is false.

Quoted 10 lines
net/wireless/util.c +0 -0
@@ -768,6 +768,13 @@ void ieee80211_amsdu_to_8023s(struct sk_buff
 *skb, struct sk_buff_head *list,
  		subframe_len = sizeof(struct ethhdr) + len;
  		padding = (4 - subframe_len) & 0x3;

net/wireless/util.c +3 -0
+		if (unlikely(has_80211_header &&
+			     (iftype == NL80211_IFTYPE_AP ||
+			      iftype == NL80211_IFTYPE_AP_VLAN)

&&

Quoted 7 lines

net/wireless/util.c void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list, · line 776

Quoted 4 lines
Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+			     !ether_addr_equal(eth_80211.h_source,

eth.h_source)

net/wireless/util.c +2 -0
+		   ))
+			goto purge;

And this then compares against uninitialized data, so this won't work.

Quoted 4 lines

but it only compares against eth_80211 if has_80211_header is true due to order of evaluation, which in turn implies eth_80211 is initialized, right?

Oh, right, I missed that, sorry.

Nevertheless, it seems it would be better to allow the other users (not mac80211) that have has_80211_header=false to still have the check?

johannes

#2 lore raw
In reply to Johannes Berg

Am 27.09.2016 10:01, schrieb Johannes Berg:

Quoted 4 lines

...
=20
This leaves "eth_80211" uninitialized if has_80211_header is false. =20

Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +0 -0
@@ -768,6 +768,13 @@ void ieee80211_amsdu_to_8023s(struct sk_buff
 *skb, struct sk_buff_head *list,
 =C2=A0		subframe_len =3D sizeof(struct ethhdr) + len;
 =C2=A0		padding =3D (4 - subframe_len) & 0x3;

=C2=A0

(quoted diff) +3 -0
+		if (unlikely(has_80211_header &&
+			=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(iftype =3D=3D NL80211_IFTYPE_AP ||
+			=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0iftype =3D=3D NL80211_IFTYPE_AP_=

VLAN) &&

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +1 -0
+			=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0!ether_addr_equal(eth_80211.h_source,

eth.h_source)

(quoted diff) +2 -0
+		=C2=A0=C2=A0=C2=A0))
+			goto purge;

=20
And this then compares against uninitialized data, so this won't work.

but it only compares against eth_80211 if has_80211_header is true due=20 to order of evaluation, which in turn implies eth_80211 is initialized,=20 right?

michael