summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/exit.c
diff options
context:
space:
mode:
authordhartmei <dhartmei@openbsd.org>2002-07-29 19:54:42 +0000
committerdhartmei <dhartmei@openbsd.org>2002-07-29 19:54:42 +0000
commitf8c1f0d009f7abd3f8c7892ef28889e323bd1421 (patch)
treefceaa25db605fa094524dea156a9f83969805383 /lib/libc/stdlib/exit.c
parentTry to modify __atexit directly and see if our function gets called. (diff)
downloadwireguard-openbsd-f8c1f0d009f7abd3f8c7892ef28889e323bd1421.tar.xz
wireguard-openbsd-f8c1f0d009f7abd3f8c7892ef28889e323bd1421.zip
Replace atexit handler. mprotect() the pages so an attempt to modify the
function pointers from the outside will segfault. Idea, hints and feedback from deraadt. ok deraadt.
Diffstat (limited to 'lib/libc/stdlib/exit.c')
-rw-r--r--lib/libc/stdlib/exit.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c
index ab53f9400bc..c16b33bd300 100644
--- a/lib/libc/stdlib/exit.c
+++ b/lib/libc/stdlib/exit.c
@@ -32,9 +32,11 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: exit.c,v 1.4 2000/01/06 08:45:50 d Exp $";
+static char *rcsid = "$OpenBSD: exit.c,v 1.5 2002/07/29 19:54:42 dhartmei Exp $";
#endif /* LIBC_SCCS and not lint */
+#include <sys/types.h>
+#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include "atexit.h"
@@ -58,12 +60,19 @@ void
exit(status)
int status;
{
- register struct atexit *p;
- register int n;
+ register struct atexit *p, *q;
+ register int n, pgsize = getpagesize();
- for (p = __atexit; p; p = p->next)
- for (n = p->ind; --n >= 0;)
- (*p->fns[n])();
+ if (!__atexit_invalid) {
+ p = __atexit;
+ while (p != NULL) {
+ for (n = p->ind; --n >= 0;)
+ (*p->fns[n])();
+ q = p;
+ p = p->next;
+ munmap(q, pgsize);
+ }
+ }
if (__cleanup)
(*__cleanup)();
_exit(status);