<div dir="ltr"><div>Version 4.14 of the Linux kernel was released on November 12th, and it contains a new MADV_WIPEONFORK option for madvise(). Memory regions marked with the option will be wiped (set to all zeroes) in the child process after a call to fork() (or clone() or whatever). This is similar to the MINHERIT_ZERO option from OpenBSD that the new addition is based on.</div><div><br></div><div>For crypto libraries this is particularly useful:</div><div><br></div><div>  * The option can be used to robustly reset a guard variable, and hence re-initialize an RNG, DRBG, PRF, or other generator where duplicate state across processes would be a security issue.  </div><div>  * The option can be used to ensure that keys and plaintext are not inadvertently duplicated across processes and lingering in memory needlessly. </div><div>  * The option avoids the problems of pthread_atfork, which is avoided by some applications (they syscall clone directly), and the overhead, probabilistic risk or caching risk of using getpid() and getppid() guards to detect forks. </div><div>  * The option can be combined with MADV_DONTDUMP (prevents memory from showing up in a core dump) and mlock() (prevents memory from being swapped) to ensure that sensitive data is also not recorded on disk.<br></div><div><br></div><div>To use the option, it's as simple as something like ...</div><div><br></div><div>#ifdef MADV_WIPEONFORK</div><div><br></div><div>if (madvise(addr, len, MADV_WIPEONFORK)) {</div><div>    /* madvise failed, maybe an older kernel */</div><div>}</div><div><br></div><div>#endif</div><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Colm</div>
</div>