Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] crypto: caam: Clear some memory in instantiate_rng()
@ 2023-03-20 23:45 Christophe JAILLET
  2023-03-21  3:26 ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe JAILLET @ 2023-03-20 23:45 UTC (permalink / raw)
  To: horia.geanta, pankaj.gupta, gaurav.jain, herbert, davem
  Cc: linux-crypto, linux-kernel, kernel-janitors, Christophe JAILLET

According to the comment at the end of the 'for' loop just a few lines
below, it looks needed to clear 'desc'.

So it should also be cleared for the first iteration.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is speculative, but can't hurt.

Maybe the memset() at the end of the 'for' loop could be removed instead.
---
 drivers/crypto/caam/ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 32253a064d0f..e4e971dc0f96 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -276,7 +276,7 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,
 	int ret = 0, sh_idx;
 
 	ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;
-	desc = kmalloc(CAAM_CMD_SZ * 7, GFP_KERNEL | GFP_DMA);
+	desc = kzalloc(CAAM_CMD_SZ * 7, GFP_KERNEL | GFP_DMA);
 	if (!desc)
 		return -ENOMEM;
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] crypto: caam: Clear some memory in instantiate_rng()
  2023-03-20 23:45 [PATCH] crypto: caam: Clear some memory in instantiate_rng() Christophe JAILLET
@ 2023-03-21  3:26 ` Herbert Xu
  2023-03-21  5:03   ` [EXT] " Gaurav Jain
  0 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2023-03-21  3:26 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: horia.geanta, pankaj.gupta, gaurav.jain, davem, linux-crypto,
	linux-kernel, kernel-janitors

On Tue, Mar 21, 2023 at 12:45:43AM +0100, Christophe JAILLET wrote:
> According to the comment at the end of the 'for' loop just a few lines
> below, it looks needed to clear 'desc'.
> 
> So it should also be cleared for the first iteration.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This patch is speculative, but can't hurt.
> 
> Maybe the memset() at the end of the 'for' loop could be removed instead.

I think the memset can be removed.  Horia?
-- 
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

* RE: [EXT] Re: [PATCH] crypto: caam: Clear some memory in instantiate_rng()
  2023-03-21  3:26 ` Herbert Xu
@ 2023-03-21  5:03   ` Gaurav Jain
  2023-03-21  5:06     ` Herbert Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Gaurav Jain @ 2023-03-21  5:03 UTC (permalink / raw)
  To: Herbert Xu, Christophe JAILLET
  Cc: Horia Geanta, Pankaj Gupta, davem@davemloft.net,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org

Hi Herbert

> -----Original Message-----
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Sent: Tuesday, March 21, 2023 8:57 AM
> To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Cc: Horia Geanta <horia.geanta@nxp.com>; Pankaj Gupta
> <pankaj.gupta@nxp.com>; Gaurav Jain <gaurav.jain@nxp.com>;
> davem@davemloft.net; linux-crypto@vger.kernel.org; linux-
> kernel@vger.kernel.org; kernel-janitors@vger.kernel.org
> Subject: [EXT] Re: [PATCH] crypto: caam: Clear some memory in
> instantiate_rng()
> 
> Caution: EXT Email
> 
> On Tue, Mar 21, 2023 at 12:45:43AM +0100, Christophe JAILLET wrote:
> > According to the comment at the end of the 'for' loop just a few lines
> > below, it looks needed to clear 'desc'.
> >
> > So it should also be cleared for the first iteration.
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> > This patch is speculative, but can't hurt.
> >
> > Maybe the memset() at the end of the 'for' loop could be removed instead.
> 
> I think the memset can be removed.  Horia?
memset() is needed to clear the desc for each state handle before recreating descriptor.
So it is required.

Regards
Gaurav Jain
> --
> Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgondor
> .apana.org.au%2F~herbert%2F&data=05%7C01%7Cgaurav.jain%40nxp.com%
> 7C93eb192d0c734fc5105e08db29bc1da2%7C686ea1d3bc2b4c6fa92cd99c5c3
> 01635%7C0%7C0%7C638149660155476281%7CUnknown%7CTWFpbGZsb3d8
> eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
> D%7C3000%7C%7C%7C&sdata=S%2Bh6BA5ka9HoWb%2BHq8Vwb3TwnEu8b
> RZ5scpGvOxg8iw%3D&reserved=0
> PGP Key:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgondor
> .apana.org.au%2F~herbert%2Fpubkey.txt&data=05%7C01%7Cgaurav.jain%4
> 0nxp.com%7C93eb192d0c734fc5105e08db29bc1da2%7C686ea1d3bc2b4c6fa
> 92cd99c5c301635%7C0%7C0%7C638149660155476281%7CUnknown%7CTWF
> pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV
> CI6Mn0%3D%7C3000%7C%7C%7C&sdata=7YT4gr8kviqJYFABOcg6UgZL3BceG
> 3oY4HUSUuUwAdg%3D&reserved=0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [EXT] Re: [PATCH] crypto: caam: Clear some memory in instantiate_rng()
  2023-03-21  5:03   ` [EXT] " Gaurav Jain
