Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7192946imm; Tue, 24 Jul 2018 09:54:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe+XluFIAtZTJAua1ki4ztBsixfXMJHYioovg1LUeSU0rTJWknJRfvhyenwS91B6wk+iqfE X-Received: by 2002:a62:c00c:: with SMTP id x12-v6mr18444846pff.216.1532451276227; Tue, 24 Jul 2018 09:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451276; cv=none; d=google.com; s=arc-20160816; b=iSdt5vRidC+Q92MQFSfpI/zq6xx4Ihh8lkbXleZ8jTpn8me5NdIVkkG+oeYhtdlPa1 aDhc4fXetezdxHTcTbpv+gpabzlxtjjJZH7plkr0BjZrgRYuYcEhtyy37aE/VwcSrqYf Zu6fY5hdABNL4SyYjDd3J+92vktG/Tv1c4HxDoHS7luC7T1obn2zSR5dZy0RdEt9Dqzc Bk+ytx0II66feVvToy/6oWbjMhLec25B0FUqvhh27Yw6gaJD1CZNCgDkp95aoETJ2i4U hy+UYhYjk50higJpOLdCqQC4VmTIa4n6zh8ywmBKaUi9BLXcoRdnGeHIAJW/64cHDR7b W4Jg== 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=EgkhKZ/Kq1WYLP+KKm550fKJfIA30Q04zx67UHx5CVw=; b=h2+gkM6t/BqF1AklrBYMPdUtTdo0Se33EKNImhIMAflMwEU8GvbE1WMvGj1qlWdN2K eu9YFUy8KQ+5xdD9XPkm1FhTcMI1EsT2yKROg62R+xjCyFKr1THRybSY5b0PoqOdtXYt WU2SAm9Erf3hefG4xcNhbfvAjHg01/pMnsdBTS6V6mhjHTk4lLVfqQMgi14ANdkX9B5Q RjDmMZ8rrgu1+i+6aDxVgZaGUj+00BVEK3X9ubTwNEn7Qpezh4VjiZPmXzwQzku5/5pG xPNoLpGI1gvtLQYCM6cr7c1W8gYul+y1Z8NsEoSAQfH4vGOo1QVyVp9Tyi8jInQwGjrM t90g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S92o1ZFw; 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 z125-v6si11515388pfz.10.2018.07.24.09.54.21; Tue, 24 Jul 2018 09:54:36 -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=S92o1ZFw; 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 S2388777AbeGXR7J (ORCPT + 99 others); Tue, 24 Jul 2018 13:59:09 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:39465 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388619AbeGXR5O (ORCPT ); Tue, 24 Jul 2018 13:57:14 -0400 Received: by mail-pf1-f196.google.com with SMTP id j8-v6so982195pff.6 for ; Tue, 24 Jul 2018 09:49:53 -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=EgkhKZ/Kq1WYLP+KKm550fKJfIA30Q04zx67UHx5CVw=; b=S92o1ZFwaZ2aylf4k1VTGxvWM7JZPhGcyXrz7iZHR94z/kaZL0L6kH2rRGVWrH6iju eUpSLl/7EISqe9730FeeGBGn7J6lWJa1DO2CrW7zgkLsAF3YR1X8Wk74laRSb+Zs4zvj SYx8wnid83S/p8ReZrV3kGlfr/ZxMOFmYYKnA= 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=EgkhKZ/Kq1WYLP+KKm550fKJfIA30Q04zx67UHx5CVw=; b=kquDSHK/MMZHBKVNRQTruaOd5xMeHckfEZ9uBfu0udKY082tATeua0bgwG+I6wBLIG 2Hyi3X8YzfmLfbOXD9rG/LzSvemFo3rpz3ZMC7GMIJI4LjqlUaegtiM0q5S2SgWhv5g3 XUZ2y9iwU+pc3QpYg2wK7jb2ErdjcizgGu4vVMJqqb2906vTiXkUPKV39Dwe28JKQ2wp IZ8sDpLoSXwCeKkMbQ75cGhEFtbJuZm8ZHyNU8xs492rMeDU/23jO1BIVLO+5P3tu/GQ 6YFVviLeagQw2zvlQMmhK07vE7UUTQZ0DmeHASKDmd+qd+vIqmHirNltHavzI/8Mb8kr 8P7Q== X-Gm-Message-State: AOUpUlGbKjsgwn2PjQpIkYx9ReX+bo6ehtm1bZyn+6CnMAMjvDoJBIPI i0O0DHpN9IZrBlk3QXrPDUe1ew== X-Received: by 2002:a62:9d14:: with SMTP id i20-v6mr18485201pfd.3.1532450992941; Tue, 24 Jul 2018 09:49:52 -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 a15-v6sm19835983pfe.32.2018.07.24.09.49.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:49:47 -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 09/18] ppp: mppe: Remove VLA usage Date: Tue, 24 Jul 2018 09:49:27 -0700 Message-Id: <20180724164936.37477-10-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 In the quest to remove all stack VLA usage from the kernel[1], this removes the discouraged use of AHASH_REQUEST_ON_STACK (and associated VLA) by switching to shash directly and keeping the associated descriptor allocated with the regular state on the heap. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook Acked-by: Arnd Bergmann --- drivers/net/ppp/ppp_mppe.c | 56 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/drivers/net/ppp/ppp_mppe.c b/drivers/net/ppp/ppp_mppe.c index 6c7fd98cb00a..a205750b431b 100644 --- a/drivers/net/ppp/ppp_mppe.c +++ b/drivers/net/ppp/ppp_mppe.c @@ -96,7 +96,7 @@ static inline void sha_pad_init(struct sha_pad *shapad) */ struct ppp_mppe_state { struct crypto_skcipher *arc4; - struct crypto_ahash *sha1; + struct shash_desc *sha1; unsigned char *sha1_digest; unsigned char master_key[MPPE_MAX_KEY_LEN]; unsigned char session_key[MPPE_MAX_KEY_LEN]; @@ -136,25 +136,16 @@ struct ppp_mppe_state { */ static void get_new_key_from_sha(struct ppp_mppe_state * state) { - AHASH_REQUEST_ON_STACK(req, state->sha1); - struct scatterlist sg[4]; - unsigned int nbytes; - - sg_init_table(sg, 4); - - nbytes = setup_sg(&sg[0], state->master_key, state->keylen); - nbytes += setup_sg(&sg[1], sha_pad->sha_pad1, - sizeof(sha_pad->sha_pad1)); - nbytes += setup_sg(&sg[2], state->session_key, state->keylen); - nbytes += setup_sg(&sg[3], sha_pad->sha_pad2, - sizeof(sha_pad->sha_pad2)); - - ahash_request_set_tfm(req, state->sha1); - ahash_request_set_callback(req, 0, NULL, NULL); - ahash_request_set_crypt(req, sg, state->sha1_digest, nbytes); - - crypto_ahash_digest(req); - ahash_request_zero(req); + crypto_shash_init(state->sha1); + crypto_shash_update(state->sha1, state->master_key, + state->keylen); + crypto_shash_update(state->sha1, sha_pad->sha_pad1, + sizeof(sha_pad->sha_pad1)); + crypto_shash_update(state->sha1, state->session_key, + state->keylen); + crypto_shash_update(state->sha1, sha_pad->sha_pad2, + sizeof(sha_pad->sha_pad2)); + crypto_shash_final(state->sha1, state->sha1_digest); } /* @@ -200,6 +191,7 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) static void *mppe_alloc(unsigned char *options, int optlen) { struct ppp_mppe_state *state; + struct crypto_shash *shash; unsigned int digestsize; if (optlen != CILEN_MPPE + sizeof(state->master_key) || @@ -217,13 +209,21 @@ static void *mppe_alloc(unsigned char *options, int optlen) goto out_free; } - state->sha1 = crypto_alloc_ahash("sha1", 0, CRYPTO_ALG_ASYNC); - if (IS_ERR(state->sha1)) { - state->sha1 = NULL; + shash = crypto_alloc_shash("sha1", 0, 0); + if (IS_ERR(shash)) + goto out_free; + + state->sha1 = kmalloc(sizeof(*state->sha1) + + crypto_shash_descsize(shash), + GFP_KERNEL); + if (!state->sha1) { + crypto_free_shash(shash); goto out_free; } + state->sha1->tfm = shash; + state->sha1->flags = 0; - digestsize = crypto_ahash_digestsize(state->sha1); + digestsize = crypto_shash_digestsize(shash); if (digestsize < MPPE_MAX_KEY_LEN) goto out_free; @@ -246,7 +246,10 @@ static void *mppe_alloc(unsigned char *options, int optlen) out_free: kfree(state->sha1_digest); - crypto_free_ahash(state->sha1); + if (state->sha1) { + crypto_free_shash(state->sha1->tfm); + kzfree(state->sha1); + } crypto_free_skcipher(state->arc4); kfree(state); out: @@ -261,7 +264,8 @@ static void mppe_free(void *arg) struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg; if (state) { kfree(state->sha1_digest); - crypto_free_ahash(state->sha1); + crypto_free_shash(state->sha1->tfm); + kzfree(state->sha1); crypto_free_skcipher(state->arc4); kfree(state); } -- 2.17.1