From: Joe Perches Date: Mon, 06 Apr 2020 18:46:26 +0000 Subject: Re: [PATCH] mm: Add kvfree_sensitive() for freeing sensitive data objects Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit List-Id: References: <20200406023700.1367-1-longman@redhat.com> <319765.1586188840@warthog.procyon.org.uk> <19cbf3b1-2c3f-dd0f-a5c6-69ca3f77dd68@redhat.com> In-Reply-To: To: Linus Torvalds , Waiman Long Cc: David Howells , Andrew Morton , Jarkko Sakkinen , James Morris , "Serge E. Hallyn" , Linux-MM , keyrings@vger.kernel.org, Linux Kernel Mailing List On Mon, 2020-04-06 at 11:06 -0700, Linus Torvalds wrote: > On Mon, Apr 6, 2020 at 10:59 AM Waiman Long wrote: > > I have actually been thinking about that. I saw a couple of cases in the > > crypto code where a memzero_explicit() is followed by kfree(). Those can > > be replaced by kfree_sensitive. > > Ack. > > Doing that (and renaming kvzfree) should be a fairly straightforward > coccinelle patch. Not really as comment and prototype and existing cocci scripts that contain kzfree are difficult to change. A sed is straightforward and works well. $ git grep -w --name-only kzfree | \ xargs sed -i 's/\bkzfree\b/kfree_sensitive/' For today's next that's: $ git diff --shortstat 116 files changed, 322 insertions(+), 322 deletions(-) After this change: The kernel-doc comment in slab_common.c should be edited from zeroed to something else. * kfree_sensitive - like kfree but zero memory * @p: object to free memory of * * The memory of the object @p points to is zeroed before freed. * If @p is %NULL, kfree_sensitive() does nothing. * * Note: this function zeroes the whole allocated buffer which can be a good * deal bigger than the requested buffer size passed to kmalloc(). So be * careful when using this function in performance sensitive code. */