From patchwork Wed Jun 22 10:55:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masashi Honma X-Patchwork-Id: 9192401 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 261F86075C for ; Wed, 22 Jun 2016 10:55:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 133232818A for ; Wed, 22 Jun 2016 10:55:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 040EE283E5; Wed, 22 Jun 2016 10:55:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80FA32818A for ; Wed, 22 Jun 2016 10:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751586AbcFVKzg (ORCPT ); Wed, 22 Jun 2016 06:55:36 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:33431 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750943AbcFVKzg (ORCPT ); Wed, 22 Jun 2016 06:55:36 -0400 Received: by mail-pa0-f65.google.com with SMTP id ts6so3740931pac.0 for ; Wed, 22 Jun 2016 03:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BkgG6bYkJpgrMFa9TTjzrDlW+zrnTVfEceOn9PGWzs8=; b=Ta8aefhQ6+DM/vPBu+QKsqTMyDzPzovPJN01rCOLAlTaM+zM4MnWXKFxGCbdtn044K cJTxJWMSekkdlzsdM5IfVTJqrkhPsJ0qPO0/sk55B90HDTYqf5exbIiVV+F5fKTL2CSM CtXE3hXWH0IARE46RR3Bc2fsyTXwJ6Lb89lcqzbzvqnDcpzpgeXXXd+yXjzH2Lo8fMl1 p/5tOJjx3t1p3A4Dj6AafEHOSNbaG+3byxyCgrOWkYIkiTW4XsLWN9gsGTBNKBxpy/sG BnXn0EpuVau3TYASmFxZMpCGS6B1ij1Rk2E6BE4r+S66XGwMyLOc704TuzPpMiofzYid Yvaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BkgG6bYkJpgrMFa9TTjzrDlW+zrnTVfEceOn9PGWzs8=; b=e1pivtmiRu5vlVImSQh9PYl+NppjlYi3HJFQh4LWt+OrbHXJAWk9EGmrtkywIJZsHC yAXu1hUUQ2rZgalt+O76jW17TewXhwtLJdEx2G4laOYQzWEYiZeNpIJM+bVA+AC+GQLt GhDR2X1AEKTIt+6PGKKqDmTKfSDgrqRRs7pnH3XimKmjni6mfprIb8EQMR/iObvBrM1N hjO7OV41CUvytaIom1m1qPvmqlJPJQBJ3C8K4gxjyHRsEDVcinBghyG0qFK991lMz0j8 +rz0Z8LWXNR3mYhP2wZX9MEcdMT/faN7x8Tmc4jXrC3Q/FHPa6Wwe6DhZx0EW6COljYc Clng== X-Gm-Message-State: ALyK8tJdTK/6yVXGm2kjUXvZofIAM6WwtZTaGc51vNUdekh+sZm0pML711gDwP+nyBte8g== X-Received: by 10.67.15.72 with SMTP id fm8mr34423224pad.50.1466592935151; Wed, 22 Jun 2016 03:55:35 -0700 (PDT) Received: from localhost.localdomain (p023c03.kngwnt01.ap.so-net.ne.jp. [121.2.60.3]) by smtp.gmail.com with ESMTPSA id i3sm4731023pfk.30.2016.06.22.03.55.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Jun 2016 03:55:34 -0700 (PDT) From: Masashi Honma To: j@w1.fi, johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Masashi Honma Subject: [PATCH v3] mac80211: Encrypt "Group addressed privacy" action frames Date: Wed, 22 Jun 2016 19:55:20 +0900 Message-Id: <1466592920-2716-1-git-send-email-masashi.honma@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <20160621170120.GA24882@w1.fi> References: <20160621170120.GA24882@w1.fi> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Previously, the action frames to group address was not encrypted. But [1] "Table 8-38 Category values" indicates "Mesh" and "Multihop" category action frames should be encrypted (Group addressed privacy == yes). And the encyption key should be MGTK ([1] 10.13 Group addressed robust management frame procedures). So this patch modifies the code to make it suitable for spec. [1] IEEE Std 802.11-2012 Signed-off-by: Masashi Honma --- include/linux/ieee80211.h | 32 ++++++++++++++++++++++++++++++++ net/mac80211/rx.c | 7 ++++++- net/mac80211/tx.c | 6 +++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h index b118744..7c0771a 100644 --- a/include/linux/ieee80211.h +++ b/include/linux/ieee80211.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -2487,6 +2488,37 @@ static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr, } /** + * _ieee80211_is_group_privacy_action - check if frame is a group addressed + * privacy action frame + * @hdr: the frame + */ +static inline bool _ieee80211_is_group_privacy_action(struct ieee80211_hdr *hdr) +{ + struct ieee80211_mgmt *mgmt; + + if (!ieee80211_is_action(hdr->frame_control) || + !is_multicast_ether_addr(hdr->addr1)) + return false; + + mgmt = (struct ieee80211_mgmt *)hdr; + + return mgmt->u.action.category == WLAN_CATEGORY_MESH_ACTION || + mgmt->u.action.category == WLAN_CATEGORY_MULTIHOP_ACTION; +} + +/** + * ieee80211_is_group_privacy_action - check if frame is a group addressed + * privacy action frame + * @skb: the skb containing the frame, length will be checked + */ +static inline bool ieee80211_is_group_privacy_action(struct sk_buff *skb) +{ + if (skb->len < IEEE80211_MIN_ACTION_SIZE) + return false; + return _ieee80211_is_group_privacy_action((void *)skb->data); +} + +/** * ieee80211_tu_to_usec - convert time units (TU) to microseconds * @tu: the TUs */ diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 5e65e83..2300c0f 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -1624,8 +1624,13 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx) if (mmie_keyidx < NUM_DEFAULT_KEYS || mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) return RX_DROP_MONITOR; /* unexpected BIP keyidx */ - if (rx->sta) + if (rx->sta) { + if (ieee80211_is_group_privacy_action(skb) && + test_sta_flag(rx->sta, WLAN_STA_MFP)) + return RX_DROP_MONITOR; + rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]); + } if (!rx->key) rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]); } else if (!ieee80211_has_protected(fc)) { diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 2030443..e194df6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -590,6 +590,9 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) else if (tx->sta && (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]))) tx->key = key; + else if (ieee80211_is_group_privacy_action(tx->skb) && + (key = rcu_dereference(tx->sdata->default_multicast_key))) + tx->key = key; else if (ieee80211_is_mgmt(hdr->frame_control) && is_multicast_ether_addr(hdr->addr1) && ieee80211_is_robust_mgmt_frame(tx->skb) && @@ -622,7 +625,8 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) case WLAN_CIPHER_SUITE_GCMP_256: if (!ieee80211_is_data_present(hdr->frame_control) && !ieee80211_use_mfp(hdr->frame_control, tx->sta, - tx->skb)) + tx->skb) && + !ieee80211_is_group_privacy_action(tx->skb)) tx->key = NULL; else skip_hw = (tx->key->conf.flags &