Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp420891imm; Thu, 28 Jun 2018 23:33:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIGjAzNqsua0zPrJw1hBjotfz+Kr0m3FeIY+1UPcSW2T0S0vII+qmmkRucLxkNp6R/8psZU X-Received: by 2002:a17:902:14b:: with SMTP id 69-v6mr13638311plb.184.1530254037201; Thu, 28 Jun 2018 23:33:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530254037; cv=none; d=google.com; s=arc-20160816; b=G1fGABsLXmZbS+UIbaC2KLtSA2x//6/KAPmm60eCVsZVTbmbVEFZZGhJ+WQ0tM3uJP M//kx1vcD61VWnBYk+q+xwtg9Wgni4ODn6b5Q8QEW3V0osvETw6PLXKVUv0i6FO7Fldy nisQdwHtKayM+nVPXPAFNfNemvzk0D70FJo+WZ9y5nvDlNO6LPsPAnw5zEwOiy+xDVZK oWL072krSs0Cepv5pMMLMKCMLTkPqCtquqWuvRylpegfh8bbSWy/Uci/p4LJ6lxSQM5Y g9X6QVjoJsSrYIYhYOtmnQW7NZ6M3wQAzOIp099/wC8ookG6S/tlXRdA3aeTUa+5w6Kj qJLg== 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=JBfo1fF2PqSm7e4PfP+/dVxXoai8pEOtQGF0NnToX8o=; b=ARqYD4cho7B8AGKcb1HY8gllRorqHBZyFcT4/V3dQ2kDCrTXBcaLpbHdV2BWH6qcHp K9hSis23F/wOc+cIU2zePFlniIzH420iWTYOLYmhHFJpkxOvNPqZaHDO1UDusJImJ0F5 hii8xGsIBWdqSBlM8aVN1fW/dWrnOQbUhqgpccTq+nkrA+UXiY7NaRbbdK6SB9uzf8Ci FvVa91SALoIRInKNHmO068CWBkgOd4q3KL/uJG13/R53IAJR6OjXGEsOyW8L7TTt1npC YUkSMLRtmeU0yZx4w1yq1+/0RZAUptyif/DYDdI18HTlLe/+9cdbPUNTxZkow1c1MAub nEiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YKGDFhFt; 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 c13-v6si7246586pgq.316.2018.06.28.23.33.42; Thu, 28 Jun 2018 23:33:57 -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=YKGDFhFt; 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 S1030389AbeF2Aa3 (ORCPT + 99 others); Thu, 28 Jun 2018 20:30:29 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:44720 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935851AbeF2A2x (ORCPT ); Thu, 28 Jun 2018 20:28:53 -0400 Received: by mail-pf0-f193.google.com with SMTP id j3-v6so3355674pfh.11 for ; Thu, 28 Jun 2018 17:28:53 -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=JBfo1fF2PqSm7e4PfP+/dVxXoai8pEOtQGF0NnToX8o=; b=YKGDFhFtacjeAovU5Uk0Oqx1NcPS9G3M4QG6MT9MJZ81Kfrqd2VEVw3+i+JNfuaNqy T0vrXko/VSVhVWhiuXOqofnq8ceG2iHGVZlCCv0CIKzeKHdmzwJeHEtf3crvGViOmRq3 RVzZ4FQxSpFWe9iBaMUGl1J7KCHWj2Jkbw0zs= 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=JBfo1fF2PqSm7e4PfP+/dVxXoai8pEOtQGF0NnToX8o=; b=kT2+jbG3+Nerk65lQPHCMlFozwgIb0V/KesojpSs14ePF8qxi35H/sXXAu2awmUpIf rX3csCmx2lts+oPn/X+n+rayNpp/biszI+YKWgYLzd1VogKZ1DGwSRwU6rC27K5nrOWS mlOudKPnodpMyM+RQUb/85Ljo/6hb/0JBtMamwkKG0L772Qun+0a9cy5BbDVY2xP3Smf 1OhE15S9+VG6y4xuEYrAyxc9tAAThhxzQIyRIvMoS7XlAoPCj8WtYoPX/SNFqP9fiySY KZo0fHNH54C0uNR7QnqTDBJ7+TZEmis+zTbdgm8WqlrUeO4s+sT9mT7JpncBIFFaZmhG ynLA== X-Gm-Message-State: APt69E3ThAmCUcul5TScooMsUIFWwvAkknWuqZpoTAsZNaNubJbM38Dk uLL7B3vgI9iaJRcc+iVB7ABx2Q== X-Received: by 2002:a63:384c:: with SMTP id h12-v6mr10576887pgn.230.1530232133416; Thu, 28 Jun 2018 17:28:53 -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 b62-v6sm16125302pfm.24.2018.06.28.17.28.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 17:28:48 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , "Gustavo A. R. Silva" , Arnd Bergmann , Eric Biggers , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , "David S. Miller" , linux-crypto@vger.kernel.org, qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] crypto: xcbc: Remove VLA usage Date: Thu, 28 Jun 2018 17:28:35 -0700 Message-Id: <20180629002843.31095-2-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629002843.31095-1-keescook@chromium.org> References: <20180629002843.31095-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the quest to remove all stack VLA usage from the kernel[1], this uses the maximum blocksize and adds a sanity check. For xcbc, the blocksize must always be 16, so use that, since it's already being enforced during instantiation. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- crypto/xcbc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crypto/xcbc.c b/crypto/xcbc.c index 25c75af50d3f..7aa03beed795 100644 --- a/crypto/xcbc.c +++ b/crypto/xcbc.c @@ -57,6 +57,8 @@ struct xcbc_desc_ctx { u8 ctx[]; }; +#define XCBC_BLOCKSIZE 16 + static int crypto_xcbc_digest_setkey(struct crypto_shash *parent, const u8 *inkey, unsigned int keylen) { @@ -65,7 +67,10 @@ static int crypto_xcbc_digest_setkey(struct crypto_shash *parent, int bs = crypto_shash_blocksize(parent); u8 *consts = PTR_ALIGN(&ctx->ctx[0], alignmask + 1); int err = 0; - u8 key1[bs]; + u8 key1[XCBC_BLOCKSIZE]; + + if (WARN_ON(bs > sizeof(key1))) + return -EINVAL; if ((err = crypto_cipher_setkey(ctx->child, inkey, keylen))) return err; @@ -212,7 +217,7 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb) return PTR_ERR(alg); switch(alg->cra_blocksize) { - case 16: + case XCBC_BLOCKSIZE: break; default: goto out_put_alg; -- 2.17.1