Skip to contentSkip to conversation

crypto: drbg - fix error return code in drbg_alloc_state()

PATCH In review Wei Yongjun 3 participants 3 messages Apr 30, 2020 – May 8, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: drbg - fix error return code in drbg_alloc_state()

Fix to return negative error code -ENOMEM from the kzalloc error handling case instead of 0, as done elsewhere in this function.

Fixes db07cd26ac6a ("crypto: drbg - add FIPS 140-2 CTRNG for noise source")
---
 crypto/drbg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/drbg.c +3 -1
index e57901d8545b..37526eb8c5d5 100644
@@ -1306,8 +1306,10 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)
 	if (IS_ENABLED(CONFIG_CRYPTO_FIPS)) {
 		drbg->prev = kzalloc(drbg_sec_strength(drbg->core->flags),
 				     GFP_KERNEL);
-		if (!drbg->prev)
+		if (!drbg->prev) {
+			ret = -ENOMEM;
 			goto fini;
+		}
 		drbg->fips_primed = false;
 	}
 
Reviewed-by on v1 1/1
#1 lore raw

Am Donnerstag, 30. April 2020, 10:13:53 CEST schrieb Wei Yongjun:

Hi Wei,

Quoted 14 lines

Fix to return negative error code -ENOMEM from the kzalloc error handling case instead of 0, as done elsewhere in this function.

Fixes db07cd26ac6a ("crypto: drbg - add FIPS 140-2 CTRNG for noise source")
---
 crypto/drbg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/drbg.c +0 -0
index e57901d8545b..37526eb8c5d5 100644

crypto/drbg.c static inline int drbg_alloc_state(struct drbg_state · line 1314

Quoted 10 lines
crypto/drbg.c +3 -1
@@ -1306,8 +1306,10 @@ static inline int drbg_alloc_state(struct drbg_state
 *drbg) if (IS_ENABLED(CONFIG_CRYPTO_FIPS)) {
 		drbg->prev = kzalloc(drbg_sec_strength(drbg->core->flags),
 				     GFP_KERNEL);
-		if (!drbg->prev)
+		if (!drbg->prev) {
+			ret = -ENOMEM;
 			goto fini;
+		}
 		drbg->fips_primed = false;
 	}

Thank you

Ciao
Stephan

maintainer
#2 lore raw
In reply to Wei Yongjun
Quoted 8 lines · Wei Yongjun

Fix to return negative error code -ENOMEM from the kzalloc error handling case instead of 0, as done elsewhere in this function.

Fixes db07cd26ac6a ("crypto: drbg - add FIPS 140-2 CTRNG for noise source")
---
 crypto/drbg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt