linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: drbg: check the return value of crypto_shash_init()
@ 2022-02-25  7:46 Jia-Ju Bai
  2022-02-25 20:19 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2022-02-25  7:46 UTC (permalink / raw)
  To: herbert, davem; +Cc: linux-crypto, linux-kernel, Jia-Ju Bai

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);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] crypto: drbg: check the return value of crypto_shash_init()
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2022-02-25 20:19 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: herbert, davem, linux-crypto, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-25 20:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).