Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp420560imm; Thu, 28 Jun 2018 23:33:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeF1FFxJzhLHblXYmTyIB/9+oNM4L5A1B74z0xwtIcKtR+halfJSjtzd2kN8e6mDvE9NXrt X-Received: by 2002:a62:190d:: with SMTP id 13-v6mr986991pfz.103.1530254010595; Thu, 28 Jun 2018 23:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530254010; cv=none; d=google.com; s=arc-20160816; b=BzNZJtl3fg0gHoCMdbgF8a3KbS7l5nVWpnwERivA994Bu3BYHjpKyA+Ux5JTcxsfqw W7cuLtNjd79iB9X++ATyBBG17BDX7ci3hijZmF2MZ8FOYCWDkKlEZPD9M3QBaM+KtqZk g/gHMVgNwqN2wHOPJrPJF5Q9r+1hsS9V5JRC16OyZI8NFjYURulv/6Dy58VZHc20Zryv TW9D/dLS3wzaQYs2lVMHV8B/FsabWVuNQRSwtJ8tf8MUz7uSKMw57P6YvAOR2HZTXUbI 525z54k84mxEWs9Ris9U1tuLfxCDG7D7pA2jyqHmvIggMLPRBZvA0wrP0aesB1DBFY42 wz8Q== 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=MIo1Nz6xsAzhrUOgz3ZsT3FQwlEkJYwkNKsz5fusJ5PFx+ddb4GnwgNQw+bqXW/mQR poAMBfnTqx8E9k2MEdIk/oHvBP+LoE2I3zBdRA+5pqBi9tx7n0wUh0CxGVd/35xVxAJi 8q0vS5BmzysuHs6KIK/P35WxkcFGFm2daSWYDxzSH7zFsZVEdckgIh+vAXSAbg/NTo/C 5PBssfzSBPxi7x7J1LWGgRt933z2W0swTJu0PI2AEPcXxJh+fDpuDoeKyCVt/Ixjkuq9 ySfEoHzYIa+VOE3StREZfEbzcVCXVhXLoRt7TYAeiZQRJwtua2hI+tZQ4j8+KxpFCsI4 KMFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S35jWs85; 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 n3-v6si4530784pld.146.2018.06.28.23.33.16; Thu, 28 Jun 2018 23:33:30 -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=S35jWs85; 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 S1030312AbeF2A3d (ORCPT + 99 others); Thu, 28 Jun 2018 20:29:33 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:37568 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936300AbeF2A25 (ORCPT ); Thu, 28 Jun 2018 20:28:57 -0400 Received: by mail-pl0-f68.google.com with SMTP id 31-v6so3562568plc.4 for ; Thu, 28 Jun 2018 17:28:56 -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=S35jWs85ys3BWA/Bzji6sOJbRwrE2ZB2/rmhd6T+dKutXl+khA/4ynT9Vg13nddteO Zg53ACOgdQS73jc3VMC1QbDRtsUtFShBurMEZNdZERAxkqEpl9eUwbTXbGtjnl0QZ1B9 912OSbBm+ggMq2Ga4/hg5gSe92yKKJsr1nh7M= 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=gOReQFVD0yg0Lez/K4r19BIvkT0TImauwEPo4phXlKuhYJx+HlL1flDVetrBD4KlLV sNLCqcHl7NLhos6mYlu2hB6KdyX1b7CvBAPFjwDTM+jk/1xCkKPkx4eZksdWv33uWk4A SADlj4Op49CyISScyLYrYypY+1BJc1ALKUW23sdgByGOIVgBTfAS/ScvC0OjwBufbewr uU/lnLgF6imtukQk18xUJejkLX1MO4hA6em1HnTnEhOS7R0ZxweSp4FvyVSxwY0T7gGS wCNI44DP2KbUQd2SDmgLpds/Wu/YkxkrIOf/oPWZLGpmBJuoNG+726CvsltiG/zHF4cn xHcA== X-Gm-Message-State: APt69E3F7udXYu2a5SRnqFSKTdfOEwWRJpgOao7Exf87PbepHNSIU0bM Y+QbB50Z1t3pfU9HDPuzFfqMiQ== X-Received: by 2002:a17:902:b683:: with SMTP id c3-v6mr12524863pls.158.1530232136608; Thu, 28 Jun 2018 17:28:56 -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 5-v6sm10969030pfd.11.2018.06.28.17.28.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jun 2018 17:28:53 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , "Gustavo A. R. Silva" , Arnd Bergmann , Eric Biggers , Alasdair Kergon , 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 v3 7/9] crypto alg: Introduce generic max blocksize and alignmask Date: Thu, 28 Jun 2018 17:28:41 -0700 Message-Id: <20180629002843.31095-8-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629002843.31095-1-keescook@chromium.org> References: <20180629002843.31095-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