Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp81712imm; Tue, 7 Aug 2018 14:21:06 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyljqS+R4r8RDwkbo6x1qABmxhx/y7tPdF9UsJxwH3YwleND7dH2oOcWWhAwZbBhVhJRd98 X-Received: by 2002:a63:4c56:: with SMTP id m22-v6mr61627pgl.299.1533676866078; Tue, 07 Aug 2018 14:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533676866; cv=none; d=google.com; s=arc-20160816; b=IOO8JbvbmOUgISvhsZ2O9tcCl9fUJyQSZynsee8QlgFDH4bdZ+1cFfCPw+/mpPZKos 2DBi9tBrvRcFjbu9XJ2rU9pLQF2O6C4ocP4x4gCmp0Qg4GG6Da3NqfOsICqI+eyspsQD 1y0XkXlNS5cGbyV3cBzly7nvjNHMVpZgeOGSNWwZlXjc9/d0gDN6fYPmXjjalXCZBaXS M2mY0/qgphpKY0zncBAb0ufB8SL0LBOYHEFgvPZUiaUV389YBu2EdJodk7g/rOqwGv5h Ha14IKpW5G8iS0qPlMruuf/aMP81EB56QAF7ekz0EmghcmZlw1Muazhw6U7bTjt8Anc9 uZQA== 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=FM9iXdXlkS52TsyFP2gg7rNNx/jcS2tRpExv/ehOgY6+7HaSeE5QY91zWpTOelEyLq 2mmOFuAhIkVGmSJk3FlHOW7iRohcnJHJOgqNeukH2v6ZhhSVn4vcvRUGlBCVFsPz6z6D zqiyai0HE1gz/J+xj4dB9reHAKSufzycSBdQoYJXD0/pzI9/zeFlaOg+eCXK65moi6H3 UUG7TXn0Om8xg+4B05Us401BvLloslPSxhZT4SuBEe+hJ6JDcB24WbYSvMQaquVE0yCl yzZsTfJ0n1S7icZMOsSJEbpsrd1qKJhhsnlByf5WmJ2WIJmuRPMIsfKrDtrs6Ty1wvvH 85Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nArgZqlY; 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=REJECT sp=REJECT 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 f16-v6si2416599pff.13.2018.08.07.14.20.51; Tue, 07 Aug 2018 14:21:06 -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=nArgZqlY; 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=REJECT sp=REJECT dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727434AbeHGXff (ORCPT + 99 others); Tue, 7 Aug 2018 19:35:35 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46931 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726990AbeHGXfL (ORCPT ); Tue, 7 Aug 2018 19:35:11 -0400 Received: by mail-pg1-f195.google.com with SMTP id f14-v6so19352pgv.13 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=f1QU7t8dRsl79llv7yKfgAcFFMliGIHCDgF1bGYz8kNIROxSa9ZwvWK1GZ+l2Ep2Dg KkE9iAOZqCZgSU2ttGej4CNQHDZ2PyvEXSHHofDUkU1mxGP9o599PCS1gJfvXcTkHVgN Z7jxIiIkxqGm0b9FSzVp19+ewdG3eQZnZ6cik/mIwWUy/zXfvPtA/URg12RknI6/nrLw gTq8BvYyGQHXJ90P3DuCUzioCzgaZt55Z4ajVQWvpw8ufg4Guz6KNWoxozWozyTysMpe Ph13V8iHiQKyJneugfmKpELDBq88ZcVwLaArvs4alBtf49t3eQ/jffEZL57x4XaGJOjx b0IQ== X-Gm-Message-State: AOUpUlEn5/v4/jwiOO7pZnPB/F6aRbdWNqSuyTsdLTfkJB7cGb/tNDlv Gu65Wo1L1gBk8+np/W9Mh4DAKQ== 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-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