From patchwork Mon Dec 23 11:42:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fred.chou.nd@gmail.com X-Patchwork-Id: 3396501 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AB1B7C0D4A for ; Mon, 23 Dec 2013 11:41:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 63CDB2034F for ; Mon, 23 Dec 2013 11:41:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2560C202F2 for ; Mon, 23 Dec 2013 11:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757247Ab3LWLlJ (ORCPT ); Mon, 23 Dec 2013 06:41:09 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:51100 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757239Ab3LWLlI (ORCPT ); Mon, 23 Dec 2013 06:41:08 -0500 Received: by mail-pa0-f44.google.com with SMTP id fa1so5217547pad.17 for ; Mon, 23 Dec 2013 03:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=uxxf1uXYScfvDaDCgupz8/DZDIZ6UQK3PZvex4Fa9Ns=; b=xbFB8Y48dRuLTwtXaovQ8ppgfQ02JPkXzj2M51eP1ppZfl15+nV+089wLkY+KjM0L5 V0doAsE/7Ca6a4JLyoLTjMeam9mQq4KDHrJnColZEBghQyHKpiIRYhXyMr8ETloaFkY0 lY/6t2eX80tW+b2BIPJ8BQKU2xa0SPvA8M69QA5LvOPqIQ9d1UzekX7WzzCD3FsCDx0g Mi+s+T1QUSgH7/KxuzbEgm7eCm6zA5BMadjBIKjdZ2aHlmdvcocaPabduErgMMuvg40r ruPaFyMIFF0hC5l1YtminkGee4Ok8AvdDuPPaWnFChoE8odwQZEAtwLB+59AVYgBA8DQ wSmA== X-Received: by 10.68.173.132 with SMTP id bk4mr992847pbc.169.1387798868182; Mon, 23 Dec 2013 03:41:08 -0800 (PST) Received: from gmail.com ([192.122.131.9]) by mx.google.com with ESMTPSA id fk4sm44123442pab.23.2013.12.23.03.41.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Dec 2013 03:41:07 -0800 (PST) From: Fred Chou To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Fred Chou Subject: [PATCH] mac80211: reorder packet checking and processing Date: Mon, 23 Dec 2013 19:42:55 +0800 Message-Id: <1387798975-17708-1-git-send-email-fred.chou.nd@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FSL_HELO_FAKE, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- net/mac80211/rx.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) 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);