diff mbox

mac80211: reorder packet checking and processing

Message ID 1387798975-17708-1-git-send-email-fred.chou.nd@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

fred.chou.nd@gmail.com Dec. 23, 2013, 11:42 a.m. UTC
Check received packet length first and drop the packet
if it is shorter than MAC header. Process packet after
the checking. 

Signed-off-by: 	Fred Chou <fred.chou.nd@gmail.com>
---
 net/mac80211/rx.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

Comments

Johannes Berg Jan. 6, 2014, 4:42 p.m. UTC | #1
On Mon, 2013-12-23 at 19:42 +0800, Fred Chou wrote:
> 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

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 688e0aa..95b8cd9 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -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);