2020-06-04 13:06:53

by Denis Efremov

[permalink] [raw]
Subject: [PATCH] scsi: storvsc: Use kzfree() in storvsc_suspend()

Use kzfree() instead of memset() with 0 followed by kfree().

Signed-off-by: Denis Efremov <[email protected]>
---
drivers/scsi/storvsc_drv.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 072ed8728657..e5a19cd8a450 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -2035,10 +2035,7 @@ static int storvsc_suspend(struct hv_device *hv_dev)

vmbus_close(hv_dev->channel);

- memset(stor_device->stor_chns, 0,
- num_possible_cpus() * sizeof(void *));
-
- kfree(stor_device->stor_chns);
+ kzfree(stor_device->stor_chns);
stor_device->stor_chns = NULL;

cpumask_clear(&stor_device->alloced_cpus);
--
2.26.2


2020-06-04 18:58:01

by Dexuan-Linux Cui

[permalink] [raw]
Subject: Re: [PATCH] scsi: storvsc: Use kzfree() in storvsc_suspend()

On Thu, Jun 4, 2020 at 6:06 AM Denis Efremov <[email protected]> wrote:
>
> Use kzfree() instead of memset() with 0 followed by kfree().
>
> Signed-off-by: Denis Efremov <[email protected]>
> ---
> drivers/scsi/storvsc_drv.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
> index 072ed8728657..e5a19cd8a450 100644
> --- a/drivers/scsi/storvsc_drv.c
> +++ b/drivers/scsi/storvsc_drv.c
> @@ -2035,10 +2035,7 @@ static int storvsc_suspend(struct hv_device *hv_dev)
>
> vmbus_close(hv_dev->channel);
>
> - memset(stor_device->stor_chns, 0,
> - num_possible_cpus() * sizeof(void *));
> -
> - kfree(stor_device->stor_chns);
> + kzfree(stor_device->stor_chns);
> stor_device->stor_chns = NULL;
>
> cpumask_clear(&stor_device->alloced_cpus);
> --
> 2.26.2

Hi Denis,
When I added the function storvsc_suspend() several months ago, somehow I forgot
to remove the unnecessary memset(). Sorry!

The buffer is recreated in storvsc_resume() -> storvsc_connect_to_vsp() ->
storvsc_channel_init() -> stor_device->stor_chns = kcalloc(...), so I believe
the memset() can be safely removed. Can you please make a v2 patch for it
and Cc my corporate email "decui" (in To)?

Thanks,
Dexuan

2020-06-04 22:03:43

by Dexuan Cui

[permalink] [raw]
Subject: RE: [PATCH] scsi: storvsc: Use kzfree() in storvsc_suspend()

> From: Dexuan Cui
> Sent: Thursday, June 4, 2020 2:50 PM
>
> > > Can you please make a v2 patch for it and Cc my corporate email "decui" (in
> > To)?
> >
> > Yes, of course. Could I add "Suggested-by"?
> >
> > Thanks,
> > Denis
>
> Sure.

Please also added a tag:

Fixes: 56fb10585934 ("scsi: storvsc: Add the support of hibernation")

Thanks,
Dexuan

2020-06-04 22:04:14

by Dexuan Cui

[permalink] [raw]
Subject: RE: [PATCH] scsi: storvsc: Use kzfree() in storvsc_suspend()

> From: Denis Efremov <[email protected]>
> Sent: Thursday, June 4, 2020 2:43 PM
> >
> > Hi Denis,
> > When I added the function storvsc_suspend() several months ago, somehow
> > I forgot to remove the unnecessary memset(). Sorry!
> >
> > The buffer is recreated in storvsc_resume() -> storvsc_connect_to_vsp() ->
> > storvsc_channel_init() -> stor_device->stor_chns = kcalloc(...), so I believe
> > the memset() can be safely removed.
>
> I'm not sure that I understand your description. As for me, memset with 0
> before
> memory freeing is required only for sensitive information and it's completely
> unrelated to memory zeroing during allocation with kzalloc/kcalloc.
> If it's not a sensitive information then memset could be safely removed.

There is no sensitive info in the buffer here.

> > Can you please make a v2 patch for it and Cc my corporate email "decui" (in
> To)?
>
> Yes, of course. Could I add "Suggested-by"?
>
> Thanks,
> Denis

Sure.

Thanks,
-- Dexuan

2020-06-04 23:13:37

by Denis Efremov

[permalink] [raw]
Subject: Re: [PATCH] scsi: storvsc: Use kzfree() in storvsc_suspend()

>
> Hi Denis,
> When I added the function storvsc_suspend() several months ago, somehow I forgot
> to remove the unnecessary memset(). Sorry!
>
> The buffer is recreated in storvsc_resume() -> storvsc_connect_to_vsp() ->
> storvsc_channel_init() -> stor_device->stor_chns = kcalloc(...), so I believe
> the memset() can be safely removed.

I'm not sure that I understand your description. As for me, memset with 0 before
memory freeing is required only for sensitive information and it's completely
unrelated to memory zeroing during allocation with kzalloc/kcalloc.
If it's not a sensitive information then memset could be safely removed.

> Can you please make a v2 patch for it and Cc my corporate email "decui" (in To)?

Yes, of course. Could I add "Suggested-by"?

Thanks,
Denis

2020-06-05 08:04:04

by Denis Efremov

[permalink] [raw]
Subject: [PATCH] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

Remove memset with 0 for stor_device->stor_chns in storvsc_suspend()
before the call to kfree() as the memory contains no sensitive information.

Fixes: 56fb10585934 ("scsi: storvsc: Add the support of hibernation")
Suggested-by: Dexuan Cui <[email protected]>
Signed-off-by: Denis Efremov <[email protected]>
---
drivers/scsi/storvsc_drv.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 072ed8728657..2d90cddd8ac2 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -2035,9 +2035,6 @@ static int storvsc_suspend(struct hv_device *hv_dev)

vmbus_close(hv_dev->channel);

- memset(stor_device->stor_chns, 0,
- num_possible_cpus() * sizeof(void *));
-
kfree(stor_device->stor_chns);
stor_device->stor_chns = NULL;

--
2.26.2

2020-06-05 08:12:42

by Dexuan Cui

[permalink] [raw]
Subject: RE: [PATCH] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

> From: Denis Efremov <[email protected]>
> Sent: Friday, June 5, 2020 1:00 AM
> To: Dexuan Cui <[email protected]>; Michael Kelley
> <[email protected]>
> Cc: Denis Efremov <[email protected]>; James E . J . Bottomley
> <[email protected]>; Martin K . Petersen <[email protected]>;
> [email protected]; Linux SCSI List <[email protected]>;
> Linux Kernel Mailing List <[email protected]>
> Subject: [PATCH] scsi: storvsc: Remove memset before memory freeing in
> storvsc_suspend()
>
> Remove memset with 0 for stor_device->stor_chns in storvsc_suspend()
> before the call to kfree() as the memory contains no sensitive information.
>
> Fixes: 56fb10585934 ("scsi: storvsc: Add the support of hibernation")
> Suggested-by: Dexuan Cui <[email protected]>
> Signed-off-by: Denis Efremov <[email protected]>
> ---
> drivers/scsi/storvsc_drv.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
> index 072ed8728657..2d90cddd8ac2 100644
> --- a/drivers/scsi/storvsc_drv.c
> +++ b/drivers/scsi/storvsc_drv.c
> @@ -2035,9 +2035,6 @@ static int storvsc_suspend(struct hv_device
> *hv_dev)
>
> vmbus_close(hv_dev->channel);
>
> - memset(stor_device->stor_chns, 0,
> - num_possible_cpus() * sizeof(void *));
> -
> kfree(stor_device->stor_chns);
> stor_device->stor_chns = NULL;
>
> --

Denis, thank you for fixing this!

Reviewed-by: Dexuan Cui <[email protected]>

2020-06-10 02:07:32

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

On Fri, 5 Jun 2020 10:59:34 +0300, Denis Efremov wrote:

> Remove memset with 0 for stor_device->stor_chns in storvsc_suspend()
> before the call to kfree() as the memory contains no sensitive information.

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()
https://git.kernel.org/mkp/scsi/c/f47c24033a1a

--
Martin K. Petersen Oracle Linux Engineering