Skip to contentSkip to conversation

mac80211: accept public action frames with mismatched BSSID

PATCH Superseded Johannes Berg 2 participants 5 messages Dec 5, 2011 – Dec 6, 2011

Subsystems (2)
lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

PATCH 1/1 mac80211: accept public action frames with mismatched BSSID

From: Johannes Berg <[email protected]>

Arik's patch "mac80211: allow action frames with unknown BSSID in GO mode" allowed any action frames in P2P mode to go through, but only to cooked monitor interfaces as the IEEE80211_RX_RA_MATCH was still cleared. As a result my no-monitor patches broke invitation responses.

Instead of allowing any action frames in P2P GO mode to go through with a wrong BSSID like that patch did, allow all public action frames. They will never be processed by mac80211, but can be reported via nl80211 then.

---
 include/linux/ieee80211.h |   17 +++++++++++++++++
 net/mac80211/rx.c         |   13 ++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)
include/linux/ieee80211.h +17 -0
@@ -1695,6 +1695,23 @@ static inline bool ieee80211_is_robust_m
 }
 
 /**
+ * ieee80211_is_public_action - check if frame is a public action frame
+ * @hdr: the frame
+ * @len: length of the frame
+ */
+static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
+					      size_t len)
+{
+	struct ieee80211_mgmt *mgmt = (void *)hdr;
+
+	if (len < 25)
+		return false;
+	if (!ieee80211_is_action(hdr->frame_control))
+		return false;
+	return mgmt->u.action.category == WLAN_CATEGORY_PUBLIC;
+}
+
+/**
  * ieee80211_fhss_chan_to_freq - get channel frequency
  * @channel: the FHSS channel
  *
net/mac80211/rx.c +10 -3
@@ -2796,10 +2796,17 @@ static int prepare_for_handlers(struct i
 				return 0;
 		} else if (!ieee80211_bssid_match(bssid,
 					sdata->vif.addr)) {
+			/*
+			 * Accept public action frames even when the
+			 * BSSID doesn't match, this is used for P2P
+			 * and location updates. Note that mac80211
+			 * itself never looks at these frames.
+			 */
 			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
-			    !ieee80211_is_beacon(hdr->frame_control) &&
-			    !(ieee80211_is_action(hdr->frame_control) &&
-			      sdata->vif.p2p))
+			    ieee80211_is_public_action(hdr, skb->len))
+				return 1;
+			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
+			    !ieee80211_is_beacon(hdr->frame_control))
 				return 0;
 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
 		}
#1 lore raw
Quoted 15 lines · Johannes Berg

From: Johannes Berg <[email protected]>

Arik's patch "mac80211: allow action frames with unknown BSSID in GO mode" allowed any action frames in P2P mode to go through, but only to cooked monitor interfaces as the IEEE80211_RX_RA_MATCH was still cleared. As a result my no-monitor patches broke invitation responses.

Instead of allowing any action frames in P2P GO mode to go through with a wrong BSSID like that patch did, allow all public action frames. They will never be processed by mac80211, but can be reported via nl80211 then.

---

[...]

include/linux/ieee80211.h static inline bool ieee80211_is_robust_m · line 1708

Quoted 7 lines
include/linux/ieee80211.h +7 -0
+static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
+                                             size_t len)
+{
+       struct ieee80211_mgmt *mgmt = (void *)hdr;
+
+       if (len < 25)
+               return false;

maybe use offsetof() to make clearer?

Eliad.

author maintainer
#2 lore raw
Quoted 9 lines · Eliad Peller

include/linux/ieee80211.h static inline bool ieee80211_is_robust_m · line 1708

Quoted 7 lines
include/linux/ieee80211.h +7 -0
+static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
+                                             size_t len)
+{
+       struct ieee80211_mgmt *mgmt = (void *)hdr;
+
+       if (len < 25)
+               return false;

maybe use offsetof() to make clearer?

Hm. The problem with that is that you need

	offsetof(... u.action.category ...) + 1

still since the *offset* is 24 and the size is implicit. Going beyond that in the offset calculation would be even stranger... I think 25 is a sufficiently non-magic number since everybody knows 24 is the "normal" header length, and it matches the style used in this file elsewhere.

johannes

#3 lore raw
Quoted 12 lines · Johannes Berg
Quoted 9 lines · Eliad Peller

include/linux/ieee80211.h static inline bool ieee80211_is_robust_m · line 1708

Quoted 7 lines
include/linux/ieee80211.h +7 -0
+static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
+                                             size_t len)
+{
+       struct ieee80211_mgmt *mgmt = (void *)hdr;
+
+       if (len < 25)
+               return false;

maybe use offsetof() to make clearer?

Quoted 7 lines

Hm. The problem with that is that you need
       offsetof(... u.action.category ...) + 1
still since the *offset* is 24 and the size is implicit. Going beyond that in the offset calculation would be even stranger... I think 25 is a sufficiently non-magic number since everybody knows 24 is the "normal" header length, and it matches the style used in this file elsewhere.

you can do something like:

#define end_offsetof(TYPE, MEMBER) offsetof(TYPE, MEMBER) + \
		sizeof(((TYPE *)0)->MEMBER)

but hey, whatever :)

Eliad.

author maintainer
#4 lore raw

PATCH v2 1/1 mac80211: accept public action frames with mismatched BSSID

From: Johannes Berg <[email protected]>

Arik's patch "mac80211: allow action frames with unknown BSSID in GO mode" allowed any action frames in P2P mode to go through, but only to cooked monitor interfaces as the IEEE80211_RX_RA_MATCH was still cleared. As a result my no-monitor patches broke invitation responses.

Instead of allowing any action frames in P2P GO mode to go through with a wrong BSSID like that patch did, allow all public action frames. They will never be processed by mac80211, but can be reported via nl80211 then.

---
v2: use IEEE80211_MIN_ACTION_SIZE, thanks Eliad

 include/linux/ieee80211.h |   17 +++++++++++++++++
 net/mac80211/rx.c         |   13 ++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)
include/linux/ieee80211.h +17 -0
@@ -1695,6 +1695,23 @@ static inline bool ieee80211_is_robust_m
 }
 
 /**
+ * ieee80211_is_public_action - check if frame is a public action frame
+ * @hdr: the frame
+ * @len: length of the frame
+ */
+static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
+					      size_t len)
+{
+	struct ieee80211_mgmt *mgmt = (void *)hdr;
+
+	if (len < IEEE80211_MIN_ACTION_SIZE)
+		return false;
+	if (!ieee80211_is_action(hdr->frame_control))
+		return false;
+	return mgmt->u.action.category == WLAN_CATEGORY_PUBLIC;
+}
+
+/**
  * ieee80211_fhss_chan_to_freq - get channel frequency
  * @channel: the FHSS channel
  *
net/mac80211/rx.c +10 -3
@@ -2796,10 +2796,17 @@ static int prepare_for_handlers(struct i
 				return 0;
 		} else if (!ieee80211_bssid_match(bssid,
 					sdata->vif.addr)) {
+			/*
+			 * Accept public action frames even when the
+			 * BSSID doesn't match, this is used for P2P
+			 * and location updates. Note that mac80211
+			 * itself never looks at these frames.
+			 */
 			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
-			    !ieee80211_is_beacon(hdr->frame_control) &&
-			    !(ieee80211_is_action(hdr->frame_control) &&
-			      sdata->vif.p2p))
+			    ieee80211_is_public_action(hdr, skb->len))
+				return 1;
+			if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
+			    !ieee80211_is_beacon(hdr->frame_control))
 				return 0;
 			status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
 		}