From patchwork Wed Mar 11 15:06:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cedric Izoard X-Patchwork-Id: 5986281 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7EA9B9F318 for ; Wed, 11 Mar 2015 15:06:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A92E2037C for ; Wed, 11 Mar 2015 15:06:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A719B202EB for ; Wed, 11 Mar 2015 15:06:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753181AbbCKPGY (ORCPT ); Wed, 11 Mar 2015 11:06:24 -0400 Received: from sbg-il.ceva-dsp.com ([195.82.128.8]:57362 "EHLO sbg-il.ceva-dsp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751207AbbCKPGX convert rfc822-to-8bit (ORCPT ); Wed, 11 Mar 2015 11:06:23 -0400 X-AuditID: ac181808-f798d6d000000db0-5a-550059e850de Received: from ilmail1.ceva-dsp.com (ilmail1.corp.local [192.168.61.16]) by sbg-il.ceva-dsp.com (CEVA eMail Gateway) with SMTP id 1E.50.03504.8E950055; Wed, 11 Mar 2015 17:06:16 +0200 (IST) Received: from ILMAIL1.corp.local ([192.168.61.16]) by ILMAIL1.corp.local ([192.168.61.16]) with mapi id 14.03.0210.002; Wed, 11 Mar 2015 17:06:16 +0200 From: Cedric Izoard To: "linux-wireless@vger.kernel.org" CC: johannes Berg , "Stepanov, Max" Subject: [PATCH v3] mac80211: Get-IV-len-from-key-conf-and-not-cipher-scheme Thread-Topic: [PATCH v3] mac80211: Get-IV-len-from-key-conf-and-not-cipher-scheme Thread-Index: AdBcDOux63xWqCn2SL+VSgdoyfxTeg== Date: Wed, 11 Mar 2015 15:06:16 +0000 Message-ID: <5842EA9CC042B141995329508713AD672105ACA7@ILMAIL1.corp.local> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.65.5] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLJsWRmVeSWpSXmKPExsVyYIWtgO6LSIZQg4bNphYfN3xisXiz4g67 xZpj39gdmD0W73nJ5NHfu43F4/MmuQDmKC6blNSczLLUIn27BK6MvqZ21oLn8hULLm9kb2A8 JNXFyMkhIWAi0X27lRHCFpO4cG89G4gtJLCfUeJkowCEPYdR4lJXGYjNJmAgcfDUJWYQW0TA VWLqxs1ANgcHs0CkxOIpWiBhYQEfiRs/prJClARLXGuYzQ5h60lsPjGLBcRmEVCVeDPhE9gY XgFPiab1rUwgNiPQCd9PrQGzmQXEJW49mc8EcZqAxJI955khbFGJl4//sULYChI77/9jhKjX kViw+xMbhK0tsWzha6j5ghInZz5hmcAoMgvJ2FlIWmYhaZmFpGUBI8sqRuHipHTdzBy95NSy RN2U4gK95PzcTYzAyFgjIcGxg/HLLqtDjAIcjEo8vEneDKFCrIllxZW5hxgtOZiURHnvhAGF +JLyUyozEosz4otKc1KLleR4w/3+hgiJw4WLS4sLMpMz80uL40uLcg4xSnAwK4nw7ggE6uVN SaysSi3Kh2g9xCjNwaIkziv0e0qgkEB6YklqdmpqQWoRTNaeg0NJgndDBFCjYFFqempFWmZO CUxaSZH3JMheKWQZdKuZODgPMZpz8ADt94oE2V9ckJhbnJkONUKWdz7ICDGYKKr2U4zWUuK8 80HWC4BUZJTmwW2XUuCdt+hfiJAkkgSq7leMpsBgFOY9D9LPA0z2CGtleLeBrBWFCqLrMweG tQgvi/X/EKB7SxJLkN3rBhIVg4mi6pRqYFxZ6XapMfjaAllVg2Wcob+D7k8R3vy4KXfl8+7Z 8povUpZ9naoQLbC8VWrDIYNHO61/7Xwk9fjnAgcFjw/NVxZtXxiz9HOim0uT7Q1/tT2dRjL5 Xm8fMHR+iZEX2FIYvTbLZFb9bOt3fx6375o8O1g11e2s7oFkl/t/Dm1oXSd9OXEC25ZLT+cq sRRnJBpqMRcVJwIASiOQYfADAAA= Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 When a key is installed using a cipher scheme, a new flag IEE80211_KEY_FLAG_CIPHER_SCHEME is set. This flag is used on TX path to test for "cipher scheme" key, instead of testing for sta->cipher_scheme as sta is NULL for bcast/mcast messages. For cipher scheme key, security header length is then read from key->conf.iv_len initialized with cs->hdr_len. --- include/net/mac80211.h | 5 ++++- net/mac80211/key.c | 1 + net/mac80211/wpa.c | 13 ++++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index a7756e4..74af5cf 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1318,6 +1318,8 @@ struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev); * @IEEE80211_KEY_FLAG_RESERVE_TAILROOM: This flag should be set by the * driver for a key to indicate that sufficient tailroom must always * be reserved for ICV or MIC, even when HW encryption is enabled. + * @IEEE80211_KEY_FLAG_CIPHER_SCHEME: Set by mac80211, this flag indicates + * that the key has been installed using a cipher scheme. */ enum ieee80211_key_flags { IEEE80211_KEY_FLAG_GENERATE_IV_MGMT = BIT(0), @@ -1328,6 +1330,7 @@ enum ieee80211_key_flags { IEEE80211_KEY_FLAG_PUT_IV_SPACE = BIT(5), IEEE80211_KEY_FLAG_RX_MGMT = BIT(6), IEEE80211_KEY_FLAG_RESERVE_TAILROOM = BIT(7), + IEEE80211_KEY_FLAG_CIPHER_SCHEME = BIT(8), }; /** @@ -1356,7 +1359,7 @@ struct ieee80211_key_conf { u8 icv_len; u8 iv_len; u8 hw_key_idx; - u8 flags; + u16 flags; s8 keyidx; u8 keylen; u8 key[0]; diff --git a/net/mac80211/key.c b/net/mac80211/key.c index 0825d76..10870a6 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -492,6 +492,7 @@ ieee80211_key_alloc(u32 cipher, int idx, size_t key_len, for (j = 0; j < len; j++) key->u.gen.rx_pn[i][j] = seq[len - j - 1]; + key->conf.flags |= IEEE80211_KEY_FLAG_CIPHER_SCHEME; } } memcpy(key->conf.key, key_data, key_len); diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c index 75de6fa..5f21bd3 100644 --- a/net/mac80211/wpa.c +++ b/net/mac80211/wpa.c @@ -780,9 +780,8 @@ ieee80211_crypto_cs_encrypt(struct ieee80211_tx_data *tx, struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct ieee80211_key *key = tx->key; struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); - const struct ieee80211_cipher_scheme *cs = key->sta->cipher_scheme; int hdrlen; - u8 *pos; + u8 *pos, iv_len = key->conf.iv_len; if (info->control.hw_key && !(info->control.hw_key->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE)) { @@ -790,14 +789,14 @@ ieee80211_crypto_cs_encrypt(struct ieee80211_tx_data *tx, return TX_CONTINUE; } - if (unlikely(skb_headroom(skb) < cs->hdr_len && - pskb_expand_head(skb, cs->hdr_len, 0, GFP_ATOMIC))) + if (unlikely(skb_headroom(skb) < iv_len && + pskb_expand_head(skb, iv_len, 0, GFP_ATOMIC))) return TX_DROP; hdrlen = ieee80211_hdrlen(hdr->frame_control); - pos = skb_push(skb, cs->hdr_len); - memmove(pos, pos + cs->hdr_len, hdrlen); + pos = skb_push(skb, iv_len); + memmove(pos, pos + iv_len, hdrlen); return TX_CONTINUE; } @@ -1217,7 +1216,7 @@ ieee80211_crypto_hw_encrypt(struct ieee80211_tx_data *tx) if (!info->control.hw_key) return TX_DROP; - if (tx->key->sta->cipher_scheme) { + if (tx->key->conf.flags & IEEE80211_KEY_FLAG_CIPHER_SCHEME) { res = ieee80211_crypto_cs_encrypt(tx, skb); if (res != TX_CONTINUE) return res;