diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2003-02-15 22:39:15 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2003-02-15 22:39:15 +0000 |
commit | 6c34c2c4c127669edb0ec50693e3493ce3c5f154 (patch) | |
tree | 9fa80d528987c0ea03eb3220d5863de82a608201 /libexec/ld.so/powerpc/rtld_machine.c | |
parent | 6cc8ca737f0cac9a74ff9c9ad770326f1dd10663 (diff) |
Paranoia about mprotect, mprotect page aligned regions for got and plt.
Diffstat (limited to 'libexec/ld.so/powerpc/rtld_machine.c')
-rw-r--r-- | libexec/ld.so/powerpc/rtld_machine.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c index 8c5b1e89535..2a040336a6d 100644 --- a/libexec/ld.so/powerpc/rtld_machine.c +++ b/libexec/ld.so/powerpc/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.23 2003/02/15 00:30:16 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.24 2003/02/15 22:39:13 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -448,9 +448,10 @@ _dl_printf(" found other symbol at %x size %d\n", void _dl_md_reloc_got(elf_object_t *object, int lazy) { - Elf32_Addr *pltresolve; - Elf32_Addr *first_rela; - Elf32_Rela *relas; + Elf_Addr *pltresolve; + Elf_Addr *first_rela; + Elf_RelA *relas; + Elf_Addr plt_addr; int numrela; int i; int index; @@ -461,6 +462,8 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) if (object->Dyn.info[DT_PLTREL] != DT_RELA) return; + object->got_addr = NULL; + object->got_size = 0; this = NULL; ooff = _dl_find_symbol("__got_start", object, &this, SYM_SEARCH_SELF|SYM_NOWARNNOTFOUND|SYM_PLT, SYM_NOTPLT, @@ -475,20 +478,38 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) if (this != NULL) object->got_size = ooff + this->st_value - object->got_addr; + plt_addr = 0; + object->plt_size = 0; this = NULL; ooff = _dl_find_symbol("__plt_start", object, &this, SYM_SEARCH_SELF|SYM_NOWARNNOTFOUND|SYM_PLT, SYM_NOTPLT, NULL); if (this != NULL) - object->plt_addr = ooff + this->st_value; + plt_addr = ooff + this->st_value; this = NULL; ooff = _dl_find_symbol("__plt_end", object, &this, SYM_SEARCH_SELF|SYM_NOWARNNOTFOUND|SYM_PLT, SYM_NOTPLT, NULL); if (this != NULL) - object->plt_size = ooff + this->st_value - object->plt_addr; - + object->plt_size = ooff + this->st_value - plt_addr; + + if (object->got_addr == NULL) + object->got_start = NULL; + else { + object->got_start = ELF_TRUNC(object->got_addr, _dl_pagesz); + object->got_size += object->got_addr - object->got_start; + object->got_size = ELF_ROUND(object->got_size, _dl_pagesz); + } + if (plt_addr == NULL) + object->plt_start = NULL; + else { + object->plt_start = ELF_TRUNC(plt_addr, _dl_pagesz); + object->plt_size += plt_addr - object->plt_start; + object->plt_size = ELF_ROUND(object->plt_size, _dl_pagesz); + } + + if (!lazy) { _dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ); return; @@ -518,13 +539,14 @@ _dl_md_reloc_got(elf_object_t *object, int lazy) _dl_dcbf(&r_addr[0]); _dl_dcbf(&r_addr[2]); } - if (object->got_addr != NULL && object->got_size != 0) { - _dl_mprotect((void*)object->got_addr, object->got_size, + if (object->got_size != 0) { + + _dl_mprotect((void*)object->got_start, object->got_size, PROT_READ|PROT_EXEC); /* only PPC is PROT_EXE */ _dl_syncicache((void*)object->got_addr, 4); } - if (object->plt_addr != NULL && object->plt_size != 0) - _dl_mprotect((void*)object->plt_addr, object->plt_size, + if (object->plt_size != 0) + _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_EXEC); } @@ -560,10 +582,10 @@ _dl_bind(elf_object_t *object, int reloff) } /* if PLT is protected, allow the write */ - if (object->plt_addr != NULL && object->plt_size != 0) { + if (object->plt_size != 0) { sigfillset(&nmask); _dl_sigprocmask(SIG_BLOCK, &nmask, &omask); - _dl_mprotect((void*)object->plt_addr, object->plt_size, + _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_WRITE|PROT_EXEC); } @@ -611,8 +633,8 @@ _dl_bind(elf_object_t *object, int reloff) } /* if PLT is (to be protected, change back to RO/X */ - if (object->plt_addr != NULL && object->plt_size != 0) { - _dl_mprotect((void*)object->plt_addr, object->plt_size, + if (object->plt_size != 0) { + _dl_mprotect((void*)object->plt_start, object->plt_size, PROT_READ|PROT_EXEC); /* only PPC is PROT_EXE */ _dl_sigprocmask(SIG_SETMASK, &omask, NULL); } |