From patchwork Wed Jun 20 19:04:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10478517 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 9B3F6601D7 for ; Wed, 20 Jun 2018 19:04:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CB8328DDE for ; Wed, 20 Jun 2018 19:04:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8094A28DE2; Wed, 20 Jun 2018 19:04:59 +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 24B8C28DDE for ; Wed, 20 Jun 2018 19:04:59 +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 590863082123; Wed, 20 Jun 2018 19:04:58 +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 307E3100164E; Wed, 20 Jun 2018 19:04:58 +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 9CFCC180053C; Wed, 20 Jun 2018 19:04:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5KJ4SJh023543 for ; Wed, 20 Jun 2018 15:04:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1748430012A6; Wed, 20 Jun 2018 19:04:28 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DAAE308332D for ; Wed, 20 Jun 2018 19:04:28 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) (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 EC10330B933A for ; Wed, 20 Jun 2018 19:04:26 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id a14-v6so233227pgw.10 for ; Wed, 20 Jun 2018 12:04:26 -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=yG5aybviBuPPbm4hUFlJLeIulnNClRZRG7IFfSv4RdI=; b=GtmvCXS4gzLVHgI//WNGTExd5/nQ7vznhaSM3pYNYe9JInLKuGTFDDpEBdLtCZueRn UJjBTspH/LM3ZJ8GoI8xOkPZW6fP23jVg8z6F/Mz1zEmrsBpPC7VV2xlLzPc49ceVSRe 9qi6hrtMVUeWCf768ZKZZ9mJ4g0gqxFmsVuxE= 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=yG5aybviBuPPbm4hUFlJLeIulnNClRZRG7IFfSv4RdI=; b=dVz5Q7656AAvIufjd1p0ytRJXzOJYfw95oYtwsD/a0/MolpAabUw3eMDQGVzj3RJLv VijOaiRr2V4X8m9iNOjqQav42aRUiXytYLX6RtBvqSHTi5+n9A/xV4Ncz58TgWJBzcb/ 1ZXypq6Az7Z0i+Twg7vL/qFEpRTxlDS7l8UpyqPJI5tQUMFQ2G5dNPOWHFqsT4koX2KT eq7C3bHJ31YrAfsT6eRYgcTUVsrwWPgT5iyQq1vkKDfZ0lUaAOdEZQNbcqL12xHS8Fra gwbCJxZqOqRuc9yEKFogL+JGwaVMcENuNDf2XJufhuHnR9ZYqU4NLUgA8EiH9KTwo3GS 1yqQ== X-Gm-Message-State: APt69E2d+rpn+iAD+pcqS5YetxAldM8FbREEe6XzhYO8dwR+a00S68a2 VjTJs/0rhRFI3bHBTFdFuJ88ow== X-Google-Smtp-Source: ADUXVKKMKQrFM8RIP5Tlf7ywdNgogzeibWCqjg/PpiVmt7ySl36l7NBdU9vTus48v7Ud5tJkAwTH8A== X-Received: by 2002:a62:484d:: with SMTP id v74-v6mr24339476pfa.256.1529521465371; Wed, 20 Jun 2018 12:04:25 -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 o87-v6sm6689374pfa.106.2018.06.20.12.04.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Jun 2018 12:04:21 -0700 (PDT) From: Kees Cook To: Herbert Xu Date: Wed, 20 Jun 2018 12:04:02 -0700 Message-Id: <20180620190408.45104-6-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.49]); Wed, 20 Jun 2018 19:04:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 20 Jun 2018 19:04:27 +0000 (UTC) for IP:'74.125.83.67' DOMAIN:'mail-pg0-f67.google.com' HELO:'mail-pg0-f67.google.com' FROM:'keescook@chromium.org' RCPT:'' X-RedHat-Spam-Score: -0.131 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.83.67 mail-pg0-f67.google.com 74.125.83.67 mail-pg0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 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 05/11] crypto alg: Introduce max blocksize and alignmask 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.42]); Wed, 20 Jun 2018 19:04:58 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP In the quest to remove all stack VLA usage from the kernel[1], this exposes the existing upper bound on crypto block sizes for VLA removal, and introduces a new check for alignmask (current maximum in the kernel is 63 from manual inspection of all cra_alignmask settings). [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- crypto/algapi.c | 5 ++++- include/linux/crypto.h | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crypto/algapi.c b/crypto/algapi.c index c0755cf4f53f..760a412b059c 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -57,7 +57,10 @@ static int crypto_check_alg(struct crypto_alg *alg) if (alg->cra_alignmask & (alg->cra_alignmask + 1)) return -EINVAL; - if (alg->cra_blocksize > PAGE_SIZE / 8) + if (alg->cra_blocksize > CRYPTO_ALG_MAX_BLOCKSIZE) + return -EINVAL; + + if (alg->cra_alignmask > CRYPTO_ALG_MAX_ALIGNMASK) return -EINVAL; if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 6eb06101089f..e76ffcbd5aa6 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h @@ -134,6 +134,10 @@ */ #define CRYPTO_MAX_ALG_NAME 128 +/* Maximum values for registered algorithms. */ +#define CRYPTO_ALG_MAX_BLOCKSIZE (PAGE_SIZE / 8) +#define CRYPTO_ALG_MAX_ALIGNMASK 63 + /* * The macro CRYPTO_MINALIGN_ATTR (along with the void * type in the actual * declaration) is used to ensure that the crypto_tfm context structure is