Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7192697imm; Tue, 24 Jul 2018 09:54:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdp7PevkjduSjg8gAfEi1CSdPAyr5gRtdUflVL9kIxSBk9L9snVpnQV0YKb5LZvbN2D1uKS X-Received: by 2002:aa7:8645:: with SMTP id a5-v6mr18312626pfo.247.1532451258640; Tue, 24 Jul 2018 09:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532451258; cv=none; d=google.com; s=arc-20160816; b=VrBYbNOz3ygpu5rZdssa1h39g3bQyMPKWtufzTVQDAHURCRBd/bcpsGAuO71XSxRd3 T+keGjpCqp11ARLngjXmDqlwsa3l45seQ94ekaacT2aGGQDwSs1ejn2O6EB7cuBQqyrq 0Jjv5PkyfcAxN0ioPCjyhHHSJcwiJZdzZjiswbfAza4B3muaVqfcYr9CbJ5tkC+pzYUt AOP/Vuo242avyeAFFf1b9H/9h1I5OMPKlbS62BxhbUAgpZFTTsvFEyBUKZyJCO65vK1E 9J3vp5UaIX2jJ7Men0TIWKBqJIkw13R/c2kJs9y5EStUTPbip67B/IDWjzhcYlbkOUuN 7HsQ== 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=Kf7dHXgLwN6RFwqcJMAMZl/UE1iNvtjOZ0QOZwFF6uvGrWQIzr+LjxPC/aYZ6wP9Q7 ZAc73WNkwPaZcebgJa11JP11I8W8H0hxaE8Blee2Rzxsz40chbhBmVGd7LWUBYXs5wRN 0dI5BG62HTFaeazUW6qkilhdXMB5dYgZrRnVBlAzOXkt8BbTPrK3LHhKOvzfyUjW5wvD ohLVMfLaTKsDyicnhjwy+18umtHoUG3iY2KvAaJWuvQOqJU89ZHqgXHyRxU6O5lplZlp h+xdEyyvtEqQsg3y7yeUvly3fwJnbXPugIbZO5E84EXsJbaU1QSPnNdlaKl7DqAeEF8p ua5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dyArO5HP; 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 z15-v6si12147835pgs.570.2018.07.24.09.54.04; Tue, 24 Jul 2018 09:54:18 -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=dyArO5HP; 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 S2388611AbeGXR5M (ORCPT + 99 others); Tue, 24 Jul 2018 13:57:12 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:38120 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388582AbeGXR5M (ORCPT ); Tue, 24 Jul 2018 13:57:12 -0400 Received: by mail-pl0-f66.google.com with SMTP id b1-v6so2023441pls.5 for ; Tue, 24 Jul 2018 09:49:51 -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=dyArO5HPDOmgxu1KqX1PLyjELlLB/4D/84YPYAORv5WvH1EukArfqKSZklwmUMMB7a /TGpsRkqAMjiQVw/mB48Ccn1vguQr0t20yF9CE+lGYxame7S7lxWefDK14kQapdlhLEk 203wUEPeCBMmH4vWUkmIeSP0Tbz3jZdvFjhbE= 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=irBYB9tDfLYFktEvA+ih7tSCQ51g/NileaNqtP+Bbj+wxBOiqEZmprF0Lk/8RDGC6T 4zC7J5yVXNUG5+4kDpxvVQkIgKRzm24J8Gi8y1Hj6Y+kT5FON8mrQlnQoz9gYrX6vqVZ i4Kt/RjC54ijnbRmz3ybVDZ++FQjGXrVVspKdWgnMPYZHkIbRi+D9Urz0KfF2IeWohPp ytMNuuLcsZm5OJ4kbjFp94erSGHsy0QmohUFQlv6hP1VC9JQE6kcKyp2oYaCtec0aa7d 9X/RH68AaTWaws5RyGiitGm5puQvIpGQjhC532HoRm8K0IA7NygeOJlvJsyxevjVKOph oOrw== X-Gm-Message-State: AOUpUlGdk0jXBeaHfwIx1cEi3x/iI4IJr7sxgcy1fA/eV0PJh5a4fFjo CI9g98ZNsXxyqiBb/n4PAPx8ww== X-Received: by 2002:a17:902:b112:: with SMTP id q18-v6mr17394185plr.284.1532450990853; Tue, 24 Jul 2018 09:49:50 -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 e2-v6sm13671874pgo.92.2018.07.24.09.49.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 09:49:47 -0700 (PDT) From: Kees Cook To: Herbert Xu Cc: Kees Cook , Arnd Bergmann , Eric Biggers , "Gustavo A. R. Silva" , Alasdair Kergon , Rabin Vincent , Tim Chen , "Rafael J. Wysocki" , Pavel Machek , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Philipp Reisner , Lars Ellenberg , Jens Axboe , Giovanni Cabiddu , Mike Snitzer , Paul Mackerras , Greg Kroah-Hartman , David Howells , Johannes Berg , Tudor-Dan Ambarus , Jia-Ju Bai , Andrew Morton , Geert Uytterhoeven , Josh Poimboeuf , David Woodhouse , Will Deacon , dm-devel@redhat.com, linux-pm@vger.kernel.org, linux-crypto@vger.kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, qat-linux@intel.com, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 08/18] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Date: Tue, 24 Jul 2018 09:49:26 -0700 Message-Id: <20180724164936.37477-9-keescook@chromium.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724164936.37477-1-keescook@chromium.org> References: <20180724164936.37477-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