diff options
author | dhartmei <> | 2002-07-29 19:54:42 +0000 |
---|---|---|
committer | dhartmei <> | 2002-07-29 19:54:42 +0000 |
commit | 647ec2253a1bdb04c0e60e9d5c78159c7df3fad8 (patch) | |
tree | b733554d99fff8aaa5f020eb86c7307c88904586 /src/lib/libc/stdlib/exit.c | |
parent | 6f9ce38a0a9c5edc0d3984f9c1878e6f227fd210 (diff) | |
download | openbsd-647ec2253a1bdb04c0e60e9d5c78159c7df3fad8.tar.gz openbsd-647ec2253a1bdb04c0e60e9d5c78159c7df3fad8.tar.bz2 openbsd-647ec2253a1bdb04c0e60e9d5c78159c7df3fad8.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 'src/lib/libc/stdlib/exit.c')
-rw-r--r-- | src/lib/libc/stdlib/exit.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c index ab53f9400b..c16b33bd30 100644 --- a/src/lib/libc/stdlib/exit.c +++ b/src/lib/libc/stdlib/exit.c | |||
@@ -32,9 +32,11 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char *rcsid = "$OpenBSD: exit.c,v 1.4 2000/01/06 08:45:50 d Exp $"; | 35 | static char *rcsid = "$OpenBSD: exit.c,v 1.5 2002/07/29 19:54:42 dhartmei Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <sys/types.h> | ||
39 | #include <sys/mman.h> | ||
38 | #include <stdlib.h> | 40 | #include <stdlib.h> |
39 | #include <unistd.h> | 41 | #include <unistd.h> |
40 | #include "atexit.h" | 42 | #include "atexit.h" |
@@ -58,12 +60,19 @@ void | |||
58 | exit(status) | 60 | exit(status) |
59 | int status; | 61 | int status; |
60 | { | 62 | { |
61 | register struct atexit *p; | 63 | register struct atexit *p, *q; |
62 | register int n; | 64 | register int n, pgsize = getpagesize(); |
63 | 65 | ||
64 | for (p = __atexit; p; p = p->next) | 66 | if (!__atexit_invalid) { |
65 | for (n = p->ind; --n >= 0;) | 67 | p = __atexit; |
66 | (*p->fns[n])(); | 68 | while (p != NULL) { |
69 | for (n = p->ind; --n >= 0;) | ||
70 | (*p->fns[n])(); | ||
71 | q = p; | ||
72 | p = p->next; | ||
73 | munmap(q, pgsize); | ||
74 | } | ||
75 | } | ||
67 | if (__cleanup) | 76 | if (__cleanup) |
68 | (*__cleanup)(); | 77 | (*__cleanup)(); |
69 | _exit(status); | 78 | _exit(status); |