From: Todd C. Miller Date: Tue, 3 Jul 2018 19:58:49 +0000 (-0600) Subject: Use madvise(2) with MADV_WIPEONFORK if available. X-Git-Tag: SUDO_1_8_24^2~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33f96a03472a3f6ed74549c2989af467e3f65353;p=sudo Use madvise(2) with MADV_WIPEONFORK if available. --- diff --git a/lib/util/arc4random.h b/lib/util/arc4random.h index ec63c635e..d6490177e 100644 --- a/lib/util/arc4random.h +++ b/lib/util/arc4random.h @@ -63,17 +63,21 @@ _rs_forkhandler(void) } #endif /* HAVE_PTHREAD_ATFORK */ +static int wipeonfork; + static inline void _rs_forkdetect(void) { - static pid_t _rs_pid = 0; - pid_t pid = getpid(); - - if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { - _rs_pid = pid; - _rs_forked = 0; - if (rs) - memset(rs, 0, sizeof(*rs)); + if (!wipeonfork) { + static pid_t _rs_pid = 0; + pid_t pid = getpid(); + + if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { + _rs_pid = pid; + _rs_forked = 0; + if (rs) + memset(rs, 0, sizeof(*rs)); + } } } @@ -91,6 +95,13 @@ _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) return (-1); } +#ifdef MADV_WIPEONFORK + if (madvise (*rsp, sizeof(**rsp), MADV_WIPEONFORK) == 0 && + madvise (*rsxp, sizeof(**rsxp), MADV_WIPEONFORK) == 0) { + wipeonfork = 1; + } +#endif + _ARC4_ATFORK(_rs_forkhandler); return (0); }