Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp81936imm; Tue, 7 Aug 2018 14:21:25 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx+n8M8qP6K3YJLouMjJSpx6NkrQCyD7Bv7OrHzcP4j87ysJ4lctlcKJKW9J3/skfDZuj4q X-Received: by 2002:a63:ba54:: with SMTP id l20-v6mr70741pgu.145.1533676885103; Tue, 07 Aug 2018 14:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533676885; cv=none; d=google.com; s=arc-20160816; b=tVRjw6JYntCPOAZBzurlsgZaa4OB8yBYYCex5c+dKqbSLYtmFf2kFjkIOS87CsWjO9 LyG+t+HjzuTDdTVmlRXPdrndqg5EBZ+QAh2t8moLs4kMaUTyg//toYIhGPK8jVp+YfxC 8YPaavvxlMUlTqMMBQyL/qFm3xuO2XTmXnfTtLefloTeauHsyTCSIyBgB0WdTn3VcV3l Aabqh/6CBCFAj2m9J6perBZyD6z92C6t/edkoRYp5+Pjm/M8Z+U2251N1Kl99p4R3yAZ kOZXo407VrKSOG6pOIex81WBtexKzF5OKXjqtlrlv+NWykqCzu93nzoHwfxX8eRU8chc sHcg== 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=xi1UiijgPtH3bEbgxLJTLT+H3zXPa7fDlbmxyBVC5QY=; b=pburix7VwC6BTBq7HSwaxy9WTv5L96GndQp3oKDH6DXTuHOKzaHTxYSUlwJ1sawHzJ UNx6UUhI6cPcEYxLQUzcd+cu88V5OTnG0DVzAeFskRtuVNJpfwtkjdiTPXIh9QQjuL1n hv03x/vWjiIxQ2zTf5FNS8QfiY3XuMTWh4mVllYZ5HFhoXQ2Mdk5zLd71FCJkGbLoqV1 dwzyx2+X4Hu+tTcbsnttOBKcH1sDAi+lAmHagcR1oKAbZ8Q3BUOZ7MYxPwtS6+uCh9LY zLtE8LzXXIiT060oMXA6ApJG2KJ8NYTbqV5KaYPpiIc/Lpt7zhatQ24yYIs0SlNzBLep d/PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MolSfpaK; 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 w19-v6si2111725pfn.160.2018.08.07.14.21.10; Tue, 07 Aug 2018 14:21:25 -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=MolSfpaK; 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 S1727386AbeHGXf0 (ORCPT + 99 others); Tue, 7 Aug 2018 19:35:26 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33690 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727243AbeHGXfN (ORCPT ); Tue, 7 Aug 2018 19:35:13 -0400 Received: by mail-pg1-f194.google.com with SMTP id r5-v6so49090pgv.0 for ; Tue, 07 Aug 2018 14:18:55 -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=xi1UiijgPtH3bEbgxLJTLT+H3zXPa7fDlbmxyBVC5QY=; b=MolSfpaKz70ZU2b1072Jk1SbatLRIM91vChMXrA2xIqNwfxBezcEU2kqo4c2Wno5rh 6QwpE0T2sBrl+rxI8Nxqt0spLN6nEyODTgD28prp0sGMxIV2Mb49rWrW9A0Iz20U3/tm I6ZgxWs75yLRyZGwq2XZx2PttDL0r6w0zlggU= 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=xi1UiijgPtH3bEbgxLJTLT+H3zXPa7fDlbmxyBVC5QY=; b=nMGQDEORavTGnLh+hqm4X0hC6atIxyxzpAaDBh4QhCq5Gp7Ds2Hlmh9BXEhOZSzQYS wTanr6SIHuuYP5ST7WzcwUH3D4ySx+1CMNPy+HtrZpqIjy+OHqBZCnXS9QqXCpgZsJom xVunkaAMZnVgjdCH/bHJpDRdxXmsym9xfh/6iKnf6x2ZFAmVjXFyTN+VGxagTIUj2RRi ldnsf9B3leQ0TnDZgcHC6U7PI6VCkH/TH7YKEqIZVwvdxNKj1QlTN3n5XgWVgdpM6H74 bFd0sCeOjddISYIu9Pq5FQdxNmNLsveogjhj0+wiMrNGJbcB8YgLlwI4XXIOREkR7mww WLgw== X-Gm-Message-State: AOUpUlFdjOAeGcKrWgdUS8Z7Zvb2P8ae+XEQiTvJu/5mZMhp/RC7Hi2D b1bgjz/x3Ub9iQCDOpsFMsX9Iw== X-Received: by 2002:a62:8559:: with SMTP id u86-v6mr105034pfd.32.1533676735035; Tue, 07 Aug 2018 14:18:55 -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 b68-v6sm422503pfd.74.2018.08.07.14.18.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Aug 2018 14:18:51 -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 9/9] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Date: Tue, 7 Aug 2018 14:18:43 -0700 Message-Id: <20180807211843.47586-10-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 caps the skcipher request size similar to other limits and adds a sanity check at registration. Looking at instrumented tcrypt output, the largest is for lrw: crypt: testing lrw(aes) crypto_skcipher_set_reqsize: 8 crypto_skcipher_set_reqsize: 88 crypto_skcipher_set_reqsize: 472 [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Signed-off-by: Kees Cook --- include/crypto/internal/skcipher.h | 1 + include/crypto/skcipher.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h index e42f7063f245..5035482cbe68 100644 --- a/include/crypto/internal/skcipher.h +++ b/include/crypto/internal/skcipher.h @@ -130,6 +130,7 @@ static inline struct crypto_skcipher *crypto_spawn_skcipher( static inline void crypto_skcipher_set_reqsize( struct crypto_skcipher *skcipher, unsigned int reqsize) { + BUG_ON(reqsize > SKCIPHER_MAX_REQSIZE); skcipher->reqsize = reqsize; } diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h index 2f327f090c3e..c48e194438cf 100644 --- a/include/crypto/skcipher.h +++ b/include/crypto/skcipher.h @@ -139,9 +139,11 @@ struct skcipher_alg { struct crypto_alg base; }; +#define SKCIPHER_MAX_REQSIZE 472 + #define SKCIPHER_REQUEST_ON_STACK(name, tfm) \ char __##name##_desc[sizeof(struct skcipher_request) + \ - crypto_skcipher_reqsize(tfm)] CRYPTO_MINALIGN_ATTR; \ + SKCIPHER_MAX_REQSIZE] CRYPTO_MINALIGN_ATTR; \ struct skcipher_request *name = (void *)__##name##_desc /** -- 2.17.1