2020-09-09 19:42:32

by Alex Dewar

[permalink] [raw]
Subject: [PATCH 1/2] w1: Use kfree_sensitive instead of memset+kfree

Issue identified with Coccinelle.

Signed-off-by: Alex Dewar <[email protected]>
---
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 e58c7592008d..4f597b0fd1da 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -71,8 +71,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.28.0


2020-09-09 20:32:21

by Alex Dewar

[permalink] [raw]
Subject: Re: [PATCH 1/2] w1: Use kfree_sensitive instead of memset+kfree

On 2020-09-09 20:41, Alex Dewar wrote:
> Issue identified with Coccinelle.
Hmm, on second thoughts, I'm not sure this memory is so sensitive after
all. Should we just remove the call to memset?
>
> Signed-off-by: Alex Dewar <[email protected]>
> ---
> 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 e58c7592008d..4f597b0fd1da 100644
> --- a/drivers/w1/w1.c
> +++ b/drivers/w1/w1.c
> @@ -71,8 +71,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)