Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 18 Sep 2021 02:36:50 +0300
From: Konstantin Belousov <kostikbel@...il.com>
To: libc-coord@...ts.openwall.com
Subject: Re: freezero() and freezeroall()

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?

BTW is clearing done by userspace or kernel?  Does kernel ensure that
possible copies anywhere, e.g. in swap, are obliterated as well?

Just that the described semantic of the function is too vague, and it
is impossible to understand the real effects without turning to the
implementation.

> 
> The reliance on the caller to provide the size to clear allows the function
> to be implemented independently of the underlying allocator library, and has
> allowed this function to be implemented in libbsd, as well as fallback
> implementations provided in portable software packages for systems without
> their own implementation - including in OpenSSH, OpenNNTPd, OpenBGPd,
> OpenIKEd, OpenSMTPd, sudo, tmux, libretls, and a few more I see in the search
> results on codesearch.debian.net.  I've also seen it implemented in libc on
> illumos and DragonflyBSD.
> 
> I'm working on adding it to the Solaris libc now, and since we can determine
> the underlying allocation size, proposed also adding:
> 
>                 void freezeroall(void *ptr);
> 
> as basically doing: freezero(ptr, malloc_usable_size(ptr));
> 
> During review of this change I was asked if there's any existing equivalent
> we should be following instead before we invent our own name - I couldn't
> find one, but figured I'd ask here - are other libc implementations doing
> anything like this?
> 
> -- 
> 	-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.