crypto: drbg - fix error return code in drbg_alloc_state()
authorWei Yongjun <weiyongjun1@huawei.com>
Thu, 30 Apr 2020 08:13:53 +0000 (08:13 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 8 May 2020 05:30:41 +0000 (15:30 +1000)
Fix to return negative error code -ENOMEM from the kzalloc error handling
case instead of 0, as done elsewhere in this function.

Reported-by: Xiumei Mu <xmu@redhat.com>
Fixes: db07cd26ac6a ("crypto: drbg - add FIPS 140-2 CTRNG for noise source")
Cc: <stable@vger.kernel.org>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Reviewed-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/drbg.c

index e57901d..37526eb 100644 (file)
@@ -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;
        }