summaryrefslogtreecommitdiff
path: root/libexec/ld.so/loader.c
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2003-02-15 22:43:07 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2003-02-15 22:43:07 +0000
commit4a0dddfd01348e3c2a7f9b347673233797e055d7 (patch)
tree048606d86c48e9f44cc3f7e00a71e609ae221b49 /libexec/ld.so/loader.c
parent6c34c2c4c127669edb0ec50693e3493ce3c5f154 (diff)
After relocation is completed, remove write protection from GOT/PLT in ld.so.
Diffstat (limited to 'libexec/ld.so/loader.c')
-rw-r--r--libexec/ld.so/loader.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c
index 7be6c73e70d..04587cb007f 100644
--- a/libexec/ld.so/loader.c
+++ b/libexec/ld.so/loader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: loader.c,v 1.54 2003/02/02 16:57:58 deraadt Exp $ */
+/* $OpenBSD: loader.c,v 1.55 2003/02/15 22:43:06 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -173,6 +173,33 @@ _dl_boot(const char **argv, char **envp, const long loff, long *dl_data)
else
_dl_pagesz = 4096;
+ /*
+ * now that GOT and PLT has been relocated, and we know page size
+ * protect it from modification
+ */
+ {
+ extern char *__got_start;
+ extern char *__got_end;
+#ifndef __i386__
+ extern char *__plt_start;
+ extern char *__plt_end;
+#endif
+
+ _dl_mprotect((void *)ELF_TRUNC((long)&__got_start, _dl_pagesz),
+ ELF_ROUND((long)&__got_end,_dl_pagesz) -
+ ELF_TRUNC((long)&__got_start, _dl_pagesz),
+ GOT_PERMS);
+
+#ifndef __i386__
+ /* only for DATA_PLT or BSS_PLT */
+ _dl_mprotect((void *)ELF_TRUNC((long)&__plt_start, _dl_pagesz),
+ ELF_ROUND((long)&__plt_end,_dl_pagesz) -
+ ELF_TRUNC((long)&__plt_start, _dl_pagesz),
+ PROT_READ|PROT_EXEC);
+#endif
+ }
+
+
DL_DEB(("rtld loading: '%s'\n", _dl_progname));
exe_obj = NULL;