Re: [PATCH v2] mm: Add kvfree_sensitive() for freeing sensitive data objects
From: Linus Torvalds
Date: Tue Apr 07 2020 - 17:23:08 EST
On Tue, Apr 7, 2020 at 2:14 PM David Howells <dhowells@xxxxxxxxxx> wrote:
>
> It might be worth asking the compiler folks to give us an __attribute__ for
> that - even if they don't do anything with it immediately. So we might have
> something like:
>
> void free(const volatile void *ptr) __attribute__((free(1)));
Yeah, that sounds sane.
> There are some for allocation functions, some of which we use, though I'm not
> sure we do so as consistently as we should (should inline functions like
> kcalloc() have them, for example?).
I think that gcc supports a "malloc" attribute, but it's only used for
alias analysis optimizations, afaik (ie it says that the pointer the
function returns cannot alias anything else).
So we do have that "__malloc" thing, but I'm not sure how much it
actually matters.
And adding it to inline functions shouldn't be _wrong_, but it
shouldn't matter either, since I think the alias analysis would work
regardless.
I wonder how much of a code generation difference it makes. I suspect
not a lot, but maybe I'd be surprsied.
But yes, having the free attribute would be consistent (even if the
syntax for it might be as you suggest, kind of like the __printf()
attribute works). Even if it wasn't initially used for anything it
wouldn't hurt, and maybe some day it would improve warnings (and allow
the compiler to do the dead store elimination that started this whole
long set of threads in the first place..)
Linus