Skip to contentSkip to conversation

mac80211: reorder packet checking and processing

PATCH In review Fred Chou 2 participants 2 messages Dec 23, 2013 – Jan 6, 2014 mac80211

lore
Share & tools
lore

Fred Chou

author
#0 lore raw

PATCH 1/1 mac80211: reorder packet checking and processing

Check received packet length first and drop the packet if it is shorter than MAC header. Process packet after the checking.

---
 net/mac80211/rx.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
net/mac80211/rx.c +14 -10
index 688e0aa..95b8cd9 100644
@@ -3145,20 +3145,21 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
 	struct sta_info *sta, *tmp, *prev_sta;
 	int err = 0;
 
-	fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
-	memset(&rx, 0, sizeof(rx));
-	rx.skb = skb;
-	rx.local = local;
+	hdr = (struct ieee80211_hdr *)skb->data;
+	fc = hdr->frame_control;
 
+	/* drop frame if too short for header */
+	if (skb->len < ieee80211_hdrlen(fc)) {
+		dev_kfree_skb(skb);
+		return;
+	}
+
+	/* update counter only for reliable packet */
 	if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
 		local->dot11ReceivedFragmentCount++;
 
 	if (ieee80211_is_mgmt(fc)) {
-		/* drop frame if too short for header */
-		if (skb->len < ieee80211_hdrlen(fc))
-			err = -ENOBUFS;
-		else
-			err = skb_linearize(skb);
+		err = skb_linearize(skb);
 	} else {
 		err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
 	}
@@ -3168,7 +3169,10 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
 		return;
 	}
 
-	hdr = (struct ieee80211_hdr *)skb->data;
+	memset(&rx, 0, sizeof(rx));
+	rx.skb = skb;
+	rx.local = local;
+
 	ieee80211_parse_qos(&rx);
 	ieee80211_verify_alignment(&rx);
 
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 3 lines · Fred Chou

Check received packet length first and drop the packet if it is shorter than MAC header. Process packet after the checking.

Why do you think we should do this? Your commit message is also misleading - we already check that the patch is long enough. Too short packets should be relatively rare anyway.

johannes