From b44bddec975d44d19e71af201374cff9bd96f615 Mon Sep 17 00:00:00 2001 From: Daniel Hartmeier Date: Mon, 29 Jul 2002 19:54:43 +0000 Subject: 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. --- lib/libc/stdlib/exit.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'lib/libc/stdlib/exit.c') 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 +#include #include #include #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); -- cgit v1.2.3