Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3078477imm; Mon, 16 Jul 2018 21:24:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeuL1tjgfUSPsPd+vexAJCn5hwIBOyF1BHjOwCob9f/JEOQQg9sXS9K6yu9BB5eOvsaZE5M X-Received: by 2002:a17:902:28e4:: with SMTP id f91-v6mr34808plb.146.1531801457822; Mon, 16 Jul 2018 21:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531801457; cv=none; d=google.com; s=arc-20160816; b=cwdabqlewlkn1sZitqsTFE/EJgoPbV/QKa2vC2Ap7EseE4aSuqKPzuKiMJzN6CIHqV Nf+ZF/McxBb/9KzKXasgeEMh790hQ7hvkHPDUr4p5mwHj9oIZP2gmYIGMjiiFRQxv+8C DbQLnRxaJxY5P38XYhohme+K7tWuX0xFCobmzyME0RDuONUzI5LD5hVNKgTocx8SCyG8 AlyArrKzHwdFvMZO3FCDjA0Vt2EQEOthR9ab34OAszuI0e9Zekr5Y4s14jescwcPJDt4 4jrYXAsYi5ZZzfTP0OYV2NuM3KYwSUd5s2BNeBfh0rfwslX9jAbBwk8WmhtV8zG3NhPH L3Tg== 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=VpRN1iVcyfvpdLCnHxX+qb6aNSO7KKjQOjR+1Yg0fIQecpbjU9e83WbYriS9adMzuG sU8c2KOrtp6g1xJ7pHhwe9cO6gkYZeH8zllUnuj1Fka7INPwV/wy5M5XvUKCTYjCwZAm ADFhw4cSjpx0XBggnki4GvQ28C3UApJEjqYfZyuW6VbbpxELC1O6OijOToPZqFO+haFW WhAGNI2HofdvuYWC6TgOr9FCUUCrxXKjQ/X8fexf02KmYl0XwDt58FgAzrcgReCA+dVT lrRBMrQjuv2VecZ1qrpeKPDT/67tUs0NTvCnNyACgLNkND7l6tCwVnbSGnkYzbCaCRAP vtXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WYogaV9z; 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 s9-v6si31847510pfm.85.2018.07.16.21.24.03; Mon, 16 Jul 2018 21:24:17 -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=WYogaV9z; 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 S1728304AbeGQExA (ORCPT + 99 others); Tue, 17 Jul 2018 00:53:00 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:41187 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727064AbeGQEwg (ORCPT ); Tue, 17 Jul 2018 00:52:36 -0400 Received: by mail-pl0-f68.google.com with SMTP id w8-v6so16252127ply.8 for ; Mon, 16 Jul 2018 21:22:01 -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=WYogaV9zX4EwpeGgNzSh0v+fVsrHv1YXEUagL8KbE9Xjw5VDv4pQ0kIn3keeIAB7/W oHi0VG6Vaz/zFeAAQUoxT8FFlJCrUcN7WATzemySzvSLNEllP73Err3jKdzOrCT3erJd hgZUvzjRsR2R5yI/s7E9w0LOQBjYzLOQW934A= 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=G/2Cf6aMZQqR/17SJuDqHREAqb9VSxJX162X2x1KAMZtBL7Lo0k2rypo2B0kXzR8cY Bmx52oIjy4Ph+5nTvDPwUVdqwTpxYc+gBdAo6alD63FH4b8dGLLtD/VSIqZS2xUEggo5 mM7W/YgmOOplQMqO2rY3wLM7GSQCgRPunFLqsd0SUo4gFF0AHfTxNTvLuRAoxSKUaJQH YuJXcGYaCncyJQXLjjfNjziM1XDyhDnXA0VmjpO9HcuO1FqOLMZXtXe+KqB2C6SSDQXQ pJiUT7rY1QAihsfXWSmJtKolRgU3Hug3K6QtgcOnkC8Mt/3VIQTOJxKUzPJO4tWc5A/0 KS5Q== X-Gm-Message-State: AOUpUlEyArrd6eN29qSFnFmwerQtbgWC9A0stBaY+8vdJl2FkcY0963x +9oVzxlhbWr7uG4JzayXSGPgjA== X-Received: by 2002:a17:902:583:: with SMTP id f3-v6mr4764plf.115.1531801321124; Mon, 16 Jul 2018 21:22:01 -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 s27-v6sm42465095pfk.133.2018.07.16.21.21.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Jul 2018 21:21:58 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Arnd Bergmann , Eric Biggers , "Gustavo A. R. Silva" , Alasdair Kergon , Giovanni Cabiddu , Lars Persson , Mike Snitzer , Rabin Vincent , Tim Chen , linux-crypto@vger.kernel.org, qat-linux@intel.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH v5 07/11] crypto alg: Introduce generic max blocksize and alignmask Date: Mon, 16 Jul 2018 21:21:46 -0700 Message-Id: <20180717042150.37761-8-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180717042150.37761-1-keescook@chromium.org> References: <20180717042150.37761-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