Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8bce1f65-b5d6-2eea-fb29-76f72dca2a87@oracle.com>
Date: Fri, 17 Sep 2021 17:20:20 -0700
From: Alan Coopersmith <alan.coopersmith@...cle.com>
To: libc-coord@...ts.openwall.com, Konstantin Belousov <kostikbel@...il.com>
Subject: Re: freezero() and freezeroall()

On 9/17/21 4:36 PM, Konstantin Belousov wrote:
> On Fri, Sep 17, 2021 at 04:31:13PM -0700, Alan Coopersmith wrote:
>> OpenBSD 6.2 added a new interface to their libc:
>>
>>                void freezero(void *ptr, size_t size);
>>
>> The man page at https://man.openbsd.org/freezero defines it as:
>>
>>               The freezero() function is similar to the free() function
>>               except it ensures memory is explicitly discarded. If ptr
>>               is NULL, no action occurs. If ptr is not NULL, the size
>>               argument must be equal to or smaller than the size of the
>>               earlier allocation that returned ptr. freezero()
>>               guarantees the memory range starting at ptr with length
>>               size is discarded while deallocating the whole object
>>               originally allocated.
>>
>>           where "discarded" is defined as:
>>
>>               pages of memory are disposed via munmap(2) and cached
>>               free objects are cleared with explicit_bzero(3).
> And what does the function do if the page is co-populated by unrelated
> allocations?

My reading of it is that if free() is getting rid of entire pages, then
it just munmaps them, and anything left on pages that aren't being unmapped
is cleared with explicit_bzero().  At the moment I'm just calling
explicit_bzero() on everything and leaving the work to skip that if calling
munmap() as a later optimization.

> BTW is clearing done by userspace or kernel?

Userspace.

> Does kernel ensure that
> possible copies anywhere, e.g. in swap, are obliterated as well?

I don't know in the general case.  If you look at the man page at
https://man.openbsd.org/freezero you'll see there's also "conceal"
versions of the allocation functions to ensure that pages aren't
written to swap, but that's something that has to be done in
coordination with the kernel, not purely in libc.

-- 
	-Alan Coopersmith-               alan.coopersmith@...cle.com
	 Oracle Solaris Engineering - https://blogs.oracle.com/alanc

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.