Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7195689imm; Tue, 24 Jul 2018 09:57:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfkG0RTDat48s/dj6Zz58prU7qXGkwcEbMjbkqTozHdN2Fqe5SNqqM+4g0iA36SGFGDqHeu X-Received: by 2002:a17:902:6b84:: with SMTP id p4-v6mr17685344plk.272.1532451457490; Tue, 24 Jul 2018 09:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451457; cv=none; d=google.com; s=arc-20160816; b=Z9kH1zNRxf51l+WwfQyVAYuwz7AluCtpyIdiOrIIKCRCWd71AEEzoAbkMmWhPcYaZe cqNr87m4OQMiD1az7zQHP2KYJSS4t2IXIHUtQTbyy1fz1wfbwWxZN8Nh0fPGThL6vrBl T6RKURMn1xZ2mey1BPMs50uXzPaA/rY8tbDcfGab/NMLNYiHRBz2MAtm3CDnDAOlNbyU BtfyDpQB62O1Zp9gWFy4V3iv6GzomLgxo+/zP69vYHYJwGxwFUfUrtpS3++5WJUsGBe/ 9yhNNpxZy3GlbUfWrpi+lZhmI3Pp3yBrC6UrHwqJSiyWU+98t8Mna0bggPUUY0vd0KSt VOhg== 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=rY4YuVuUYi0T7Kc7rAxIGGlyNCX/bxtUNG26en6PXbV/O5oyPQVJsGzNHKNogWubhL SK2/+DCov7nz+nQ1BKabL6VAj0E1K2T+3oruDkjpyqn5+nAzbAy7iZcqArWO4VWfjdHc 0XeISQAqumU9Yo2LhahPg199GZDStKb0CQKPjmPQPgt1JuZ/UgcrVFoNGKdv7ZZx0BBG IS0LCKuifDYGkm53jvmzYbVN7HVXxqKyFbMmKTOFq66b814bsprPlyKtP0eNVzxc457w ulJN2tqvRqYnORm/yxwlD4KAEVOYQYFekjl9tCVFPhS8+/pPNFtf7pEceeJzptLxK4v8 QD2A== 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-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 r21-v6si12008656pgu.55.2018.07.24.09.57.22; Tue, 24 Jul 2018 09:57:37 -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=X3kCdf0U; 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 S2388562AbeGXSDm (ORCPT + 99 others); Tue, 24 Jul 2018 14:03:42 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35030 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388533AbeGXSDm (ORCPT ); Tue, 24 Jul 2018 14:03:42 -0400 Received: by mail-pg1-f194.google.com with SMTP id e6-v6so3312500pgv.2 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=OC5ABNORxeauGd4bF3WsMy/xsy9fdbDXnOhfEZtWMGm9NeCnfhQzFEtx/HxOeL9zws CvV5QGMRULcUaoiB8/qzDEt/W7g3GfO8KZOL2SfXtsdSWVbTfVfLEJRy4YpWkjGqr50Y MFNCpEQOOBDG4rlVsqYnAEYNiWf2UCeP2kIGvq4tAaKz5FVyiBxiqaHIbRVuofwHj+Wy 5nivXPlL+t3cmsPahLoHDCCpJIdTLAel+Ioou12b9WaeTSsq8KhwD7hMl4eFUuVPLlKM 8GJAOtNP9gMUUVXX8ueA0Hoo0FYVSbu3MPkfsQp7nihHzNIF0WMARPLyzliBPiSko6Er zZsA== X-Gm-Message-State: AOUpUlE9DaU9px225rZzpA9W0VJQnpjqvNxEk3D3IUR49MG2GevOgm2p xNPFqr3L65Ff78ivgsJKsLGv5Q== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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; -- 2.17.1