From: Deepak R Varma <drv@mailo.com>
To: Evgeniy Polyakov <zbr@ioremap.net>, linux-kernel@vger.kernel.org
Cc: Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>,
drv@mailo.com
Subject: [PATCH] w1: Use kfree_sensitive to clear sensitive information
Date: Fri, 23 Dec 2022 04:09:22 +0530 [thread overview]
Message-ID: <Y6TcmtlRvvblvL2f@qemulion> (raw)
Replace combination of 'memset(0) + kfree()' by kfree_sensitive() as it
prevents compiler from optimizing away from zeroing out memory at the
end of a scope. kfree_sensitive() is also safe in case the memory
pointer turns out to be null, which simply gets ignored.
Issue identified using kfree_sensitive.cocci coccinelle semantic patch.
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Note: proposed change is compile tested only.
drivers/w1/w1.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index f2ae2e563dc5..e08467e08b73 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)
@@ -805,9 +804,10 @@ int w1_unref_slave(struct w1_slave *sl)
w1_family_notify(BUS_NOTIFY_DEL_DEVICE, sl);
device_unregister(&sl->dev);
#ifdef DEBUG
- memset(sl, 0, sizeof(*sl));
- #endif
+ kfree_sensitive(sl);
+ #else
kfree(sl);
+ #endif
}
atomic_dec(&dev->refcnt);
mutex_unlock(&dev->list_mutex);
--
2.34.1
next reply other threads:[~2022-12-22 22:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-22 22:39 Deepak R Varma [this message]
2023-01-07 20:11 ` [PATCH] w1: Use kfree_sensitive to clear sensitive information Deepak R Varma
2023-01-22 19:50 ` Deepak R Varma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y6TcmtlRvvblvL2f@qemulion \
--to=drv@mailo.com \
--cc=kumarpraveen@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ssengar@microsoft.com \
--cc=zbr@ioremap.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox