Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7192436imm; Tue, 24 Jul 2018 09:54:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpclp91HaroEm6vF1PgYLb7E4yZQg94JBoFcyABD3Gy1toM8Xjylh6K3Jif6nwAFFvOHu2fL X-Received: by 2002:a63:24c:: with SMTP id 73-v6mr17505734pgc.252.1532451240003; Tue, 24 Jul 2018 09:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451239; cv=none; d=google.com; s=arc-20160816; b=C4OmFBdlTdS3PzQBKKxVPxEE6IbAbMWm4Og2NLbAHrWtm2yQ2qufJnaw1oIfxmdy5u lb5LoWoWbtn8d9EaNSLDihK2qgGyBeRZrxozGN3eyYAxHlZ7HOyimSMvwkDlldMy6Jqg XBD/hThBTL4fmqZsJdkVoiWih4kptlvcf/PrSVfHSHTQcIcQ4fhwUgjx4Y4PaRkO5AtX FKtzcwEqTDMvTKFUgM9ROSPDOVkBVISHvCzCv9uibP/r3iIvS4EfEFDY8Rbt8LXN2Wz7 sK+A1kMZ7+6J0wc8CWBxiWcBqZ5u9we6FpzzxMCilTP3a4i08537MvbqSDlBLMGHFpzb LK+g== 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=om28ZBbqlVOdWVGgbNqly+1dcj2BlW29w8AmBA0lHYw=; b=kZ3jtArJ113K7Lss0cyaTtBef5Okf+3Oa8cM1u9eXV3HSaKGF3Z854lfnHnajBOmma 9N9pEdkeCueTydfNodR6zH1JKL29JkKgm4Ml19ZEaNBWTk58FOi5mx9M2D2E8T4S8Zde fNbMu6f1Io8Kc0B762fX2uDK20VNbcctRldUiNb2vuJpmyW0sMFMYOnRHkWmuFt/92oW ZI5FgwcJHruGrj3rmxVU1EUi4UWfDiJRDzE47L45nrKB4IgCFa1pHbRm572A7uU2iIaN +vDASeRTI3NhuH75mr4pBLEaWkwJKiRnmarIIZ011Hr3exAqRm7OweoM19l08uh+hO3A 2/sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="jX0T/1t+"; 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 w9-v6si10348705plp.395.2018.07.24.09.53.45; Tue, 24 Jul 2018 09:53:59 -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="jX0T/1t+"; 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 S2388567AbeGXR5K (ORCPT + 99 others); Tue, 24 Jul 2018 13:57:10 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42636 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388541AbeGXR5K (ORCPT ); Tue, 24 Jul 2018 13:57:10 -0400 Received: by mail-pf1-f196.google.com with SMTP id l9-v6so982081pff.9 for ; Tue, 24 Jul 2018 09:49:49 -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=om28ZBbqlVOdWVGgbNqly+1dcj2BlW29w8AmBA0lHYw=; b=jX0T/1t+6ISxyA0Xu/P8wbMfZX4kQyW0Su7SqfXTq8k/RPM2fjPSGS0aCOhAlQST+W b4Vk7coIKTa9vBa1wvkAXRWt0UsEdIwSMy7PAf6LroT/KbEEyPbumKF92+ACRdPHGsJ3 2IdOeyVA5HEJgHD7cpjQMPRtLT3BSGgo+mUQE= 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=om28ZBbqlVOdWVGgbNqly+1dcj2BlW29w8AmBA0lHYw=; b=DnJ8BE5eSDGgbzOS+3sargwcqk2e8FxUZ1iO9bMWcZs5PKYY0HLqzgQBd1k2vrVHtk fdp6k8M97ixTDtve5tbtmdmRrGqZuaE2Es319RnpdYGAzQK5B7rlNVRWzrs2UCSjqX4C J2ReCvJJk7tNjkgq2GsmjqVkKikwzmo6KoXwNzAf8qIRrHvbWJ2R7+Ttf+8oJ/WqbyJk efoBT2GDwoD8e5ayNAwlnVmMsB9ZbBoUsLjGdwwxoYW/AIblMHdFUHL1xXLrUS5ZJoEN P9ZNAKZZ3J62nhHOKSNhPi6fgI+9HhnO2AGluPwJ6hE3Jt3cgdUc5nmVyjgz68GbQJdg h1dg== X-Gm-Message-State: AOUpUlEROMIPSlPteBl77qMcUd+4a0Ts9q0OCvOdjXlxf/oYSbt2oUfd wHNyfFHf2xuIxHA6+8jZPgOHvw== X-Received: by 2002:a63:220d:: with SMTP id i13-v6mr17411926pgi.212.1532450989120; Tue, 24 Jul 2018 09:49:49 -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 s195-v6sm25373097pgs.76.2018.07.24.09.49.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:49:47 -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 05/18] crypto alg: Introduce generic max blocksize and alignmask Date: Tue, 24 Jul 2018 09:49:23 -0700 Message-Id: <20180724164936.37477-6-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-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 exposes a new general upper bound on crypto blocksize and alignmask (higher than for the existing cipher limits) for VLA removal, and introduces new checks. At present, the highest cra_alignmask in the kernel is 63. The highest cra_blocksize is 144 (SHA3_224_BLOCK_SIZE, 18 8-byte words). For the new blocksize limit, I went with 160 (20 8-byte words). [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- crypto/algapi.c | 7 ++++++- include/crypto/algapi.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crypto/algapi.c b/crypto/algapi.c index c0755cf4f53f..496fc51bf215 100644 --- a/crypto/algapi.c +++ b/crypto/algapi.c @@ -57,9 +57,14 @@ 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) + /* General maximums for all algs. */ + if (alg->cra_alignmask > MAX_ALGAPI_ALIGNMASK) return -EINVAL; + if (alg->cra_blocksize > MAX_ALGAPI_BLOCKSIZE) + return -EINVAL; + + /* Lower maximums for specific alg types. */ if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) { if (alg->cra_alignmask > MAX_CIPHER_ALIGNMASK) diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index bd5e8ccf1687..21371ac8f355 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h @@ -20,8 +20,10 @@ /* * Maximum values for blocksize and alignmask, used to allocate * static buffers that are big enough for any combination of - * ciphers and architectures. + * algs and architectures. Ciphers have a lower maximum size. */ +#define MAX_ALGAPI_BLOCKSIZE 160 +#define MAX_ALGAPI_ALIGNMASK 63 #define MAX_CIPHER_BLOCKSIZE 16 #define MAX_CIPHER_ALIGNMASK 15 -- 2.17.1