Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3424329imm; Tue, 4 Sep 2018 23:14:30 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZDKbj75/NipUTfbZLLeB943Wv4yWXFb/cB7lw2WNrKJZzOKpJyHYfqazg+K8tRBCjEA/PZ X-Received: by 2002:a62:ed5:: with SMTP id 82-v6mr38367704pfo.198.1536128070325; Tue, 04 Sep 2018 23:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536128070; cv=none; d=google.com; s=arc-20160816; b=orCaJlXHQLijcch1OuMdoxW0RMr3Bwo074LSPqduRrBHgNTMG1sxBBtNmvMdEfUQU2 zEWSVeWDfnaIGfyzNY85ITZJTggJJC7njBmpn59KQNM/c03OKAiZPp37X5k5yHK8Bqpe weQaZrcsFoJFYl8vA2QPfErA6Sh71Sed8x/Uz9AmpS4SeGwiEF5WyZk4bMK8euiNN5K6 Hu3Sw/74bKVEmN4jn8xEgsrocFhxLFJhvNdObZ6aH6QC91b4IYaeSVD43gsSQEiliiJX unA02p/szWJX+zjHHekzy1lOUPwKNItO+8Z3iZtq8NkCNl6MN6CvZTjzzDUKc23SPOVN tFJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qGwqC9iAvQY3FUzwdnDrWyx804tOix7USn96LrTPHxo=; b=BRATtLgQ4Pqq5vFvZjw5DCukR8mOucyZuO4ZMoatZw2BhcBpkrBpPQCbvODExGuGQy 1HzMk4lokxHbb7NACXM7W5ka7iMAN1wLqymRx2UjACyIjZ8GRj3svZ621C+zzjoAQ+s0 P0vMmy/leW+tEBpUN8fBJuJsoyNiMYq/lHiBTKtgRoycIzoJfVQUkLVViOFJ0NHS2sBb gXd92/uWJ04aXrZRmRpH61HbG4+Sm4NPBSLJ84iZmZACZ0BgrZpJ/ykphpbHAkVOHYi9 rSvF7FrP6XLwzl9N0DFCYxzyeqz+2cQ27/pmaexeC7kqyWHWvFOATnZ3zsWj/ULPup3B 9u1g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x68-v6si1031095pfc.239.2018.09.04.23.14.14; Tue, 04 Sep 2018 23:14:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727366AbeIEKlX (ORCPT + 99 others); Wed, 5 Sep 2018 06:41:23 -0400 Received: from webbox1416.server-home.net ([77.236.96.61]:39503 "EHLO webbox1416.server-home.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726272AbeIEKlX (ORCPT ); Wed, 5 Sep 2018 06:41:23 -0400 X-Greylist: delayed 439 seconds by postgrey-1.27 at vger.kernel.org; Wed, 05 Sep 2018 06:41:23 EDT Received: from imapserver.systec-electronic.com (unknown [212.185.67.146]) by webbox1416.server-home.net (Postfix) with ESMTPA id CF62927A6B3; Wed, 5 Sep 2018 08:05:31 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by imapserver.systec-electronic.com (Postfix) with ESMTP id 9F04A1A1B50; Wed, 5 Sep 2018 08:05:31 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at imapserver.systec-electronic.com Received: from imapserver.systec-electronic.com ([127.0.0.1]) by localhost (imapserver.systec-electronic.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fAX3J75soR6O; Wed, 5 Sep 2018 08:05:29 +0200 (CEST) Received: from ws-140106.localnet (ws-140106.systec.local [192.168.10.92]) by imapserver.systec-electronic.com (Postfix) with ESMTPA id 97DCB1A1B4F; Wed, 5 Sep 2018 08:05:29 +0200 (CEST) From: Alexander Stein To: Kees Cook Cc: Herbert Xu , Eric Biggers , Ard Biesheuvel , Gilad Ben-Yossef , Antoine Tenart , Boris Brezillon , Arnaud Ebalard , Corentin Labbe , Maxime Ripard , Chen-Yu Tsai , Christian Lamparter , Philippe Ombredanne , Jonathan Cameron , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 2/2] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Date: Wed, 05 Sep 2018 08:05:29 +0200 Message-ID: <2109885.PdqaXYh4EC@ws-140106> In-Reply-To: <20180904181629.20712-3-keescook@chromium.org> References: <20180904181629.20712-1-keescook@chromium.org> <20180904181629.20712-3-keescook@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday, September 4, 2018, 8:16:29 PM CEST Kees Cook wrote: > 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 | 3 +++ > include/crypto/skcipher.h | 4 +++- > 2 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h > index d2926ecae2ac..6da811c0747e 100644 > --- a/include/crypto/internal/skcipher.h > +++ b/include/crypto/internal/skcipher.h > @@ -130,6 +130,9 @@ static inline struct crypto_skcipher *crypto_spawn_skcipher( > static inline int crypto_skcipher_set_reqsize( > struct crypto_skcipher *skcipher, unsigned int reqsize) > { > + if (WARN_ON(reqsize > SKCIPHER_MAX_REQSIZE)) > + return -EINVAL; > + > skcipher->reqsize = reqsize; > > return 0; > 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 Now tfm could be removed from the macro arguments, no? Best regards, Alexander