From: chenridong <chenridong@huawei.com>
To: Chen Ridong <chenridong@huaweicloud.com>, <horia.geanta@nxp.com>,
<pankaj.gupta@nxp.com>, <gaurav.jain@nxp.com>,
<herbert@gondor.apana.org.au>, <davem@davemloft.net>,
<tudor-dan.ambarus@nxp.com>, <radu.alexe@nxp.com>
Cc: <linux-crypto@vger.kernel.org>, <wangweiyang2@huawei.com>
Subject: Re: [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form
Date: Mon, 11 Nov 2024 10:21:18 +0800 [thread overview]
Message-ID: <15bedaeb-245f-4748-9560-cdc081050f44@huawei.com> (raw)
In-Reply-To: <20241104121511.1634822-1-chenridong@huaweicloud.com>
On 2024/11/4 20:15, Chen Ridong wrote:
> From: Chen Ridong <chenridong@huawei.com>
>
> 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>
> ---
> drivers/crypto/caam/caampkc.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
> index 887a5f2fb927..cb001aa1de66 100644
> --- a/drivers/crypto/caam/caampkc.c
> +++ b/drivers/crypto/caam/caampkc.c
> @@ -984,7 +984,7 @@ static int caam_rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,
> 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 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
> 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;
>
Friendly ping
Best regards,
Ridong
next prev parent reply other threads:[~2024-11-11 2:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-04 12:15 [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form Chen Ridong
2024-11-11 2:21 ` chenridong [this message]
2024-11-11 5:28 ` [EXT] " Gaurav Jain
2024-11-13 12:56 ` Horia Geanta
2024-11-15 11:56 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15bedaeb-245f-4748-9560-cdc081050f44@huawei.com \
--to=chenridong@huawei.com \
--cc=chenridong@huaweicloud.com \
--cc=davem@davemloft.net \
--cc=gaurav.jain@nxp.com \
--cc=herbert@gondor.apana.org.au \
--cc=horia.geanta@nxp.com \
--cc=linux-crypto@vger.kernel.org \
--cc=pankaj.gupta@nxp.com \
--cc=radu.alexe@nxp.com \
--cc=tudor-dan.ambarus@nxp.com \
--cc=wangweiyang2@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox