mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
crypto: caam - add error check to caam_rsa_set_priv_key_form
[ Upstream commit b64140c74e954f1db6eae5548ca3a1f41b6fad79 ]
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: 52e26d77b8 ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
4771ad8c70
commit
e951b29237
@@ -979,7 +979,7 @@ err:
|
|||||||
return -ENOMEM;
|
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 rsa_key *raw_key)
|
||||||
{
|
{
|
||||||
struct caam_rsa_key *rsa_key = &ctx->key;
|
struct caam_rsa_key *rsa_key = &ctx->key;
|
||||||
@@ -988,7 +988,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);
|
rsa_key->p = caam_read_raw_data(raw_key->p, &p_sz);
|
||||||
if (!rsa_key->p)
|
if (!rsa_key->p)
|
||||||
return;
|
return -ENOMEM;
|
||||||
rsa_key->p_sz = p_sz;
|
rsa_key->p_sz = p_sz;
|
||||||
|
|
||||||
rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz);
|
rsa_key->q = caam_read_raw_data(raw_key->q, &q_sz);
|
||||||
@@ -1021,7 +1021,7 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
|
|||||||
|
|
||||||
rsa_key->priv_form = FORM3;
|
rsa_key->priv_form = FORM3;
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
free_dq:
|
free_dq:
|
||||||
kfree_sensitive(rsa_key->dq);
|
kfree_sensitive(rsa_key->dq);
|
||||||
@@ -1035,6 +1035,7 @@ free_q:
|
|||||||
kfree_sensitive(rsa_key->q);
|
kfree_sensitive(rsa_key->q);
|
||||||
free_p:
|
free_p:
|
||||||
kfree_sensitive(rsa_key->p);
|
kfree_sensitive(rsa_key->p);
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
|
static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
|
||||||
@@ -1080,7 +1081,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->e_sz = raw_key.e_sz;
|
||||||
rsa_key->n_sz = raw_key.n_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;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user