linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH -next] drivers: w1: use kfree_sensitive()
  2022-05-11  6:49 [PATCH -next] drivers: w1: use kfree_sensitive() Yang Yingliang
@ 2022-05-11  6:45 ` Greg KH
  2022-05-11  7:25   ` Yang Yingliang
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2022-05-11  6:45 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, linux-hwmon, zbr, jdelvare, linux

On Wed, May 11, 2022 at 02:49:54PM +0800, Yang Yingliang wrote:
> Use kfree_sensitive() instead of open-coding it.
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/w1/w1.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
> index f2ae2e563dc5..a0a6c3c739d9 100644
> --- a/drivers/w1/w1.c
> +++ b/drivers/w1/w1.c
> @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
>  	struct w1_master *md = dev_to_w1_master(dev);
>  
>  	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
> -	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
> -	kfree(md);
> +	kfree_sensitive(md);

Does this actually change anything?  Why is the memset being called here
at all?

thanks,

greg k-h

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

* [PATCH -next] drivers: w1: use kfree_sensitive()
@ 2022-05-11  6:49 Yang Yingliang
  2022-05-11  6:45 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Yang Yingliang @ 2022-05-11  6:49 UTC (permalink / raw)
  To: linux-kernel, linux-hwmon; +Cc: zbr, jdelvare, linux, gregkh

Use kfree_sensitive() instead of open-coding it.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/w1/w1.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index f2ae2e563dc5..a0a6c3c739d9 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
 	struct w1_master *md = dev_to_w1_master(dev);
 
 	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
-	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
-	kfree(md);
+	kfree_sensitive(md);
 }
 
 static void w1_slave_release(struct device *dev)
-- 
2.25.1


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

* Re: [PATCH -next] drivers: w1: use kfree_sensitive()
  2022-05-11  6:45 ` Greg KH
@ 2022-05-11  7:25   ` Yang Yingliang
  2022-05-11 10:05     ` Greg KH
  2022-05-17 10:18     ` Greg KH
  0 siblings, 2 replies; 7+ messages in thread
From: Yang Yingliang @ 2022-05-11  7:25 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, linux-hwmon, zbr, jdelvare, linux

Hi,

On 2022/5/11 14:45, Greg KH wrote:
> On Wed, May 11, 2022 at 02:49:54PM +0800, Yang Yingliang wrote:
>> Use kfree_sensitive() instead of open-coding it.
>>
>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>> ---
>>   drivers/w1/w1.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
>> index f2ae2e563dc5..a0a6c3c739d9 100644
>> --- a/drivers/w1/w1.c
>> +++ b/drivers/w1/w1.c
>> @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
>>   	struct w1_master *md = dev_to_w1_master(dev);
>>   
>>   	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
>> -	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
>> -	kfree(md);
>> +	kfree_sensitive(md);
> Does this actually change anything?  Why is the memset being called here
> at all?
It's no functional change and I got this by 
scripts/coccinelle/api/kfree_sensitive.cocci.
I'm not sure why using memset() here.

Thanks,
Yang
>
> thanks,
>
> greg k-h
> .

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

* Re: [PATCH -next] drivers: w1: use kfree_sensitive()
  2022-05-11  7:25   ` Yang Yingliang
@ 2022-05-11 10:05     ` Greg KH
  2022-05-17 10:18     ` Greg KH
  1 sibling, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-05-11 10:05 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, linux-hwmon, zbr, jdelvare, linux

On Wed, May 11, 2022 at 03:25:52PM +0800, Yang Yingliang wrote:
> Hi,
> 
> On 2022/5/11 14:45, Greg KH wrote:
> > On Wed, May 11, 2022 at 02:49:54PM +0800, Yang Yingliang wrote:
> > > Use kfree_sensitive() instead of open-coding it.
> > > 
> > > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > > ---
> > >   drivers/w1/w1.c | 3 +--
> > >   1 file changed, 1 insertion(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
> > > index f2ae2e563dc5..a0a6c3c739d9 100644
> > > --- a/drivers/w1/w1.c
> > > +++ b/drivers/w1/w1.c
> > > @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
> > >   	struct w1_master *md = dev_to_w1_master(dev);
> > >   	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
> > > -	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
> > > -	kfree(md);
> > > +	kfree_sensitive(md);
> > Does this actually change anything?  Why is the memset being called here
> > at all?
> It's no functional change and I got this by
> scripts/coccinelle/api/kfree_sensitive.cocci.

That's an odd rule, and as you can see here, not always correct or
needed.

> I'm not sure why using memset() here.

Then let's not make this change without figuring that out first please.

thanks,

greg k-h

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

* Re: [PATCH -next] drivers: w1: use kfree_sensitive()
  2022-05-11  7:25   ` Yang Yingliang
  2022-05-11 10:05     ` Greg KH
@ 2022-05-17 10:18     ` Greg KH
  2022-05-17 13:03       ` Yang Yingliang
  1 sibling, 1 reply; 7+ messages in thread
From: Greg KH @ 2022-05-17 10:18 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, linux-hwmon, zbr, jdelvare, linux

On Wed, May 11, 2022 at 03:25:52PM +0800, Yang Yingliang wrote:
> Hi,
> 
> On 2022/5/11 14:45, Greg KH wrote:
> > On Wed, May 11, 2022 at 02:49:54PM +0800, Yang Yingliang wrote:
> > > Use kfree_sensitive() instead of open-coding it.
> > > 
> > > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > > ---
> > >   drivers/w1/w1.c | 3 +--
> > >   1 file changed, 1 insertion(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
> > > index f2ae2e563dc5..a0a6c3c739d9 100644
> > > --- a/drivers/w1/w1.c
> > > +++ b/drivers/w1/w1.c
> > > @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
> > >   	struct w1_master *md = dev_to_w1_master(dev);
> > >   	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
> > > -	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
> > > -	kfree(md);
> > > +	kfree_sensitive(md);
> > Does this actually change anything?  Why is the memset being called here
> > at all?
> It's no functional change and I got this by
> scripts/coccinelle/api/kfree_sensitive.cocci.
> I'm not sure why using memset() here.

I think the memset() can just be dropped.  Can you make that change and
test it to verify it still works properly with that change?

thanks,

greg k-h

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

* Re: [PATCH -next] drivers: w1: use kfree_sensitive()
  2022-05-17 10:18     ` Greg KH
@ 2022-05-17 13:03       ` Yang Yingliang
  2022-05-17 13:48         ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Yang Yingliang @ 2022-05-17 13:03 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, linux-hwmon, zbr, jdelvare, linux


On 2022/5/17 18:18, Greg KH wrote:
> On Wed, May 11, 2022 at 03:25:52PM +0800, Yang Yingliang wrote:
>> Hi,
>>
>> On 2022/5/11 14:45, Greg KH wrote:
>>> On Wed, May 11, 2022 at 02:49:54PM +0800, Yang Yingliang wrote:
>>>> Use kfree_sensitive() instead of open-coding it.
>>>>
>>>> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
>>>> ---
>>>>    drivers/w1/w1.c | 3 +--
>>>>    1 file changed, 1 insertion(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
>>>> index f2ae2e563dc5..a0a6c3c739d9 100644
>>>> --- a/drivers/w1/w1.c
>>>> +++ b/drivers/w1/w1.c
>>>> @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
>>>>    	struct w1_master *md = dev_to_w1_master(dev);
>>>>    	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
>>>> -	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
>>>> -	kfree(md);
>>>> +	kfree_sensitive(md);
>>> Does this actually change anything?  Why is the memset being called here
>>> at all?
>> It's no functional change and I got this by
>> scripts/coccinelle/api/kfree_sensitive.cocci.
>> I'm not sure why using memset() here.
> I think the memset() can just be dropped.  Can you make that change and
> test it to verify it still works properly with that change?
I can make change and send a patch for this, but I don't have device to 
test it.
>
> thanks,
>
> greg k-h
> .

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

* Re: [PATCH -next] drivers: w1: use kfree_sensitive()
  2022-05-17 13:03       ` Yang Yingliang
@ 2022-05-17 13:48         ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2022-05-17 13:48 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, linux-hwmon, zbr, jdelvare, linux

On Tue, May 17, 2022 at 09:03:43PM +0800, Yang Yingliang wrote:
> 
> On 2022/5/17 18:18, Greg KH wrote:
> > On Wed, May 11, 2022 at 03:25:52PM +0800, Yang Yingliang wrote:
> > > Hi,
> > > 
> > > On 2022/5/11 14:45, Greg KH wrote:
> > > > On Wed, May 11, 2022 at 02:49:54PM +0800, Yang Yingliang wrote:
> > > > > Use kfree_sensitive() instead of open-coding it.
> > > > > 
> > > > > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > > > > ---
> > > > >    drivers/w1/w1.c | 3 +--
> > > > >    1 file changed, 1 insertion(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
> > > > > index f2ae2e563dc5..a0a6c3c739d9 100644
> > > > > --- a/drivers/w1/w1.c
> > > > > +++ b/drivers/w1/w1.c
> > > > > @@ -73,8 +73,7 @@ static void w1_master_release(struct device *dev)
> > > > >    	struct w1_master *md = dev_to_w1_master(dev);
> > > > >    	dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
> > > > > -	memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
> > > > > -	kfree(md);
> > > > > +	kfree_sensitive(md);
> > > > Does this actually change anything?  Why is the memset being called here
> > > > at all?
> > > It's no functional change and I got this by
> > > scripts/coccinelle/api/kfree_sensitive.cocci.
> > > I'm not sure why using memset() here.
> > I think the memset() can just be dropped.  Can you make that change and
> > test it to verify it still works properly with that change?
> I can make change and send a patch for this, but I don't have device to test
> it.

For something like this, it would be great to test.

thanks,

greg k-h

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

end of thread, other threads:[~2022-05-17 17:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11  6:49 [PATCH -next] drivers: w1: use kfree_sensitive() Yang Yingliang
2022-05-11  6:45 ` Greg KH
2022-05-11  7:25   ` Yang Yingliang
2022-05-11 10:05     ` Greg KH
2022-05-17 10:18     ` Greg KH
2022-05-17 13:03       ` Yang Yingliang
2022-05-17 13:48         ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).