Re: [PATCH v3] mm: Add kvfree_sensitive() for freeing sensitive data objects

From: Joe Perches
Date: Tue Apr 07 2020 - 20:37:27 EST


On Tue, 2020-04-07 at 15:12 -0700, Matthew Wilcox wrote:
> On Tue, Apr 07, 2020 at 04:45:45PM -0400, Waiman Long wrote:
> > On 4/7/20 4:31 PM, Joe Perches wrote:
> > > On Tue, 2020-04-07 at 16:03 -0400, Waiman Long wrote:
> > > > +extern void kvfree_sensitive(const void *addr, size_t len);
> > > Why should size_t len be required?
> > >
> > > Why not do what kzfree does and memset
> > > the entire allocation? (area->size)
> >
> > If the memory is really virtually mapped, the only way to find out the
> > size of the object is to use find_vm_area() which can be relatively high
> > cost and no simple helper function is available. On the other hand, the
> > length is readily available in the callers. So passing the length
> > directly to the kvfree_sensitive is simpler.
>
> Also it lets us zero only the first N bytes of the allocation. That might
> be good for performance, if only the first N bytes of an M byte allocation
> are actually sensitive. I don't know if we have any such cases, but
> they could exist.

I would really doubt it as the allocation of
sensitive data should generally be separate.

Also, a similar argument could apply to
kzfree/kfree_sensitive.