From patchwork Tue Jul 24 16:49:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10542671 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 170EE112E for ; Tue, 24 Jul 2018 16:53:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E67CC290A7 for ; Tue, 24 Jul 2018 16:53:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA2E128FFE; Tue, 24 Jul 2018 16:53: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 91E4129151 for ; Tue, 24 Jul 2018 16:53:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388761AbeGXSA0 (ORCPT ); Tue, 24 Jul 2018 14:00:26 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:44243 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388409AbeGXR5F (ORCPT ); Tue, 24 Jul 2018 13:57:05 -0400 Received: by mail-pl0-f66.google.com with SMTP id m16-v6so2018888pls.11 for ; Tue, 24 Jul 2018 09:49:45 -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=KUe+LjlaQlS1O5ciNkx+mQgwWTRmPZ13UHy/USQfoyc0dAXMTwzk2Xx6qUc7AlF0O2 QiGXnGLkJwj+BaRXaUO015beIxRmiskoZ3V8mMejwoG8eJCaOM0zKqmuuA0SSSqaghC0 k1TppukdfSo15YKpxR2HelnJKmM6fpiatM8sk= 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=ThIA/T/jggACfwMGrqg1bEgdPahwZZ5fCr1Au4lQ/r/fZ65sUPVc/61VfJWlUzIT+9 IVgp1zuLMlbej+f1ku6zwI7sDSXAfM/hGuLAqrqKRQlPYwATi9w0uB6FoAcmGcwdms+w gYlKjggqvu62AI1Wbz6yjPr4qegC7uEG0MBUprit/MJ7GpdW1yvsWAQz0CocAqtkEzOn s0jVmvCE4dAOLGvHgGHAWzJ0GkUNlUfZ51OULHGd4ervpztB+ND94m50dY7RAHs8nmWz 7Xzsn/v8FHzRCCgVlh1YM/f/2+ZgLZxYtDNDy449KBoaY8Pr4F+DFA/bzXBw6JXKSLPL GWFg== X-Gm-Message-State: AOUpUlGr5ljatK581bvuPvlgTHer/oPHL1H3QlnU4ixxo8w8BYt75EWh yk0KbaD5kfuziHZvU8aTYOxprA== X-Google-Smtp-Source: AAOMgpc3bGW4E04kHUgFezSeoq8fvmHs03wRkMlKKtoD4yLsHExUpfOH9KDFmVzDOLA8REAbdGIg7g== X-Received: by 2002:a17:902:4203:: with SMTP id g3-v6mr17515330pld.315.1532450984795; Tue, 24 Jul 2018 09:49:44 -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 w13-v6sm2179184pgs.89.2018.07.24.09.49.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:49:42 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Arnd Bergmann , Eric Biggers , "Gustavo A. R. Silva" , Alasdair Kergon , Rabin Vincent , Tim Chen , "Rafael J. Wysocki" , Pavel Machek , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Philipp Reisner , Lars Ellenberg , Jens Axboe , Giovanni Cabiddu , Mike Snitzer , Paul Mackerras , Greg Kroah-Hartman , David Howells , Johannes Berg , Tudor-Dan Ambarus , Jia-Ju Bai , Andrew Morton , Geert Uytterhoeven , Josh Poimboeuf , David Woodhouse , Will Deacon , dm-devel@redhat.com, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, qat-linux@intel.com, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 01/18] crypto: xcbc: Remove VLA usage Date: Tue, 24 Jul 2018 09:49:19 -0700 Message-Id: <20180724164936.37477-2-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724164936.37477-1-keescook@chromium.org> References: <20180724164936.37477-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;