From patchwork Tue Aug 7 21:18:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 143597 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp55006ljj; Tue, 7 Aug 2018 14:18:49 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwkDyvK1EgQpQLFZzAAFzlLerNWEBKJxgaQI8V1mb4nijfMHDyG2hzOA07zPfzAHAv5iuBe X-Received: by 2002:a63:1844:: with SMTP id 4-v6mr59629pgy.313.1533676729236; Tue, 07 Aug 2018 14:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533676729; cv=none; d=google.com; s=arc-20160816; b=pHjYgraUjZXk53pz5BxBgCaDjW9GoUmoVZv7OywFZkPBNrxx0OvXQ13K3Qmm61vLwu NzOn+YA1dAzUgZ5Sx9nyga5IJTXI7hnxXiwyiKJev9CDfVAnSM15jAUgExx87hFJP03o vNzgn0ZrpWA3+yAVxKCGM1BDH/ULUyc7icCL/dRlgL/orNcwu+5xa7O8kC3LvxqaIC9e 9oRdrZETonCWpfX4tbHgrD5WUgtYF6taxPIvY2NU9e8rMbTW213dZA553unAtsNgoCNl +iLe4Ab4xQ47ResTMzVV7YL6DMNyOSUBJyQNOsD7iWl8aoRTZz7xpxLHrxF+n7T7yMY7 GOHA== 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=cYqwOJ7ESFIZwb4gd+/rbe5MIJRsMeh+zsX7Pq9yPAY=; b=QWCu0KBmPU2gv8bC4IPhbPALk5TzEAexl0UXy7ndGqePVFZI9h51wqmITrVJdDVtlz zpc1nSuYki/BSrmsVM/sgU8g4v7nVwQeiOCYv+aA4FLQWVvH1HYjqAOfJQdiKVzgxTLY d04/Gey+1lIpQ97SrHZx4vRDH3BouOwLxvM9Xz5Zh7D2yU/xadFe8Mvtl7gi4YCreWjb zEg2d25gkf61lsD8USdPyySd9uSs3e2nF63Tw4YHoO7+drxeZBl+viYvTENXY2mLWeR6 OEDkqVlYwUgL7Q5UH5ywaFTTiAjoBRsiPb+N9g2Pn3lV60b79Nv8XGBGGG/nAg42npUm 6Nng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Zv2bO+EV; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT 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 bh12-v6si1814174plb.425.2018.08.07.14.18.49; Tue, 07 Aug 2018 14:18:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=Zv2bO+EV; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbeHGXfG (ORCPT + 2 others); Tue, 7 Aug 2018 19:35:06 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37415 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbeHGXfG (ORCPT ); Tue, 7 Aug 2018 19:35:06 -0400 Received: by mail-pf1-f193.google.com with SMTP id a26-v6so42927pfo.4 for ; Tue, 07 Aug 2018 14:18:47 -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=cYqwOJ7ESFIZwb4gd+/rbe5MIJRsMeh+zsX7Pq9yPAY=; b=Zv2bO+EVmzrhlM21vJwiHRJYvGXpTVd9Hkfi2ozX4bgt1kgLyS4x69k84MZQAaFu5/ rVBPqEXFfYt+ujIFki/OJApGkEi+OiqVD8EtaQlq8fQAE6/sWtdNjk0Tlt1uJE7szewB Ll7wLkOdmIt/ZeTDS8XOyC0JeXjOxep+1Jlno= 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=cYqwOJ7ESFIZwb4gd+/rbe5MIJRsMeh+zsX7Pq9yPAY=; b=NwRbc3D7LGky9785EG4d9AzRKqZjGhe7v6ArIf2OtHYeeRM1PgurHeShfcyDqF0+mQ gySoK5y51UST095o5OU3CaKPqDpMXAb3lAlpw1pbBXHUitgqek28lmy5VM+RYXw8ntc1 JvurZQ5iNOVXxZ7ohkgkEWk+Bcu/rpCndoiKIhnyCKJTOu+BDrepyHfQreeGGXvkrbkw 8MqCIOKnmjb8Z+u1ZnHXViX5dTBnIG8h1CVvp2D9yAycMvus1S/lBNvd3vK9Mn+1g9E7 bAb7JtC0TUuydD/94LcDFu1Hjmyb1rjqtzCXI4o7FKkL3vsj4idRRRqiWECLYC1eHpAO hYEw== X-Gm-Message-State: AOUpUlEC64+Y9z3VX76neEhwDRlbskbiMepw/ezbKYAamVQS+C8VrQGR bb7yiDEC8o664M1Hlgdtri3eVQ== X-Received: by 2002:a63:1c13:: with SMTP id c19-v6mr76678pgc.332.1533676727360; Tue, 07 Aug 2018 14:18:47 -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 e126-v6sm5493576pfg.31.2018.08.07.14.18.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 14:18:46 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Ard Biesheuvel , Eric Biggers , Giovanni Cabiddu , Alasdair Kergon , Mike Snitzer , Tudor-Dan Ambarus , Andrew Morton , Thomas Gleixner , Geert Uytterhoeven , Arnd Bergmann , Will Deacon , Rasmus Villemoes , David Woodhouse , Matthew Wilcox , "David S. Miller" , "Gustavo A. R. Silva" , linux-crypto@vger.kernel.org, dm-devel@redhat.com, qat-linux@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 3/9] crypto: ccm: Remove VLA usage Date: Tue, 7 Aug 2018 14:18:37 -0700 Message-Id: <20180807211843.47586-4-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180807211843.47586-1-keescook@chromium.org> References: <20180807211843.47586-1-keescook@chromium.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@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 preallocating the ahash request area combined 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;