Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4349184imm; Mon, 25 Jun 2018 14:13:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLTeUpPzJVtwvnF/FrY8aczLNZDfAywgaNeYH2JrcUDmkLP+HvSYEmTKWCRlwRWBZPUq6Mo X-Received: by 2002:a17:902:8f8e:: with SMTP id z14-v6mr5655451plo.139.1529961220751; Mon, 25 Jun 2018 14:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529961220; cv=none; d=google.com; s=arc-20160816; b=DP4AmT0kKxV3LY1soi8RafEg3/3ex6zirfLr6CDWlXPreZr04TRQFDaQ9ut/JvpxfX bTI5PiHG1VzFKVV+BgGUhTpMh+kjgjJDHynA7/CguMj02W7olYK+YXNq6HObjG69xFOh Jnpy09qXMXOqEaV2Yj7kTqwsyAEyK+kZ/HusT0mwo2tODlmJYTQerwEQ+dqKKVe7EzlW 59AoTWe16+L9jfod7uE8uqr20Xx+KgDuN75eJpPLVnMTCVtqU9zBk6KV91e3gBGoFKDJ RQt2HDfU1xLkClSjhLT/CAjp30hx1YX6YYyaJT0cQpkqj5RDeFu2qxiwTi525c4tlDua s0JA== 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=F0FZrEaIUPJgf66KLv7byNxsLpp5pIqlXlh9kSGp1lg=; b=LqPSjbm3cPqV4lRbjScgmHjKbonbb9p4d5GvMb1C2PcmT15LUaem4uqGUfgp7IPWwj 7dPeLHBfg+DOq073wa91KxmuqcEmQAFpfSqgg9lESMEF2+tglXH+wtYu8ZuVMPv0lKWR v0d2v74ZXy3OpzEHU0T4U/qnWqtaZxtHjtOZcRyJMxPKwp5X1X0qcTNhQj3MMrWxRvN4 TRqT96qTM69QSIxvESHx4MrCCCJbiHB9xJfiUOlFlBDy/+5FbWiw6eG38bS8KG9LTztV 0XzIPV9zKKoaBDiUWgrC2Oe+rkmopY4ui0LQr5nKWTMYPUKVpuixpaZO4m1GRTpWic9e JWZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Tky8X8wC; 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 l26-v6si3112078pgu.191.2018.06.25.14.13.26; Mon, 25 Jun 2018 14:13:40 -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=Tky8X8wC; 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 S1755756AbeFYVMN (ORCPT + 99 others); Mon, 25 Jun 2018 17:12:13 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40088 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752751AbeFYVKo (ORCPT ); Mon, 25 Jun 2018 17:10:44 -0400 Received: by mail-pf0-f194.google.com with SMTP id z24-v6so7019752pfe.7 for ; Mon, 25 Jun 2018 14:10:44 -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=F0FZrEaIUPJgf66KLv7byNxsLpp5pIqlXlh9kSGp1lg=; b=Tky8X8wCcqIIvZI3VRjDkHogeBZh/+26tohzF92fzKwQPlnoNKV+M4UgrGN0qRJqgV tnGX7fwfuVggFyTnwa+pjqwyTO6m081x05sGN4Q5+wpevkw31Qxw7WL4c4AX/Q41QWlR Z0tvdXNqolBNevUU+l84+AXvYjwrWYO3jCcJc= 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=F0FZrEaIUPJgf66KLv7byNxsLpp5pIqlXlh9kSGp1lg=; b=ghdGlB2X8N4L3v3o4TeuaSYxOFsrF4IrqWhfKPfdtS75+pPzFFcxiYmdS1pFANoX5a W7TTf1wCPiOqBgquOivcL4KrKgdaqoqwq3sED4aeWc9BphbMgILfpuH/ePG8j5vIBgAw BU1GZY+nZ8u6DNHZ/fxHyCRoVDeEPoQ5UFLZK2N11dP07Ta4yLClhJanc6lEsamcLeRu rv3hZbzG9A/AGWf1LpuS5P9IZOWEQwbFMsgkKKi+VKzXMTuyZV617tU6SJFWcJt5XmQZ FSpSvUxOxt2eNWOT+72HcKYGeDsig58aEOMTjzO3YcXh6Ij8Wy2PMPJE5BPtCZ60Ha31 RjnA== X-Gm-Message-State: APt69E3NT8sMHrr+YzCUYzZn948k4YpFVWvhb6p5TRAm1SrH4HZ4TtIW rJWV01mv8QZyn73KdmntvEiswg== X-Received: by 2002:a65:550d:: with SMTP id f13-v6mr11682196pgr.180.1529961043711; Mon, 25 Jun 2018 14:10:43 -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 k71-v6sm7497870pga.62.2018.06.25.14.10.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 14:10:41 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , "David S. Miller" , linux-crypto@vger.kernel.org, "Gustavo A. R. Silva" , Arnd Bergmann , Eric Biggers , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/11] crypto alg: Introduce generic max blocksize and alignmask Date: Mon, 25 Jun 2018 14:10:22 -0700 Message-Id: <20180625211026.15819-8-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180625211026.15819-1-keescook@chromium.org> References: <20180625211026.15819-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 Cc: Herbert Xu Cc: "David S. Miller" Cc: linux-crypto@vger.kernel.org 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