Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7191332imm; Tue, 24 Jul 2018 09:52:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe6cCzfLbf9ZtjOSEIDnMToNrnRypjuPXo1JghWno8qLtMv+eRG869KeAz45ku0TXP/YqNa X-Received: by 2002:a62:90d4:: with SMTP id q81-v6mr18680754pfk.37.1532451166087; Tue, 24 Jul 2018 09:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451166; cv=none; d=google.com; s=arc-20160816; b=E65GhSUUaRCsLISnmOu5W4uTyies7NcIHqdcIf4j9YqzGNNX6uovj7jpABoIJ79vL/ 1h5q91O/0uhO1hU/pOv/u24WVuG8RvaKU98dIz3oZwPQmlj/juNcIO4OimbOgPJwsu12 FdYC7KwsFZPgzm2+nqLAhvvEUdgDmM0RsI5vHZdEwxE+cLEK8gYFeCrJrqXzk7ktqmjb LqV/IfPJBL7VdzfZ/JE6oQ0oVh1IsNmz+MAglCmybfrIyO23S7WAP7gWRl4lE/iyo5j4 nXwD8ivqkJJFjjJ4h/QwVkF+P6eM2MG+yY0FzkMuLgu6zrGzIj+coHD4IMc72ZFcE/8y iALQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Fd4CyuLW4EvKRKBdDvHFYcqX0s0Y10MBU0R0P+vSpn0=; b=iX8+lG7aWKkCdnHmys22EY8M37au+THJVVzXZmoPP2Lom0NBaWqPLQFDrLpN814OWs Q+UuSUkK96h24hGLcP18/2bxdvhgzk9kDhpJNiBydlCg0engMUgYeWOHKi61OB53sToD xbN1LT4tiWuSz9hfbA46rU5dJt96nT18ouGhcBVQIXfM/fnfU0Kcy5xagjVLCcGXKAkV geffoqc7IoB1Ag2QF2KIBl3dO7/cac65WdxL3jddHEPY/cZkhLRe90rVhZW2q6WkRJJN 4YQMLO8BVyHhYhIE7o9/DBMTcjLzPI4OSUVuY/O/7g0lAigk41S/diNlU34wHdmXfpeg o41w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hIU+xMH8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v84-v6si12362392pfa.103.2018.07.24.09.52.30; Tue, 24 Jul 2018 09:52:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hIU+xMH8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388674AbeGXR5S (ORCPT + 99 others); Tue, 24 Jul 2018 13:57:18 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46943 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388671AbeGXR5R (ORCPT ); Tue, 24 Jul 2018 13:57:17 -0400 Received: by mail-pg1-f193.google.com with SMTP id p23-v6so3286942pgv.13 for ; Tue, 24 Jul 2018 09:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Fd4CyuLW4EvKRKBdDvHFYcqX0s0Y10MBU0R0P+vSpn0=; b=hIU+xMH81mTgYVxwuWmSqAWn5A53bqOvWhpMEc7QMlhDhVn8zjoypa/Kwg4VQ4vc5n c0c5gXf+1K9cQbw4roO1CRdC7oMEfTerePZzwbkzYMz/DZyb/ZC52dNE0HdjuuP/Wb/O BaEZgLoloJry6pklEt9aFP+0gBy/O6s6Bm+Z0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Fd4CyuLW4EvKRKBdDvHFYcqX0s0Y10MBU0R0P+vSpn0=; b=Igx2Iak6cvzI/368NaUteLk/qirnfNhkVVPVR2QEMp/erRq3mipNze/EB2ItaVIdZQ Wr9rDfVdWoCK/u3sxo8PGCxfNt6f6zEE3wgpKbKMC09NylkNYUu2Fv9pCHe3bAlB5xgh fOcfQaZk5s7uv4GinOPs28tcv82c2ZzJ21ex+6aV5+YY30zkLqFtUvRHWDM0g2wYuUlI GT594skL/tmbvift5yvv2skaanVBJ88KzZ2ZiLLQH9PgnsBqN9Dmd8XccLUpNZsBNHdp sp2VHI3hGbd3oghncQIrcRCzM6A98hPThLiHY01+UMaI4JlDqLR95DJThFbtdX0FblXV x9Rg== X-Gm-Message-State: AOUpUlHOdTkFW18RVawCUlnolX6e+iiBIlMsDjQQiWNlMmpKOtqdzsEy xmdEq1draC4tXq6PhDnpV8mE6g== X-Received: by 2002:a62:4083:: with SMTP id f3-v6mr18399882pfd.229.1532450996103; Tue, 24 Jul 2018 09:49:56 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id g184-v6sm19038443pgc.22.2018.07.24.09.49.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:49:54 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Arnd Bergmann , Eric Biggers , "Gustavo A. R. Silva" , Alasdair Kergon , Rabin Vincent , Tim Chen , "Rafael J. Wysocki" , Pavel Machek , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Philipp Reisner , Lars Ellenberg , Jens Axboe , Giovanni Cabiddu , Mike Snitzer , Paul Mackerras , Greg Kroah-Hartman , David Howells , Johannes Berg , Tudor-Dan Ambarus , Jia-Ju Bai , Andrew Morton , Geert Uytterhoeven , Josh Poimboeuf , David Woodhouse , Will Deacon , dm-devel@redhat.com, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, qat-linux@intel.com, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 14/18] staging: rtl8192u: ieee80211: Convert from ahash to shash Date: Tue, 24 Jul 2018 09:49:32 -0700 Message-Id: <20180724164936.37477-15-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724164936.37477-1-keescook@chromium.org> References: <20180724164936.37477-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an identical change to the wireless/lib80211 of the same name. In preparing to remove all stack VLA usage from the kernel[1], this removes the discouraged use of AHASH_REQUEST_ON_STACK in favor of the smaller SHASH_DESC_ON_STACK by converting from ahash-wrapped-shash to direct shash. By removing a layer of indirection this both improves performance and reduces stack usage. The stack allocation will be made a fixed size in a later patch to the crypto subsystem. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- .../rtl8192u/ieee80211/ieee80211_crypt_tkip.c | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c index a7efaae4e25a..1088fa0aee0e 100644 --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c @@ -54,9 +54,9 @@ struct ieee80211_tkip_data { int key_idx; struct crypto_skcipher *rx_tfm_arc4; - struct crypto_ahash *rx_tfm_michael; + struct crypto_shash *rx_tfm_michael; struct crypto_skcipher *tx_tfm_arc4; - struct crypto_ahash *tx_tfm_michael; + struct crypto_shash *tx_tfm_michael; /* scratch buffers for virt_to_page() (crypto API) */ u8 rx_hdr[16], tx_hdr[16]; @@ -80,8 +80,7 @@ static void *ieee80211_tkip_init(int key_idx) goto fail; } - priv->tx_tfm_michael = crypto_alloc_ahash("michael_mic", 0, - CRYPTO_ALG_ASYNC); + priv->tx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0); if (IS_ERR(priv->tx_tfm_michael)) { printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " "crypto API michael_mic\n"); @@ -98,8 +97,7 @@ static void *ieee80211_tkip_init(int key_idx) goto fail; } - priv->rx_tfm_michael = crypto_alloc_ahash("michael_mic", 0, - CRYPTO_ALG_ASYNC); + priv->rx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0); if (IS_ERR(priv->rx_tfm_michael)) { printk(KERN_DEBUG "ieee80211_crypt_tkip: could not allocate " "crypto API michael_mic\n"); @@ -111,9 +109,9 @@ static void *ieee80211_tkip_init(int key_idx) fail: if (priv) { - crypto_free_ahash(priv->tx_tfm_michael); + crypto_free_shash(priv->tx_tfm_michael); crypto_free_skcipher(priv->tx_tfm_arc4); - crypto_free_ahash(priv->rx_tfm_michael); + crypto_free_shash(priv->rx_tfm_michael); crypto_free_skcipher(priv->rx_tfm_arc4); kfree(priv); } @@ -127,9 +125,9 @@ static void ieee80211_tkip_deinit(void *priv) struct ieee80211_tkip_data *_priv = priv; if (_priv) { - crypto_free_ahash(_priv->tx_tfm_michael); + crypto_free_shash(_priv->tx_tfm_michael); crypto_free_skcipher(_priv->tx_tfm_arc4); - crypto_free_ahash(_priv->rx_tfm_michael); + crypto_free_shash(_priv->rx_tfm_michael); crypto_free_skcipher(_priv->rx_tfm_arc4); } kfree(priv); @@ -500,30 +498,31 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) return keyidx; } -static int michael_mic(struct crypto_ahash *tfm_michael, u8 *key, u8 *hdr, +static int michael_mic(struct crypto_shash *tfm_michael, u8 *key, u8 *hdr, u8 *data, size_t data_len, u8 *mic) { - AHASH_REQUEST_ON_STACK(req, tfm_michael); - struct scatterlist sg[2]; + SHASH_DESC_ON_STACK(desc, tfm_michael); int err; - if (tfm_michael == NULL) { - printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n"); - return -1; - } - - sg_init_table(sg, 2); - sg_set_buf(&sg[0], hdr, 16); - sg_set_buf(&sg[1], data, data_len); + desc->tfm = tfm_michael; + desc->flags = 0; - if (crypto_ahash_setkey(tfm_michael, key, 8)) + if (crypto_shash_setkey(tfm_michael, key, 8)) return -1; - ahash_request_set_tfm(req, tfm_michael); - ahash_request_set_callback(req, 0, NULL, NULL); - ahash_request_set_crypt(req, sg, mic, data_len + 16); - err = crypto_ahash_digest(req); - ahash_request_zero(req); + err = crypto_shash_init(desc); + if (err) + goto out; + err = crypto_shash_update(desc, hdr, 16); + if (err) + goto out; + err = crypto_shash_update(desc, data, data_len); + if (err) + goto out; + err = crypto_shash_final(desc, mic); + +out: + shash_desc_zero(desc); return err; } @@ -663,9 +662,9 @@ static int ieee80211_tkip_set_key(void *key, int len, u8 *seq, void *priv) { struct ieee80211_tkip_data *tkey = priv; int keyidx; - struct crypto_ahash *tfm = tkey->tx_tfm_michael; + struct crypto_shash *tfm = tkey->tx_tfm_michael; struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4; - struct crypto_ahash *tfm3 = tkey->rx_tfm_michael; + struct crypto_shash *tfm3 = tkey->rx_tfm_michael; struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4; keyidx = tkey->key_idx; -- 2.17.1