From: Dan Carpenter Date: Mon, 30 Oct 2023 09:02:59 +0000 (+0300) Subject: crypto: rsa - add a check for allocation failure X-Git-Tag: v6.6.14~541 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2831f4d3bfa68e64c5f83e96688be779c87b3511;p=platform%2Fkernel%2Flinux-starfive.git crypto: rsa - add a check for allocation failure [ Upstream commit d872ca165cb67112f2841ef9c37d51ef7e63d1e4 ] Static checkers insist that the mpi_alloc() allocation can fail so add a check to prevent a NULL dereference. Small allocations like this can't actually fail in current kernels, but adding a check is very simple and makes the static checkers happy. Fixes: 6637e11e4ad2 ("crypto: rsa - allow only odd e and restrict value in FIPS mode") Signed-off-by: Dan Carpenter Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- diff --git a/crypto/rsa.c b/crypto/rsa.c index c79613c..b9cd11f 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c @@ -220,6 +220,8 @@ static int rsa_check_exponent_fips(MPI e) } e_max = mpi_alloc(0); + if (!e_max) + return -ENOMEM; mpi_set_bit(e_max, 256); if (mpi_cmp(e, e_max) >= 0) {