Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp80923imm; Tue, 7 Aug 2018 14:20:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwEKNQAhyqwNltaGbxRJR9IBQdZxqh92QLWDWR9lOCX4dDSRJu0xcucC30IFiGOHooDJGux X-Received: by 2002:a62:4255:: with SMTP id p82-v6mr88307pfa.238.1533676805209; Tue, 07 Aug 2018 14:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533676805; cv=none; d=google.com; s=arc-20160816; b=hMqe/tRgW4iYEnQYG5RBQabQm9hVutHQdDhYfbkCFXP9MDpW+hxC4dTYMLgFfpF4w8 SUZu/vVRFZWbCb+PjWxGPCjrJobl/lCAGineE1MSI7Vu3g/m0L8+L5wOPduyH7yjvC3k 9hNuwcTBHTz6Be9jaXqBuXD+yjkAIV2aflCyjx2skgPToaPwZh+gSlfdrYM+wJss9G3x r5R1DTR2HstkRsCUIzWzXAGqHRWgKZ5E4dUxjKKeteA/5U7FEmmQJ5GAm60UGggoKQtL 51iHAXBvIzJ5fD1YChXn1fCUG9WgspczdmSPQBGutvJYk+llnkrAmUcVctgjZG7V05J+ gCqw== 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=uMyjSZBptaOl9GI76GL4JC3A9hlhZaJUJOMp4n4M4nrggwcHWu4Oy3DSIZzCLl9ZZz M2LjQDJ7KdRx6U21lKbg8/0o/TV+hnUDAaW8mBGfTLfcRhpG5aPQX0XHVnRt3mX4ClIi EHtG3ncgnNbJUDCh87Ml07qls1olISlb2+E/tioYCWMlFhukG7fRWg0xIJvFaLh9+Uv+ VOc6xdQToJLiMOXqhgykAcBcn133DbFk5V26U0e8OTMzCqFdo0pxakeyGY37E28iwYWa oCvYuAQuRuKzq95J3/w6tIJQIS0cBwyv16NZoTNJzkjgkrvUnSfJRtX4SHgldZvv7xUU PQlg== 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-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 f1-v6si2055855plm.375.2018.08.07.14.19.49; Tue, 07 Aug 2018 14:20:05 -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=Zv2bO+EV; 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 S1726953AbeHGXfG (ORCPT + 99 others); Tue, 7 Aug 2018 19:35:06 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42094 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726414AbeHGXfG (ORCPT ); Tue, 7 Aug 2018 19:35:06 -0400 Received: by mail-pf1-f195.google.com with SMTP id l9-v6so31708pff.9 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=Bth52cJ/KvzL61X7wE9ldkGp4d7diXRTvcAXbbYAxAMbqgHbEAJG3eeCf1GVnDhYLs Yw0rcBP0e70omkKd0caGpiN1uVA0cpwrKjioVXeW7k/MsnfpUtt/r0O77RBMTGozPhhj tOwgv3PqPhN+wZyWK9g7HVrOoR90Ya9U4guPORuJWuKLSFka/c46M9hV4eFzEyPc/Z+u wUFK/GPxpCBkrTZXg0e3vPfd2yMu1LADzLRoFt2xbJi56Ef6XZEM5t+844olAj0XvXOv Rs9LhuXm2ZdNMqhNCMjqQj25PR3iGx3V7C5ljcxAEUBM+L391A8dUK3kGSneB1DBGUE8 1ntQ== X-Gm-Message-State: AOUpUlEkIy1t22Q8HhHW3mWC/Qbnb7RZpcVvVLf5c8KXRKytaBdQmrgE r28MIbLXeYfAVc8dCPTasfJ04A== 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-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(-) 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