From patchwork Tue Aug 7 21:18:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10559191 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5464D14E2 for ; Tue, 7 Aug 2018 21:18:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 455B12A5F1 for ; Tue, 7 Aug 2018 21:18:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38B5F2A5F9; Tue, 7 Aug 2018 21:18:56 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D57C42A5F1 for ; Tue, 7 Aug 2018 21:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727048AbeHGXfM (ORCPT ); Tue, 7 Aug 2018 19:35:12 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36380 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727169AbeHGXfL (ORCPT ); Tue, 7 Aug 2018 19:35:11 -0400 Received: by mail-pg1-f193.google.com with SMTP id h12-v6so42840pgs.3 for ; Tue, 07 Aug 2018 14:18:53 -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=nArgZqlYDDgAq8YX/jvWimxGlDBI68qUF1jtzrItHrtzN3msuSa2epxNtb01j1mOa/ ca39AMvJj1q9mhidQmpE/bdZxNACdzIxjOLkMyuwCfO8eV7kfrw85ZO3lfZXU/Z1ZpWP crX2EF+lPcXz/pZMXPOg/uW4XV4QfIoCAN1Rg= 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=eDHS4IyIke/MYU74QWqpK7jDAxKdNN6JSkuN9O+lLPMv1BpQIzOV+N4Nhvy8c5R27Q 5O1gi8QTwPk0FMM1YRYH8CLtYgwbcalxRNhGkNQ3y6gZ10hfxn7c9HjNDAhTlhMKfXfl sMR6NufvOVuZqy+VqJFvXAPQ/X+QW410wN/qlWlTBdJnz+gGFthtKX60iVyuly49EY6Z hYBMml+mikskY2RyquwvEtZeIwpeTZOClKOPddlTFHHewjxJ135P16S3QWdvbiIiiXO3 a5wH+85Qun6h2HhJRoGcLixxfIWbUhvQlLXIBMbSWeff1i27zH3ixEnoefY1sBLNQ3OX kvqw== X-Gm-Message-State: AOUpUlHlQQtNTwEiCsK/NavYFMrKhmJbIOjEOrycyCUJ5gYN5Urc//Lh H+9EBQXwj9Vt17qV1gMlJwTeJg== X-Google-Smtp-Source: AA+uWPxCZWHFGrG9CATf1gLBhHbwJ5GzpSEYlL5Eskb5hpUBJH8fTI6RS9rnBo5vAeWQvw/CzTVYWA== X-Received: by 2002:a63:7a0a:: with SMTP id v10-v6mr71065pgc.444.1533676733215; Tue, 07 Aug 2018 14:18:53 -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 b64-v6sm3357099pfg.66.2018.08.07.14.18.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 14:18:50 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Eric Biggers , Ard Biesheuvel , Giovanni Cabiddu , Alasdair Kergon , Mike Snitzer , Tudor-Dan Ambarus , Andrew Morton , Thomas Gleixner , Geert Uytterhoeven , Arnd Bergmann , Will Deacon , Rasmus Villemoes , David Woodhouse , Matthew Wilcox , "David S. Miller" , "Gustavo A. R. Silva" , linux-crypto@vger.kernel.org, dm-devel@redhat.com, qat-linux@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v8 6/9] crypto alg: Introduce generic max blocksize and alignmask Date: Tue, 7 Aug 2018 14:18:40 -0700 Message-Id: <20180807211843.47586-7-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180807211843.47586-1-keescook@chromium.org> References: <20180807211843.47586-1-keescook@chromium.org> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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