@ 2023-03-21  5:06     ` Herbert Xu
  2023-03-21  6:55       ` Gaurav Jain
  0 siblings, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2023-03-21  5:06 UTC (permalink / raw)
  To: Gaurav Jain
  Cc: Christophe JAILLET, Horia Geanta, Pankaj Gupta,
	davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

On Tue, Mar 21, 2023 at 05:03:24AM +0000, Gaurav Jain wrote:
>
> memset() is needed to clear the desc for each state handle before recreating descriptor.
> So it is required.

OK so we should move it to the top of the loop then.

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

* RE: [EXT] Re: [PATCH] crypto: caam: Clear some memory in instantiate_rng()
  2023-03-21  5:06     ` Herbert Xu
@ 2023-03-21  6:55       ` Gaurav Jain
  0 siblings, 0 replies; 5+ messages in thread
From: Gaurav Jain @ 2023-03-21  6:55 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Christophe JAILLET, Horia Geanta, Pankaj Gupta,
	davem@davemloft.net, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org

Hi

> -----Original Message-----
> From: Herbert Xu <herbert@gondor.apana.org.au>
> Sent: Tuesday, March 21, 2023 10:37 AM
> To: Gaurav Jain <gaurav.jain@nxp.com>
> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>; Horia Geanta
> <horia.geanta@nxp.com>; Pankaj Gupta <pankaj.gupta@nxp.com>;
> davem@davemloft.net; linux-crypto@vger.kernel.org; linux-
> kernel@vger.kernel.org; kernel-janitors@vger.kernel.org
> Subject: Re: [EXT] Re: [PATCH] crypto: caam: Clear some memory in
> instantiate_rng()
> 
> Caution: EXT Email
> 
> On Tue, Mar 21, 2023 at 05:03:24AM +0000, Gaurav Jain wrote:
> >
> > memset() is needed to clear the desc for each state handle before
> recreating descriptor.
> > So it is required.
> 
> OK so we should move it to the top of the loop then.
kzalloc() will zeroize the contents of desc for the first time.
In this case memset() is ok at the end for instantiating other rng handles.
 
Thanks
Gaurav

> 
> Thanks,
> --
> Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgondor
> .apana.org.au%2F~herbert%2F&data=05%7C01%7Cgaurav.jain%40nxp.com%
> 7C46125a50355a466bbd6208db29ca159a%7C686ea1d3bc2b4c6fa92cd99c5c3
> 01635%7C0%7C0%7C638149720177317067%7CUnknown%7CTWFpbGZsb3d8
> eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3
> D%7C3000%7C%7C%7C&sdata=DmvSAsFT0dY%2FL%2FP5lcw90hR0FYAKRdnI
> kZxiaMN1MVk%3D&reserved=0
> PGP Key:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgondor
> .apana.org.au%2F~herbert%2Fpubkey.txt&data=05%7C01%7Cgaurav.jain%4
> 0nxp.com%7C46125a50355a466bbd6208db29ca159a%7C686ea1d3bc2b4c6fa
> 92cd99c5c301635%7C0%7C0%7C638149720177317067%7CUnknown%7CTWF
> pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV
> CI6Mn0%3D%7C3000%7C%7C%7C&sdata=8NA1ediu3cnWLFbisXecjq5Z%2BuK
> uztPYtlcRDCPSMno%3D&reserved=0

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-21  6:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-20 23:45 [PATCH] crypto: caam: Clear some memory in instantiate_rng() Christophe JAILLET
2023-03-21  3:26 ` Herbert Xu
2023-03-21  5:03   ` [EXT] " Gaurav Jain
2023-03-21  5:06     ` Herbert Xu
2023-03-21  6:55       ` Gaurav Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox