From patchwork Tue Jul 24 16:49:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 142816 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp7498599ljj; Tue, 24 Jul 2018 09:56:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe5TlPLgYtyBtVnsOpx7h0REewXtEvAXK7eEmDHxURyaOsu8I+o5g2Wdj53uii/gjJEOh6r X-Received: by 2002:a62:642:: with SMTP id 63-v6mr18647571pfg.222.1532451381697; Tue, 24 Jul 2018 09:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451381; cv=none; d=google.com; s=arc-20160816; b=Fobnp46ffGg2gE9F+Oe87J3oyuKeKAFPditMnyUeyStQwu/qxL70fT3HzepaHPQ6Pa xcppnnhWYmn5ktN65rby6+1+EZDfAZo3OnV4eUojTvBe4QrfTHPASi4fty2nIiHk8tMI EaCTGebuDJ+YtsRc4PidOXJToj1+lDLwhmvGdalEBANHSDDqKWXtYf4azAbfd+/lGVjO 1kQ6mxHnvYOgcH2VioqcXVX/IRw5Dx0V/oTMJxMyDrN0L5pQYwHSU+k+Hx1TjVOPMyN8 abpuBldZfQHqkpGAfeWu54Ri7J/QY11IX0NmP1KVrsMfuM2KfRq9tmO+nYhBlSTl9SVJ x7Cw== 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=SXSUe20DYbH44YyT3AXD6Igiq+2PNNXg+ovqiA/boxo=; b=x8lquBTasuP4Dh49JMGf9R6KBZ6OjQticl/vden61Yt78zUsMYJPWFy4/uxhl73JsP gnmzm0G+70S9clfJLvWuWPXe4jZHG9uxCXXh96nVgCESTd234HOlT6MkuO5tL5wsADXo Bk2h6HAN9p7BqcABXR6RPoIibTJMA3vRBpQZeC1MOEkdr4imhb6G3Cw1t7tjPQ7uQedT dzvd5ExRvFSpmsyMGijIL6mIMZnZVOaxL4YtRZ12mDNrmIk9WBykMfLDUPfdGw4alz62 pkqbkjTRvEyLgEnWCNxE98qiOsgqB1Ef06HHqVmiOp0zEEnPi7u/l8XSejdY4KgGSBff bWqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=X3kCdf0U; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 e1-v6si8073149pfa.274.2018.07.24.09.56.21; Tue, 24 Jul 2018 09:56:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=X3kCdf0U; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S2388550AbeGXSDm (ORCPT + 10 others); Tue, 24 Jul 2018 14:03:42 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46589 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388537AbeGXSDm (ORCPT ); Tue, 24 Jul 2018 14:03:42 -0400 Received: by mail-pg1-f194.google.com with SMTP id p23-v6so3297771pgv.13 for ; Tue, 24 Jul 2018 09:56:19 -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=SXSUe20DYbH44YyT3AXD6Igiq+2PNNXg+ovqiA/boxo=; b=X3kCdf0Uj63XqAnAuieU1YsZS8JiiKErKvsj99jp4RKXC93FHBkqibyLChQHlXi7Vg vn5ozP+TKXJymsuETeBbDnK3EqeHB5k+DWPvr18ZQ6skGgedc/wZdm1WBHKPVQBSqL/X Lc/BlOuZzIHXkUIzWZbM0u99uEHbW/wsxeLCc= 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=SXSUe20DYbH44YyT3AXD6Igiq+2PNNXg+ovqiA/boxo=; b=mOmKTcVmpGBPli3TMM4zQvQJDMqbKGZF5jgX5P0GZVDW87pInrXzyw4FVZ6TPHgUr/ FCUZuk83DpHysmfCvQuRFdGEIuky6V2CivOsgOqoN6KApFEmMqFmNYc75Vttld0MyVcX 3g8i4EVetczwNl2zkGNAYpXGywMdrpgN7YwSIvJ38pOiXHc2QbkODXCpb3gQRmpjX1bf pfn9MMQHmjFnCxDchqfaASGkqhNx2D4vvDOJAFsqm69LK10zh+DBV5DOWP9FaBuEh+MG JQ6FklapRo5eTPWTCErfAg4X9Een3kUo3FxxIiky3MxWrqMS1uruluj6UgR3jhnzpLUF DmGA== X-Gm-Message-State: AOUpUlE4c4Tdd84j/nEUAeh9iU641ZZMfT0BH5pCG2D52WJbyxyQXnUw 64gPgTG0NtlcZI2o9bhXmiIHcQ== X-Received: by 2002:a63:2506:: with SMTP id l6-v6mr16840145pgl.237.1532451378306; Tue, 24 Jul 2018 09:56:18 -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 d145-v6sm18467198pfd.52.2018.07.24.09.56.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:56:16 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Ard Biesheuvel , 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 17/18] crypto: ccm: Remove VLA usage Date: Tue, 24 Jul 2018 09:49:35 -0700 Message-Id: <20180724164936.37477-18-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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Ard Biesheuvel In the quest to remove all stack VLA usage from the kernel[1], this drops AHASH_REQUEST_ON_STACK by preallocated the ahash request area with the skcipher area (which are not used at the same time). [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Ard Biesheuvel Signed-off-by: Kees Cook --- crypto/ccm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/crypto/ccm.c b/crypto/ccm.c index 0a083342ec8c..b242fd0d3262 100644 --- a/crypto/ccm.c +++ b/crypto/ccm.c @@ -50,7 +50,10 @@ struct crypto_ccm_req_priv_ctx { u32 flags; struct scatterlist src[3]; struct scatterlist dst[3]; - struct skcipher_request skreq; + union { + struct ahash_request ahreq; + struct skcipher_request skreq; + }; }; struct cbcmac_tfm_ctx { @@ -181,7 +184,7 @@ static int crypto_ccm_auth(struct aead_request *req, struct scatterlist *plain, struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req); struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead); - AHASH_REQUEST_ON_STACK(ahreq, ctx->mac); + struct ahash_request *ahreq = &pctx->ahreq; unsigned int assoclen = req->assoclen; struct scatterlist sg[3]; u8 *odata = pctx->odata; @@ -427,7 +430,7 @@ static int crypto_ccm_init_tfm(struct crypto_aead *tfm) crypto_aead_set_reqsize( tfm, align + sizeof(struct crypto_ccm_req_priv_ctx) + - crypto_skcipher_reqsize(ctr)); + max(crypto_ahash_reqsize(mac), crypto_skcipher_reqsize(ctr))); return 0;