On Tue, 28 Nov 2017 05:52:25 +0000, Theo de Raadt wrote:
> > In fact, can recallocarray be faster than plain free followed by calloc?
>
> Yes.
>
> I think you are missing some nuances.  These added functions have fast paths
> and slow paths.  freezero() isn't just a bzero, it also has munmap()
> sequences.  You are adding forced bzero or munmap() in circumstances
> where previously a malloc implementation could keep the freed'd memory in
> a cache for reuse.

Hence programs willing to avoid leaking secrets to such cache cannot
safely use stdio functions to manipulate those secrets.  But, sure, this
may very well be acceptable as, after all, stdio is merely a library
provided for convenience, and programs needing complete control over
their memory could use their own wrappers around raw system calls
instead.

> I find it hard to read your diff as convert other than "convert all free
> operations to freezero", or always pay the cost no matter what.

I indeed took a systematic approach, so perhaps the bits in vfprintf.c
and vfwprintf.c are in fact overkill, and they could be left out.
However, this does not invalidate the other parts of my first patch,
many of which simply mirror the already established use of recallocarray
on the same buffers.

Regards,

kshe

Reply via email to