Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: herbert@gondor.apana.org.au, davem@davemloft.net,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: drbg: check the return value of crypto_shash_init()
Date: Fri, 25 Feb 2022 12:19:24 -0800	[thread overview]
Message-ID: <Yhk5zA/APtZoJhpT@sol.localdomain> (raw)
In-Reply-To: <20220225074623.17276-1-baijiaju1990@gmail.com>

On Thu, Feb 24, 2022 at 11:46:23PM -0800, Jia-Ju Bai wrote:
> Then function crypto_shash_init() in drbg_kcapi_hash() can fail, but
> there is no check of its return value. To fix this bug, its return value
> should be checked with new error handling code.
> 
> Fixes: 541af946fe13 ("crypto: drbg - SP800-90A Deterministic Random Bit Generator")
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  crypto/drbg.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/crypto/drbg.c b/crypto/drbg.c
> index 177983b6ae38..51feb9538701 100644
> --- a/crypto/drbg.c
> +++ b/crypto/drbg.c
> @@ -1725,8 +1725,11 @@ static int drbg_kcapi_hash(struct drbg_state *drbg, unsigned char *outval,
>  {
>  	struct sdesc *sdesc = (struct sdesc *)drbg->priv_data;
>  	struct drbg_string *input = NULL;
> +	int ret = 0;
>  
> -	crypto_shash_init(&sdesc->shash);
> +	ret = crypto_shash_init(&sdesc->shash);
> +	if (ret)
> +		return ret;
>  	list_for_each_entry(input, in, list)
>  		crypto_shash_update(&sdesc->shash, input->buf, input->len);
>  	return crypto_shash_final(&sdesc->shash, outval);

What about the call to crypto_shash_update() right below it?

- Eric

      reply	other threads:[~2022-02-25 20:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-25  7:46 [PATCH] crypto: drbg: check the return value of crypto_shash_init() Jia-Ju Bai
2022-02-25 20:19 ` 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=Yhk5zA/APtZoJhpT@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=baijiaju1990@gmail.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