public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Stein <alexander.stein@systec-electronic.com>
To: Kees Cook <keescook@chromium.org>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>,
	Arnaud Ebalard <arno@natisbad.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Boris Brezillon <boris.brezillon@bootlin.com>,
	Antoine Tenart <antoine.tenart@bootlin.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	linux-kernel@vger.kernel.org,
	Gilad Ben-Yossef <gilad@benyossef.com>,
	Chen-Yu Tsai <wens@csie.org>, Eric Biggers <ebiggers@google.com>,
	linux-crypto@vger.kernel.org,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Philippe Ombredanne <pombredanne@nexb.com>,
	Corentin Labbe <clabbe.montjoie@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	Christian Lamparter <chunkeey@gmail.com>
Subject: Re: [PATCH 2/2] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK
Date: Wed, 05 Sep 2018 08:05:29 +0200	[thread overview]
Message-ID: <2109885.PdqaXYh4EC@ws-140106> (raw)
In-Reply-To: <20180904181629.20712-3-keescook@chromium.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 <keescook@chromium.org>
> ---
>  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

  reply	other threads:[~2018-09-05  6:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-04 18:16 [PATCH 0/2] crypto: Remove VLA usage from skcipher Kees Cook
2018-09-04 18:16 ` [PATCH 1/2] crypto: skcipher: Allow crypto_skcipher_set_reqsize() to fail Kees Cook
2018-09-04 18:16 ` [PATCH 2/2] crypto: skcipher: Remove VLA usage for SKCIPHER_REQUEST_ON_STACK Kees Cook
2018-09-05  6:05   ` Alexander Stein [this message]
2018-09-05  9:18   ` Ard Biesheuvel
2018-09-05 21:05     ` Kees Cook
2018-09-05 22:49       ` Ard Biesheuvel
2018-09-06  0:43         ` Kees Cook
2018-09-06 20:22           ` Kees Cook
2018-09-06 22:23             ` Kees Cook
2018-09-06  4:53         ` Gilad Ben-Yossef
2018-09-06  7:21           ` Ard Biesheuvel
2018-09-06  8:11             ` Ard Biesheuvel
2018-09-06  8:51               ` Herbert Xu
2018-09-06  9:29                 ` Ard Biesheuvel
2018-09-06 13:11                   ` Herbert Xu
2018-09-06 14:49                     ` Ard Biesheuvel
2018-09-06 19:18                       ` Kees Cook
2018-09-06  8:25             ` Gilad Ben-Yossef

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2109885.PdqaXYh4EC@ws-140106 \
    --to=alexander.stein@systec-electronic.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=antoine.tenart@bootlin.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arno@natisbad.org \
    --cc=boris.brezillon@bootlin.com \
    --cc=chunkeey@gmail.com \
    --cc=clabbe.montjoie@gmail.com \
    --cc=ebiggers@google.com \
    --cc=gilad@benyossef.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.ripard@bootlin.com \
    --cc=pombredanne@nexb.com \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox