From patchwork Wed Jul 11 20:36:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10520485 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EAE57603D7 for ; Wed, 11 Jul 2018 20:38:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC5EE206E2 for ; Wed, 11 Jul 2018 20:38:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFF5328DE3; Wed, 11 Jul 2018 20:38:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73F43206E2 for ; Wed, 11 Jul 2018 20:38:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733263AbeGKUoC (ORCPT ); Wed, 11 Jul 2018 16:44:02 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:46804 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389956AbeGKUma (ORCPT ); Wed, 11 Jul 2018 16:42:30 -0400 Received: by mail-pl0-f65.google.com with SMTP id 30-v6so9644839pld.13 for ; Wed, 11 Jul 2018 13:36:27 -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=XuzogMugad7VfntrwqFlAbg699VmL688QYLzpI7JajgNZu4UDGBSKvZLyFV9bolsGE NNY/r6qVOfsEMiMrBrDDSBbSIwycjNIusJrG+eZYWcAuxq7pYpoVUCvJq2iYa4qQL17+ rTXz2Y8zGziI6YwoR6J1cyZpgoA1ihpV8VZ2E= 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=Z2W7QEVVEs1roiUWAW/u+Zi5hQALPGFPfQvxsG5Mf3FMjAh11ng0RgHfTjD8vQj7IZ yEtSN6Ikj+tQq+2N1M1xRaRNYTKCGYuc6AY4n5uvvEROLKKdpL2YSqoo4AIu0gnlDY/C OR4evvJ0DBVuT4RLfSu5h5pXq1kNJMEggJSelLMAGcx6W/oXoVjUkOgsJO5i0EsH3qRT i0GgiHZkWwsecg88pRBLtueGz8wgVdjQJLte0gHiqGqk7cTLQ3ka91KQKytVjRLS7kDM yf67Uucqw+u6t9TlB7T1s5V5E1dzMyv/s9C70l6GgBYDKliH8vQql+VNBFI3NcM9emsN yxnQ== X-Gm-Message-State: AOUpUlE442T0iUptnm6J702Megyh2WpSvvI2zA9ftUchzt2fjGEy1cqz 1QJDiUmW2/OirlRImwtIaQEaVA== X-Google-Smtp-Source: AAOMgpc6crFFXMtTNY+Tvcq/rd5+M87zPS+8kyt5D/1IK8oKZjsv9LEHOcz7AhHEFMzVG0y6iT3umw== X-Received: by 2002:a17:902:d218:: with SMTP id t24-v6mr131327ply.63.1531341387061; Wed, 11 Jul 2018 13:36:27 -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 f19-v6sm21047568pfd.147.2018.07.11.13.36.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Jul 2018 13:36:23 -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" , Masahiro Yamada , linux-crypto@vger.kernel.org, qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v4 01/14] crypto: xcbc: Remove VLA usage Date: Wed, 11 Jul 2018 13:36:06 -0700 Message-Id: <20180711203619.1020-2-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711203619.1020-1-keescook@chromium.org> References: <20180711203619.1020-1-keescook@chromium.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;