From patchwork Thu Aug 2 22:51:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10554283 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-2.web.codeaurora.org (Postfix) with ESMTP id 271AC13BF for ; Thu, 2 Aug 2018 22:52:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13E342C4C2 for ; Thu, 2 Aug 2018 22:52:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 081A52C4E1; Thu, 2 Aug 2018 22:52:03 +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=ham 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 AB83B2C4C2 for ; Thu, 2 Aug 2018 22:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732067AbeHCApQ (ORCPT ); Thu, 2 Aug 2018 20:45:16 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41516 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731944AbeHCApQ (ORCPT ); Thu, 2 Aug 2018 20:45:16 -0400 Received: by mail-pg1-f194.google.com with SMTP id z8-v6so1887687pgu.8 for ; Thu, 02 Aug 2018 15:51:59 -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=4w4IN2J6dONrrlVeO1+L0Kz9qBIwIaC7ttYkBFQeQFw=; b=MJPtM5DrXi71NqaWEQYItiJlS3TD+nNAyTVAZSz56FSXdi41JPXEIZCHRfaKPO4EGa r9bnOJ8j0gTaHlb1zSUOXZYTYqTmHxwiIH5BGkUWd3Jcc5cQZ/Yq23cOPaClZMMODbr/ CojOQODYnJ/R98Ahr+wnJbTn5SrM8+olatYVs= 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=4w4IN2J6dONrrlVeO1+L0Kz9qBIwIaC7ttYkBFQeQFw=; b=r+Yz1fRcpKfMJ1Y8UmDHuUp+ndkVRtw8HbE/8tP8+Z9URRrueJ+ghXaMA8NdKxcPDV zVOdciuSpuDHUJ6fQpBiXTwPDPdJjAoQIdP1Qj/B/rn7vtsQDOULhjo/IilP43Gh/Ur9 0/1BzYW4Bw5ZCseuYCSdC8sQv0PdEejPsiCXby8+YdHlT7YpDt5jPUmR+jkRimjzU7ud u7Uxcw8lI9F8pTjHfiBW9008nL9oibxJu5eEg2xY20ULn5AB6e/5O1OpJVHAIVJPaYbM ul95nxx54hObNT8xG7VMdMKox/30V4gUlN+gUNrGLoc0iPE3Scd5EYjbbbMMKQEFMKQ4 B1Lg== X-Gm-Message-State: AOUpUlEJTClGqI2BKK2ZUUxI05TCW1pn9YEEbuEiAyoPMdKLz6t3UTCZ DVGwoLivYcNr2lcjnlebQSWSUU7g/HE= X-Google-Smtp-Source: AAOMgpfS7uWJ2m2fnCd3q5O44WlAj38sQsrNquS+SSvsE+4QOZ9ZAOZxHfW/J5fqtyqnrkchc4RsdA== X-Received: by 2002:a62:cac5:: with SMTP id y66-v6mr1437334pfk.187.1533250319247; Thu, 02 Aug 2018 15:51:59 -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 5-v6sm4465319pgc.86.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 1/9] crypto: xcbc: Remove VLA usage Date: Thu, 2 Aug 2018 15:51:44 -0700 Message-Id: <20180802225152.19194-2-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-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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crypto/xcbc.c b/crypto/xcbc.c index 25c75af50d3f..c055f57fab11 100644 --- a/crypto/xcbc.c +++ b/crypto/xcbc.c @@ -57,15 +57,17 @@ 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) { unsigned long alignmask = crypto_shash_alignmask(parent); struct xcbc_tfm_ctx *ctx = crypto_shash_ctx(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]; + int bs = sizeof(key1); if ((err = crypto_cipher_setkey(ctx->child, inkey, keylen))) return err; @@ -212,7 +214,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;