public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Corentin Labbe <clabbe@baylibre.com>
Cc: dan.carpenter@oracle.com, davem@davemloft.net,
	herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: crypto_user_stat: Zeroize whole structure given to user space
Date: Sat, 3 Nov 2018 15:07:55 -0700	[thread overview]
Message-ID: <20181103220553.GA808@sol.localdomain> (raw)
In-Reply-To: <1539952045-18784-1-git-send-email-clabbe@baylibre.com>

On Fri, Oct 19, 2018 at 12:27:25PM +0000, Corentin Labbe wrote:
> For preventing un-initilized data to be given to user-space (and so leak
> potential useful data), the crypto_stat structure must be correctly
> initialised.
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Fixes: cac5818c25d0 ("crypto: user - Implement a generic crypto statistics")
> Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
> ---
>  crypto/crypto_user_stat.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/crypto/crypto_user_stat.c b/crypto/crypto_user_stat.c
> index 021ad06bbb62..9990c599f648 100644
> --- a/crypto/crypto_user_stat.c
> +++ b/crypto/crypto_user_stat.c
> @@ -37,6 +37,7 @@ static int crypto_report_aead(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&raead, 0, sizeof(struct crypto_stat));
>  	strncpy(raead.type, "aead", sizeof(raead.type));
>  
>  	v32 = atomic_read(&alg->encrypt_cnt);
> @@ -65,6 +66,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&rcipher, 0, sizeof(struct crypto_stat));
>  	strlcpy(rcipher.type, "cipher", sizeof(rcipher.type));
>  
>  	v32 = atomic_read(&alg->encrypt_cnt);
> @@ -93,6 +95,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&rcomp, 0, sizeof(struct crypto_stat));
>  	strlcpy(rcomp.type, "compression", sizeof(rcomp.type));
>  	v32 = atomic_read(&alg->compress_cnt);
>  	rcomp.stat_compress_cnt = v32;
> @@ -120,6 +123,7 @@ static int crypto_report_acomp(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&racomp, 0, sizeof(struct crypto_stat));
>  	strlcpy(racomp.type, "acomp", sizeof(racomp.type));
>  	v32 = atomic_read(&alg->compress_cnt);
>  	racomp.stat_compress_cnt = v32;
> @@ -147,6 +151,7 @@ static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&rakcipher, 0, sizeof(struct crypto_stat));
>  	strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
>  	v32 = atomic_read(&alg->encrypt_cnt);
>  	rakcipher.stat_encrypt_cnt = v32;
> @@ -177,6 +182,7 @@ static int crypto_report_kpp(struct sk_buff *skb, struct crypto_alg *alg)
>  	struct crypto_stat rkpp;
>  	u32 v;
>  
> +	memset(&rkpp, 0, sizeof(struct crypto_stat));
>  	strlcpy(rkpp.type, "kpp", sizeof(rkpp.type));
>  
>  	v = atomic_read(&alg->setsecret_cnt);
> @@ -203,6 +209,7 @@ static int crypto_report_ahash(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&rhash, 0, sizeof(struct crypto_stat));
>  	strncpy(rhash.type, "ahash", sizeof(rhash.type));
>  
>  	v32 = atomic_read(&alg->hash_cnt);
> @@ -227,6 +234,7 @@ static int crypto_report_shash(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&rhash, 0, sizeof(struct crypto_stat));
>  	strncpy(rhash.type, "shash", sizeof(rhash.type));
>  
>  	v32 = atomic_read(&alg->hash_cnt);
> @@ -251,6 +259,7 @@ static int crypto_report_rng(struct sk_buff *skb, struct crypto_alg *alg)
>  	u64 v64;
>  	u32 v32;
>  
> +	memset(&rrng, 0, sizeof(struct crypto_stat));
>  	strncpy(rrng.type, "rng", sizeof(rrng.type));
>  
>  	v32 = atomic_read(&alg->generate_cnt);
> -- 
> 2.18.1
> 

There are two more info leaks in the file that this doesn't fix.  I sent out a
fixed version here:

	https://patchwork.kernel.org/patch/10666775/

... as part of the series "crypto: crypto_user reporting fixes and cleanups".

- Eric

      reply	other threads:[~2018-11-03 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-19 12:27 [PATCH] crypto: crypto_user_stat: Zeroize whole structure given to user space Corentin Labbe
2018-11-03 22:07 ` Eric Biggers [this message]

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=20181103220553.GA808@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=clabbe@baylibre.com \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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