From patchwork Wed Jun 20 19:04:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10478525 X-Patchwork-Delegate: snitzer@redhat.com 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 3470660532 for ; Wed, 20 Jun 2018 19:05:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25F8428DDE for ; Wed, 20 Jun 2018 19:05:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19A7528DDF; Wed, 20 Jun 2018 19:05:05 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AF66D28DDF for ; Wed, 20 Jun 2018 19:05:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D9C230832EA; Wed, 20 Jun 2018 19:05:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 48D35100164E; Wed, 20 Jun 2018 19:05:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 938FF18037EF; Wed, 20 Jun 2018 19:05:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5KJ4TgM023573 for ; Wed, 20 Jun 2018 15:04:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA8F160A9C; Wed, 20 Jun 2018 19:04:29 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E1DFC6092F for ; Wed, 20 Jun 2018 19:04:29 +0000 (UTC) Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B709380F79 for ; Wed, 20 Jun 2018 19:04:28 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id b74-v6so257143pfl.5 for ; Wed, 20 Jun 2018 12:04:28 -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=9exG+auSNsqHVYr1/J0wLzVKyblg1tz++twhS5zFlMY=; b=cteLpY5P6Vom4UEI118zL6xuBlpK4xQ/p8mPXEm69sCeDnK7jyqdhz9SRjDbIqytDR iZHrWzE8vepf4HhrU2PkeZOjjqcvsoqwC9Mu3LjLwOemu8d1xUe0ETQKmOsgbU8YDGZn 7h0Il9lItuxyos4hgtgUXY2+CelY2Ojo7riqw= 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=9exG+auSNsqHVYr1/J0wLzVKyblg1tz++twhS5zFlMY=; b=rDcooOTTs9/vmes68TpkqszhwoFME9mjJxcsk/Ti3kWU5I5Q//WhHXJUe/AusKEzB/ M26TwoF3n6BDqycaZ4DVDugp9y6A7Y0Z9BgEM8IwLd4f0FN8dqLRLNHSp5+KCKyCO3rU PXAJuSRQfi8oDSW97hj7UQ5wPC8nBGYWID6TNKwMhXaNniYeKT0DFmt0QUkhJxk9Cb5T Lm6PIo6csOFPNnlNNhJm752vO4LeR4fZdMQuirtKu9D7RSxlKazYaxLE+wXR7CZsOYZ3 S0wrUtQ//garaBGfW2DDRSS2eJLpAyp591JKSx11MxF6YWlMJhs2DdGe5J4PDlcVc9Pf DtYA== X-Gm-Message-State: APt69E1/zcaom0z+J4HJ3eaOqmUTS1kr5zhRhgNXfXvuDK/IhCSrocGa zLUxnJ3zKo+DvRRWarObCnVqXw== X-Google-Smtp-Source: ADUXVKIgpx5iaMkj4H38Nhaqnb3VfWQddbY0K5vIEO0Ztos6tQOH3Sz10NDWi1YRMKT0Ay5JAEAxMA== X-Received: by 2002:a62:c0cb:: with SMTP id g72-v6mr23975814pfk.226.1529521468250; Wed, 20 Jun 2018 12:04:28 -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 z18-v6sm4093303pgc.0.2018.06.20.12.04.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 12:04:22 -0700 (PDT) From: Kees Cook To: Herbert Xu Date: Wed, 20 Jun 2018 12:04:05 -0700 Message-Id: <20180620190408.45104-9-keescook@chromium.org> In-Reply-To: <20180620190408.45104-1-keescook@chromium.org> References: <20180620190408.45104-1-keescook@chromium.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 20 Jun 2018 19:04:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 20 Jun 2018 19:04:28 +0000 (UTC) for IP:'209.85.192.196' DOMAIN:'mail-pf0-f196.google.com' HELO:'mail-pf0-f196.google.com' FROM:'keescook@chromium.org' RCPT:'' X-RedHat-Spam-Score: -0.112 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.192.196 mail-pf0-f196.google.com 209.85.192.196 mail-pf0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: dm-devel@redhat.com Cc: Giovanni Cabiddu , Kees Cook , Arnd Bergmann , Eric Biggers , Mike Snitzer , "Gustavo A. R. Silva" , qat-linux@intel.com, linux-kernel@vger.kernel.org, dm-devel@redhat.com, linux-crypto@vger.kernel.org, Lars Persson , Tim Chen , "David S. Miller" , Alasdair Kergon , Rabin Vincent Subject: [dm-devel] [PATCH 08/11] crypto: qat: Remove VLA usage X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 20 Jun 2018 19:05:04 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In the quest to remove all stack VLA usage from the kernel[1], this uses the upper bound for the stack buffer. Also adds a sanity check. This additionally raises the stack size limit during the build, to avoid a compiler warning while keeping it reasonably close to expected stack size. The warning was just exposing the existing max stack size, so there is nothing new here; now that it is not hidden in a VLA, the compiler can see how large it might get. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- drivers/crypto/qat/qat_common/Makefile | 2 ++ drivers/crypto/qat/qat_common/qat_algs.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/qat/qat_common/Makefile b/drivers/crypto/qat/qat_common/Makefile index 47a8e3d8b81a..c2a042023dde 100644 --- a/drivers/crypto/qat/qat_common/Makefile +++ b/drivers/crypto/qat/qat_common/Makefile @@ -19,3 +19,5 @@ intel_qat-objs := adf_cfg.o \ intel_qat-$(CONFIG_DEBUG_FS) += adf_transport_debug.o intel_qat-$(CONFIG_PCI_IOV) += adf_sriov.o adf_pf2vf_msg.o \ adf_vf2pf_msg.o adf_vf_isr.o + +CFLAGS_qat_algs.o := $(call cc-option,-Wframe-larger-than=2300) diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c index 1138e41d6805..257269126601 100644 --- a/drivers/crypto/qat/qat_common/qat_algs.c +++ b/drivers/crypto/qat/qat_common/qat_algs.c @@ -153,8 +153,8 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, struct sha512_state sha512; int block_size = crypto_shash_blocksize(ctx->hash_tfm); int digest_size = crypto_shash_digestsize(ctx->hash_tfm); - char ipad[block_size]; - char opad[block_size]; + char ipad[CRYPTO_ALG_MAX_BLOCKSIZE]; + char opad[CRYPTO_ALG_MAX_BLOCKSIZE]; __be32 *hash_state_out; __be64 *hash512_state_out; int i, offset; @@ -164,6 +164,10 @@ static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash, shash->tfm = ctx->hash_tfm; shash->flags = 0x0; + if (WARN_ON(block_size > sizeof(ipad) || + sizeof(ipad) != sizeof(opad))) + return -EINVAL; + if (auth_keylen > block_size) { int ret = crypto_shash_digest(shash, auth_key, auth_keylen, ipad);