Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1131864imm; Wed, 20 Jun 2018 12:08:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIj7BorNh/c+xDMNlpKXlOWLaS6Op/8VrYkdihwj8b5NrvSzGOOnG9PyGf39xrRijPo9xjz X-Received: by 2002:a63:9902:: with SMTP id d2-v6mr20201465pge.166.1529521709425; Wed, 20 Jun 2018 12:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529521709; cv=none; d=google.com; s=arc-20160816; b=Qg9nUho3RWTHjgP7S06mjnoPyEUUHpEVHnQzKgDUjmPQ550At2M+2kPv/9hQyx2f9y aLvoJjs6vMyPlR3o/M8oEvcAOiDLt6Ysf/3iS5ZoBDH1slCaxkgPJhjI2rf7RLglE7iU ZK2GYuDnIaTG+LjCo6poZUyiGRV2lB0jpJOKo2DIQBXWIioVfmvt91a1VYEZyEnyACbM KVYn/ypViACCIXK8wCOAzihZCfuuxt1INzs7bE0v3QggxSqP3yzBXK/b1x5BR8ROD+HC ztmfsiahsqcTpQoIBqTGtxl1rDZThTZw2JN7X8HpsT3F4v5mzWbq4DaCWi7Tv2YiTrOA jX4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=9exG+auSNsqHVYr1/J0wLzVKyblg1tz++twhS5zFlMY=; b=uehfYpk+BvNIlJOJlNtQBC6duEc5aDy3I/FM6EbJTj9GUdB6RH+BfsE2RYkzCR3CsA Y0n11Ezz7/9AxCq0T9HJ7jSl1nhOZ765jJtrSLkjTd75zTanLqmoMoNtEN+k9RgYT35r G2ZgOZSPfzDiksj/a9xE68E54senJxoOmKICd82fnI0Idag/bZy9Wlb/snP6azMms3Ze api9Aiewqi28PF8jcKR1/rJeG2OyGgAbDforAFXeWpLShxZNvnI1xgbq5hKzylP3exGo P0oF1KKGe6FQ1Y/utjHX1BKT35UsHEZPqfsavFzkKP0+KDoFwBgCbVe8/Yl7sLR3cjzK e8FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cteLpY5P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r63-v6si2822935plb.366.2018.06.20.12.08.15; Wed, 20 Jun 2018 12:08:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cteLpY5P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754891AbeFTTGS (ORCPT + 99 others); Wed, 20 Jun 2018 15:06:18 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:37167 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754759AbeFTTE2 (ORCPT ); Wed, 20 Jun 2018 15:04:28 -0400 Received: by mail-pf0-f193.google.com with SMTP id y5-v6so256946pfn.4 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=gVif9wmTNLzZU571fvCh6TGZxL09oa8FhpulLA2w522m6suaiKiKxgTumfQv0Rh3TD WM8j+rgsfwHMH3qgPZPR9oFYCTnSwboGSDFNhhipmC2WFFDher4nzCXXnB/+P9H1VP2V zjbIuigl4/BR8z0gYk+N8rRq245HSsHdLZmQYmNDb7U8GiwThhclMRvInwQd4cQGhuJg BIFcQJCzo5VKReBGSItEi8uoi72WhMDAyTE3sPC6wlm3FrBLu5BMKpovK3aifE6zYP2b opOte2W0cGCa5ReMZdq4QdbaS9q1N6+LrUD7cE4MLui0DGxEuYoRhNz90NB3qruvNbGU UVOQ== X-Gm-Message-State: APt69E2zezojtVupyCpqQZOFvfK0l3gbbh+lZSFL38UjCdSUibh+IS+A THeVj8NGsrJX0cAroHpcdDOZIg== 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 Cc: Kees Cook , "Gustavo A. R. Silva" , Alasdair Kergon , Arnd Bergmann , Eric Biggers , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , "David S. Miller" , linux-crypto@vger.kernel.org, qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH 08/11] crypto: qat: Remove VLA usage Date: Wed, 20 Jun 2018 12:04:05 -0700 Message-Id: <20180620190408.45104-9-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180620190408.45104-1-keescook@chromium.org> References: <20180620190408.45104-1-keescook@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.17.1