* [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form
@ 2024-11-04 12:15 Chen Ridong
2024-11-11 2:21 ` chenridong
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Chen Ridong @ 2024-11-04 12:15 UTC (permalink / raw)
To: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem,
tudor-dan.ambarus, radu.alexe
Cc: linux-crypto, chenridong, wangweiyang2
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;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form
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
2024-11-11 5:28 ` [EXT] " Gaurav Jain
2024-11-13 12:56 ` Horia Geanta
2024-11-15 11:56 ` Herbert Xu
2 siblings, 1 reply; 5+ messages in thread
From: chenridong @ 2024-11-11 2:21 UTC (permalink / raw)
To: Chen Ridong, horia.geanta, pankaj.gupta, gaurav.jain, herbert,
davem, tudor-dan.ambarus, radu.alexe
Cc: linux-crypto, wangweiyang2
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
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [EXT] Re: [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form
2024-11-11 2:21 ` chenridong
@ 2024-11-11 5:28 ` Gaurav Jain
0 siblings, 0 replies; 5+ messages in thread
From: Gaurav Jain @ 2024-11-11 5:28 UTC (permalink / raw)
To: chenridong, Chen Ridong, Horia Geanta, Pankaj Gupta,
herbert@gondor.apana.org.au, davem@davemloft.net,
tudor-dan.ambarus@nxp.com, Radu Andrei Alexe
Cc: linux-crypto@vger.kernel.org, wangweiyang2@huawei.com
Reviewed-by: Gaurav Jain <gaurav.jain@nxp.com>
> -----Original Message-----
> From: chenridong <chenridong@huawei.com>
> Sent: Monday, November 11, 2024 7:51 AM
> To: Chen Ridong <chenridong@huaweicloud.com>; Horia Geanta
> <horia.geanta@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>; Gaurav
> Jain <gaurav.jain@nxp.com>; herbert@gondor.apana.org.au;
> davem@davemloft.net; tudor-dan.ambarus@nxp.com; Radu Andrei Alexe
> <radu.alexe@nxp.com>
> Cc: linux-crypto@vger.kernel.org; wangweiyang2@huawei.com
> Subject: [EXT] Re: [PATCH] crypto: caam - add error check to
> caam_rsa_set_priv_key_form
>
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
>
>
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form
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
@ 2024-11-13 12:56 ` Horia Geanta
2024-11-15 11:56 ` Herbert Xu
2 siblings, 0 replies; 5+ messages in thread
From: Horia Geanta @ 2024-11-13 12:56 UTC (permalink / raw)
To: Chen Ridong, Pankaj Gupta, Gaurav Jain,
herbert@gondor.apana.org.au, davem@davemloft.net,
tudor-dan.ambarus@nxp.com, Radu Andrei Alexe
Cc: linux-crypto@vger.kernel.org, chenridong@huawei.com,
wangweiyang2@huawei.com
On 11/4/2024 2:24 PM, 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>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Thanks,
Horia
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] crypto: caam - add error check to caam_rsa_set_priv_key_form
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
2024-11-13 12:56 ` Horia Geanta
@ 2024-11-15 11:56 ` Herbert Xu
2 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2024-11-15 11:56 UTC (permalink / raw)
To: Chen Ridong
Cc: horia.geanta, pankaj.gupta, gaurav.jain, davem, tudor-dan.ambarus,
radu.alexe, linux-crypto, chenridong, wangweiyang2
On Mon, Nov 04, 2024 at 12:15:11PM +0000, 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(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-15 11:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-11-11 5:28 ` [EXT] " Gaurav Jain
2024-11-13 12:56 ` Horia Geanta
2024-11-15 11:56 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox