diff mbox series

crypto: drbg - Fix memleak in drbg_prepare_hrng

Message ID 20200611083356.88600-1-zhengbin13@huawei.com
State New
Headers show
Series crypto: drbg - Fix memleak in drbg_prepare_hrng | expand

Commit Message

Zheng Bin June 11, 2020, 8:33 a.m. UTC
drbg_prepare_hrng
  drbg->jent = crypto_alloc_rng
  err = add_random_ready_callback
  default:
    drbg->random_ready.func = NULL  -->set NULL, if fail

drbg_uninstantiate
  if (drbg->random_ready.func)      -->If NULL, will not free drbg->jent
    crypto_free_rng(drbg->jent)

Need to free drbg->jent if add_random_ready_callback return fail.

Fixes: 97f2650e5040 ("crypto: drbg - always seeded with SP800-90B compliant noise source")
Signed-off-by: Zheng Bin <zhengbin13@huawei.com>
---
 crypto/drbg.c | 2 ++
 1 file changed, 2 insertions(+)

--
2.26.0.106.g9fadedd
diff mbox series

Patch

diff --git a/crypto/drbg.c b/crypto/drbg.c
index 37526eb8c5d5..a643ab7eac7a 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -1524,6 +1524,8 @@  static int drbg_prepare_hrng(struct drbg_state *drbg)
 		/* fall through */

 	default:
+		crypto_free_rng(drbg->jent);
+		drbg->jent = NULL;
 		drbg->random_ready.func = NULL;
 		return err;
 	}