Skip to contentSkip to conversation

crypto: drbg: check the return value of crypto_shash_init()

PATCH In review Jia-Ju Bai 2 participants 2 messages Feb 25, 2022 Crypto API

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 crypto: drbg: check the return value of crypto_shash_init()

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")
---
 crypto/drbg.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
crypto/drbg.c +4 -1
index 177983b6ae38..51feb9538701 100644
@@ -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);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 18 lines · 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")
---
 crypto/drbg.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
crypto/drbg.c +0 -0
index 177983b6ae38..51feb9538701 100644
@@ -1725,8 +1725,11 @@ static int drbg_kcapi_hash(struct drbg_state *drbg, unsigned char *outval,
 {
 	struct sdesc *sdesc = (struct sdesc *)drbg->priv_data;

crypto/drbg.c static int drbg_kcapi_hash(struct drbg_state *drbg, unsigned char *outval, · line 1735

Quoted 10 lines
crypto/drbg.c +4 -1
 	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