From patchwork Mon Jun 25 21:10:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10487327 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 037AA6038C for ; Mon, 25 Jun 2018 21:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA00B2869B for ; Mon, 25 Jun 2018 21:12:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE6A8286B3; Mon, 25 Jun 2018 21:12:30 +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 94E262869B for ; Mon, 25 Jun 2018 21:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752709AbeFYVKn (ORCPT ); Mon, 25 Jun 2018 17:10:43 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:39121 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752320AbeFYVKl (ORCPT ); Mon, 25 Jun 2018 17:10:41 -0400 Received: by mail-pf0-f194.google.com with SMTP id s21-v6so1913420pfm.6 for ; Mon, 25 Jun 2018 14:10:40 -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=7ME0G7lTirc+Q70W7JaZqb0CVXH7ajkdRGsBwyVxDuE=; b=In77wWpHfGgekfSot/fIO5Wv+8sozibFJpzjLHdh1tendjC/asJNa0+pV91T9fF9At HIdAwY4KC5kGgiBJKyX0Qcaou6AeobvmgpMBBxLilJa4CxCs2+HNA2+lmBs2n5j9ZUnR J+WKEaXWlAkhKpwSM3Mn9BxxOcx7FcShqPbl4= 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=7ME0G7lTirc+Q70W7JaZqb0CVXH7ajkdRGsBwyVxDuE=; b=O3By0ocCx/e4mpFyS5A7e1YdkceuU68wVtiDDGuOIrXLsW2IgD+2FDmpkToYKPWXLH Bfxi50Y0UdbLmcxIEo6yVJPp/8o8kxe85AWtYgg6cv8nz7qgXamuZU+3OixE65qDoXot dVIdwhDqstMRRxPto5p5c71OjS9Hxc9y7gW5UufUiwxZG/yXaF7OHLMpFojs7zSvrMWe 9gvplHNv0UuSfBkEdEBdiwZhqxr32dWIA1brGi06bEoG310fj695snODmQYpcXlO8WO1 cOSLWTQ87Q2K/x61v/epUUcdAYcDvBjEFgChsZH6Hf2+n3HnbG4we3LKCJsg/s2ZbtAW 9o4g== X-Gm-Message-State: APt69E0n4STStUQzrF99Zn8m/bC3wu5MZfJlAtpxCay2asQesi7TeIQg rGGF5J89ApA/oSPIyBoBO/arVw== X-Google-Smtp-Source: ADUXVKI/B3BZHOTsr0Xa7C4H8Z+6U6Wvv90RUPYXq8geA/bgV2J5ihEmPP4s0LNq0y76d2C8WmpoMA== X-Received: by 2002:aa7:8058:: with SMTP id y24-v6mr14553361pfm.148.1529961040629; Mon, 25 Jun 2018 14:10:40 -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 o13-v6sm10069589pgn.93.2018.06.25.14.10.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 14:10:35 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , "David S. Miller" , linux-crypto@vger.kernel.org, "Gustavo A. R. Silva" , Arnd Bergmann , Eric Biggers , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/11] crypto: xcbc: Remove VLA usage Date: Mon, 25 Jun 2018 14:10:16 -0700 Message-Id: <20180625211026.15819-2-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180625211026.15819-1-keescook@chromium.org> References: <20180625211026.15819-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 Cc: Herbert Xu Cc: "David S. Miller" Cc: linux-crypto@vger.kernel.org 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;