From patchwork Thu Aug 2 22:51:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 143372 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2718679ljj; Thu, 2 Aug 2018 15:52:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc9c8KBqaiixT/QPhJo6XObYxxeoIOJ/eoR8yfFKlrKqhYdW4jjiboG53BnWqGrx6oMldZZ X-Received: by 2002:a17:902:5582:: with SMTP id g2-v6mr1160524pli.328.1533250322234; Thu, 02 Aug 2018 15:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533250322; cv=none; d=google.com; s=arc-20160816; b=wh2++fbOdvw/10isyzFCngoffCjxOZPfJOOWbHrPNkwKddMCa8utP9ae56mdyiO+TP ZcA1x0nk5SWa7Xr1YD5QtxYmNJHZs5FW7qQ2PJFgIIi0BkPM93l39BEz4ZxGvHkVrNnW nD13BkNjKs3rq2zg7ko32f0Ltl2EuWDJDG+dfiDYOnb8jnEhMehjjcRsJh1929dzfDlw 4vvY85TheZ5Jdwb3S9bOePD4kY6dEwe/pHn2nyH9JWgUz8WGIbBgHzMRUrQNSCZReMEh 381T38Deti6HA1RDEK9eiwu6o0Us6m9Gwt4HmlRlnscDBwPRfAuKg0uxooMmKo8NoGvs LQyA== 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=mbFtB0HFLVOf85zm1vVbrIYN1KG2upc6hKL7BlDmsbfiDacT5c+vHDzVi01G3Kh+R4 3bfdqjsK8tzBasdR/J32Hmd02zn3GRa9wqC8AJnrFZc3d+ylPvDES14dyWFMf94RmnBv lweNXPFbZ/F4LvQ91i56L63yWTu7ZI3kO08u42q2886PPwBxADuQyubLkMAB7M7awjkV mmZkEy7T3sg99MmsB8a2ub0zKYof3dSM0fjM6dsUHL44XgJvVNFuaHMC7BDwZXwykSaJ WD8xVsAb6yjUiBPtK/IQaBoxKU/nJTM3M5trlhttPj7VCGjIJmd2P5vPaRoThOx72Dks Vo1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mTY19WAX; 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=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 q11-v6si2790816pli.86.2018.08.02.15.52.01; Thu, 02 Aug 2018 15:52:02 -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=mTY19WAX; 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=REJECT sp=REJECT dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731911AbeHCApO (ORCPT + 31 others); Thu, 2 Aug 2018 20:45:14 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43516 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727299AbeHCApO (ORCPT ); Thu, 2 Aug 2018 20:45:14 -0400 Received: by mail-pg1-f195.google.com with SMTP id d17-v6so1880200pgv.10 for ; Thu, 02 Aug 2018 15:51:58 -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=mTY19WAXKcACv2jHRUfcKmGhLkXkq85tiOxXJpcFj0PAX9lWdyvUM9LqDcHa6iBIG/ IiVeCwl6vqLnRdkeoxpKqO8dH/xl00FXb/lTnVVb0ztRX032O5A+wUw86q+fl6g1gK+e zB2UK6iF1LM/YHdusCOZ0lTsaU8j2aRNlKuyw= 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=Pj7UPckBLsnPVjFyMycCmbdN2pbZ9tsNTK1UclRdM2j4HdLdTDdfnK6ln0I+/sVBHV LDarfdq0QP46J7wc0grcUs9p/M24NjBZgC+TnO56aEXSpb0ZD+6OJYh9zjwEtcmbcmlR xQ/L0Om84hJKm6RbyDyWkAZFXNPNsCdQ5dAgt6SvOCGloTfHye/TQEKruMFeZaw1HDEd fgrEDlAgbW19WNsqBecQhfLGXvKnH5YIzDGu1Ybf6oyPfItxZMdWltSWpZWiJdso9CLs mS+Y1GAtvDay5J4SLamH9uGrb4CspmYynJQtt9ADIIMXhceS9HUQhSB7Ff7/wnqWkkm1 9jGw== X-Gm-Message-State: AOUpUlFxPYaH2e0MFyd9cp68v9rSsUgtIhxq07IUlmR+vtzQCJhQRHaD DGM7bzygiG0B7FnNLGogChZciw== X-Received: by 2002:a63:f344:: with SMTP id t4-v6mr1222258pgj.428.1533250318354; Thu, 02 Aug 2018 15:51:58 -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 q10-v6sm4050397pfh.124.2018.08.02.15.51.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Aug 2018 15:51:56 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Ard Biesheuvel , Giovanni Cabiddu , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Tudor-Dan Ambarus , Andrew Morton , Thomas Gleixner , Geert Uytterhoeven , Arnd Bergmann , Will Deacon , Rasmus Villemoes , David Woodhouse , Matthew Wilcox , "David S. Miller" , linux-crypto@vger.kernel.org, qat-linux@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v7 3/9] crypto: ccm: Remove VLA usage Date: Thu, 2 Aug 2018 15:51:46 -0700 Message-Id: <20180802225152.19194-4-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180802225152.19194-1-keescook@chromium.org> References: <20180802225152.19194-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 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;