From patchwork Tue Jul 24 16:49:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10542533 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B597C112E for ; Tue, 24 Jul 2018 16:50:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CFA829064 for ; Tue, 24 Jul 2018 16:50:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 988DC2908E; Tue, 24 Jul 2018 16:50:15 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 05B18290E1 for ; Tue, 24 Jul 2018 16:50:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1C14307CF2C; Tue, 24 Jul 2018 16:50:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DB9A30012B1; Tue, 24 Jul 2018 16:50:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4467A18037F5; Tue, 24 Jul 2018 16:50:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6OGntNW010882 for ; Tue, 24 Jul 2018 12:49:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2BD9E60E37; Tue, 24 Jul 2018 16:49:55 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 091BD60C8F for ; Tue, 24 Jul 2018 16:49:54 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 795917CDF4 for ; Tue, 24 Jul 2018 16:49:53 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id b17-v6so985662pfi.0 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=Dwe0G31RVRSksRMQ9QABGc64/hBtk8WAtziZWx+jZEOgCzLLnstr8CH3pxObDdP93B jBw79k5Iezl4EOVhrdN6cBBLrGLGgrAtSZe5TT4QuLh4J0oUUE8CerP1eyK8PEtjOe6i LD8XVyfV6nk/XVleCHZMccLMKwJyUh0aIGzO1972YCL0nYyupXnxSWLkz8orLFMerilq L0qVyuUULrBZVZXgXZm/jrBQHxgVvJRseP+m8AzjLKdlR5pFte+4wKfNZ/udmN46N+gV dXbGjsjZihQgLDjKCcfEtPZwsjjwK2WCBWe2lt8JG4MmNy33YEBXDiNwsnwHpLU3pzlN 1cCQ== X-Gm-Message-State: AOUpUlG42a/s05YjPXupEUVp3uaF8DYiQBvlF/upixFAM0A2koSRAYvN w9C836Zg0fjSkA829F3XYy3cGg== X-Google-Smtp-Source: AAOMgpflp49N0AC5xiB8mpCD9AbiIwFcdTzaeSIcKVrYl9oEty5XsAmRJYRzowpikmxDTVIEKkvfJg== 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 Date: Tue, 24 Jul 2018 09:49:27 -0700 Message-Id: <20180724164936.37477-10-keescook@chromium.org> In-Reply-To: <20180724164936.37477-1-keescook@chromium.org> References: <20180724164936.37477-1-keescook@chromium.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 24 Jul 2018 16:49:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 24 Jul 2018 16:49:53 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'keescook@chromium.org' RCPT:'' X-RedHat-Spam-Score: -0.131 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: Giovanni Cabiddu , Mike Snitzer , "Gustavo A. R. Silva" , linux-wireless@vger.kernel.org, Will Deacon , linux-kernel@vger.kernel.org, David Howells , dm-devel@redhat.com, Jia-Ju Bai , Paul Mackerras , Pavel Machek , "H. Peter Anvin" , linux-afs@lists.infradead.org, Alasdair Kergon , Kees Cook , devel@driverdev.osuosl.org, x86@kernel.org, qat-linux@intel.com, Ingo Molnar , Eric Biggers , Geert Uytterhoeven , drbd-dev@lists.linbit.com, Rabin Vincent , Arnd Bergmann , Tudor-Dan Ambarus , linux-block@vger.kernel.org, Josh Poimboeuf , Thomas Gleixner , Lars Ellenberg , Jens Axboe , Andrew Morton , Greg Kroah-Hartman , linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Philipp Reisner , linux-crypto@vger.kernel.org, linux-ppp@vger.kernel.org, Johannes Berg , Tim Chen , netdev@vger.kernel.org, David Woodhouse Subject: [dm-devel] [PATCH v6 09/18] ppp: mppe: Remove VLA usage X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 24 Jul 2018 16:50:14 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP 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); }