]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
crypto: caam - add error check to caam_rsa_set_priv_key_form
authorChen Ridong <chenridong@huawei.com>
Mon, 4 Nov 2024 12:15:11 +0000 (12:15 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 15 Nov 2024 11:52:51 +0000 (19:52 +0800)
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>
drivers/crypto/caam/caampkc.c

index 887a5f2fb9279bcd0464a326cd74b4ce85967d47..cb001aa1de6618fcb257af730a1519a7d92f5dfd 100644 (file)
@@ -984,7 +984,7 @@ err:
        return -ENOMEM;
 }
 
-static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
+static int caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
                                       struct rsa_key *raw_key)
 {
        struct caam_rsa_key *rsa_key = &ctx->key;
@@ -994,7 +994,7 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
 
        rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz);
        if (!rsa_key->p)
-               return;
+               return -ENOMEM;
        rsa_key->p_sz = p_sz;
 
        rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz);
@@ -1029,7 +1029,7 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
 
        rsa_key->priv_form = FORM3;
 
-       return;
+       return 0;
 
 free_dq:
        kfree_sensitive(rsa_key->dq);
@@ -1043,6 +1043,7 @@ free_q:
        kfree_sensitive(rsa_key->q);
 free_p:
        kfree_sensitive(rsa_key->p);
+       return -ENOMEM;
 }
 
 static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
@@ -1088,7 +1089,9 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
        rsa_key->e_sz = raw_key.e_sz;
        rsa_key->n_sz = raw_key.n_sz;
 
-       caam_rsa_set_priv_key_form(ctx, &raw_key);
+       ret = caam_rsa_set_priv_key_form(ctx, &raw_key);
+       if (ret)
+               goto err;
 
        return 0;