Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: caam - add error check to caam_rsa_set_priv_key_form

The caam_rsa_set_priv_key_form did not check for memory allocation errors.
Add the checks to the caam_rsa_set_priv_key_form functions.

Fixes: 52e26d77b8b3 ("crypto: caam - add support for RSA key form 2")
Signed-off-by: Chen Ridong <chenridong@huawei.com>
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Chen Ridong and committed by
Herbert Xu
b64140c7 35b2237f

+7 -4
+7 -4
drivers/crypto/caam/caampkc.c
··· 984 984 return -ENOMEM; 985 985 } 986 986 987 - static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx, 987 + static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx, 988 988 struct rsa_key *raw_key) 989 989 { 990 990 struct caam_rsa_key *rsa_key = &ctx->key; ··· 994 994 995 995 rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz); 996 996 if (!rsa_key->p) 997 - return; 997 + return -ENOMEM; 998 998 rsa_key->p_sz = p_sz; 999 999 1000 1000 rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz); ··· 1029 1029 1030 1030 rsa_key->priv_form = FORM3; 1031 1031 1032 - return; 1032 + return 0; 1033 1033 1034 1034 free_dq: 1035 1035 kfree_sensitive(rsa_key->dq); ··· 1043 1043 kfree_sensitive(rsa_key->q); 1044 1044 free_p: 1045 1045 kfree_sensitive(rsa_key->p); 1046 + return -ENOMEM; 1046 1047 } 1047 1048 1048 1049 static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key, ··· 1089 1088 rsa_key->e_sz = raw_key.e_sz; 1090 1089 rsa_key->n_sz = raw_key.n_sz; 1091 1090 1092 - caam_rsa_set_priv_key_form(ctx, &raw_key); 1091 + ret = caam_rsa_set_priv_key_form(ctx, &raw_key); 1092 + if (ret) 1093 + goto err; 1093 1094 1094 1095 return 0; 1095 1096