mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: media: atomisp: Use kvfree_sensitive in a few places
@ 2020-09-09 19:53 Alex Dewar
  2020-09-09 20:06 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Dewar @ 2020-09-09 19:53 UTC (permalink / raw)
  Cc: Alex Dewar, Mauro Carvalho Chehab, Sakari Ailus,
	Greg Kroah-Hartman, linux-media, devel, linux-kernel

In the file pci/sh_css_params.c, there are a number of places where
memset+kvfree is used, where kvfree_sensitive could be used instead. Fix
these occurrences.

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
---
 .../staging/media/atomisp/pci/sh_css_params.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index 2c67c23b3700..d1b5d6608d52 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -4378,8 +4378,7 @@ ia_css_3a_statistics_free(struct ia_css_3a_statistics *me)
 	if (me) {
 		kvfree(me->rgby_data);
 		kvfree(me->data);
-		memset(me, 0, sizeof(struct ia_css_3a_statistics));
-		kvfree(me);
+		kvfree_sensitive(me, sizeof(struct ia_css_3a_statistics));
 	}
 }
 
@@ -4417,8 +4416,7 @@ ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me)
 	if (me) {
 		kvfree(me->hor_proj);
 		kvfree(me->ver_proj);
-		memset(me, 0, sizeof(struct ia_css_dvs_statistics));
-		kvfree(me);
+		kvfree_sensitive(me, sizeof(struct ia_css_dvs_statistics));
 	}
 }
 
@@ -4459,8 +4457,7 @@ ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me)
 	if (me) {
 		kvfree(me->hor_coefs);
 		kvfree(me->ver_coefs);
-		memset(me, 0, sizeof(struct ia_css_dvs_coefficients));
-		kvfree(me);
+		kvfree_sensitive(me, sizeof(struct ia_css_dvs_coefficients));
 	}
 }
 
@@ -4551,8 +4548,7 @@ ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me)
 		kvfree(me->ver_prod.odd_imag);
 		kvfree(me->ver_prod.even_real);
 		kvfree(me->ver_prod.even_imag);
-		memset(me, 0, sizeof(struct ia_css_dvs2_statistics));
-		kvfree(me);
+		kvfree_sensitive(me, sizeof(struct ia_css_dvs2_statistics));
 	}
 }
 
@@ -4635,8 +4631,7 @@ ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me)
 		kvfree(me->ver_coefs.odd_imag);
 		kvfree(me->ver_coefs.even_real);
 		kvfree(me->ver_coefs.even_imag);
-		memset(me, 0, sizeof(struct ia_css_dvs2_coefficients));
-		kvfree(me);
+		kvfree_sensitive(me, sizeof(struct ia_css_dvs2_coefficients));
 	}
 }
 
@@ -4710,8 +4705,8 @@ ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config)
 		kvfree(dvs_6axis_config->ycoords_y);
 		kvfree(dvs_6axis_config->xcoords_uv);
 		kvfree(dvs_6axis_config->ycoords_uv);
-		memset(dvs_6axis_config, 0, sizeof(struct ia_css_dvs_6axis_config));
-		kvfree(dvs_6axis_config);
+		kvfree_sensitive(dvs_6axis_config,
+				 sizeof(struct ia_css_dvs_6axis_config));
 	}
 }
 
-- 
2.28.0


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

* Re: [PATCH] staging: media: atomisp: Use kvfree_sensitive in a few places
  2020-09-09 19:53 [PATCH] staging: media: atomisp: Use kvfree_sensitive in a few places Alex Dewar
@ 2020-09-09 20:06 ` Dan Carpenter
  2020-09-09 20:40   ` Alex Dewar
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2020-09-09 20:06 UTC (permalink / raw)
  To: Alex Dewar
  Cc: devel, Greg Kroah-Hartman, linux-kernel, Sakari Ailus,
	Mauro Carvalho Chehab, linux-media

On Wed, Sep 09, 2020 at 08:53:50PM +0100, Alex Dewar wrote:
> In the file pci/sh_css_params.c, there are a number of places where
> memset+kvfree is used, where kvfree_sensitive could be used instead. Fix
> these occurrences.

This doesn't say *why* the commit is doing it.  There are two reasons:
The worry with these is that the compiler could optimize away the memset
because it sees the kfree().  Second using kvfree_sensitive() is more
clear and readable.

> 
> Issue identified with Coccinelle.
> 
> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
> ---
>  .../staging/media/atomisp/pci/sh_css_params.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
> index 2c67c23b3700..d1b5d6608d52 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css_params.c
> +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
> @@ -4378,8 +4378,7 @@ ia_css_3a_statistics_free(struct ia_css_3a_statistics *me)
>  	if (me) {
>  		kvfree(me->rgby_data);
>  		kvfree(me->data);
> -		memset(me, 0, sizeof(struct ia_css_3a_statistics));
> -		kvfree(me);
> +		kvfree_sensitive(me, sizeof(struct ia_css_3a_statistics));

I don't think ia_css_3a_statistics are sensitive at all.  What we're
trying to protect are things like passwords.  Just delete the memset.

Looking below, I don't think any of these are sensitive so just delete
all the memsets.

regards,
dan carpenter


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

* Re: [PATCH] staging: media: atomisp: Use kvfree_sensitive in a few places
  2020-09-09 20:06 ` Dan Carpenter
@ 2020-09-09 20:40   ` Alex Dewar
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Dewar @ 2020-09-09 20:40 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: devel, Greg Kroah-Hartman, linux-kernel, Sakari Ailus,
	Mauro Carvalho Chehab, linux-media

On 2020-09-09 21:06, Dan Carpenter wrote:
> On Wed, Sep 09, 2020 at 08:53:50PM +0100, Alex Dewar wrote:
>> In the file pci/sh_css_params.c, there are a number of places where
>> memset+kvfree is used, where kvfree_sensitive could be used instead. Fix
>> these occurrences.
> This doesn't say *why* the commit is doing it.  There are two reasons:
> The worry with these is that the compiler could optimize away the memset
> because it sees the kfree().  Second using kvfree_sensitive() is more
> clear and readable.
Good point :)
>
>> Issue identified with Coccinelle.
>>
>> Signed-off-by: Alex Dewar <alex.dewar90@gmail.com>
>> ---
>>   .../staging/media/atomisp/pci/sh_css_params.c | 19 +++++++------------
>>   1 file changed, 7 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
>> index 2c67c23b3700..d1b5d6608d52 100644
>> --- a/drivers/staging/media/atomisp/pci/sh_css_params.c
>> +++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
>> @@ -4378,8 +4378,7 @@ ia_css_3a_statistics_free(struct ia_css_3a_statistics *me)
>>   	if (me) {
>>   		kvfree(me->rgby_data);
>>   		kvfree(me->data);
>> -		memset(me, 0, sizeof(struct ia_css_3a_statistics));
>> -		kvfree(me);
>> +		kvfree_sensitive(me, sizeof(struct ia_css_3a_statistics));
> I don't think ia_css_3a_statistics are sensitive at all.  What we're
> trying to protect are things like passwords.  Just delete the memset.
>
> Looking below, I don't think any of these are sensitive so just delete
> all the memsets.
This makes sense. I'll send a new patch. Thanks for the feedback!

Alex
>
> regards,
> dan carpenter
>


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

end of thread, other threads:[~2020-09-09 20:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-09 19:53 [PATCH] staging: media: atomisp: Use kvfree_sensitive in a few places Alex Dewar
2020-09-09 20:06 ` Dan Carpenter
2020-09-09 20:40   ` Alex Dewar

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

all inboxes | Powered by JetHome®