summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2003-09-04 19:37:09 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2003-09-04 19:37:09 +0000
commit728366afbd8a31bc70424bf0b64579cdfef0a2a1 (patch)
tree70ef6cf6f9085f1c8fcb25356e371013e4d87d1e
parent29153d4f5d5ce3630a02cc3cf4cf730b0a5ead11 (diff)
Fix W^X mistake. If the dynamic linker is workin in non-lazy mode, it
should still mprotect the GOT and PLT as appropriate. ok deraadt@ miod@
-rw-r--r--libexec/ld.so/alpha/rtld_machine.c37
-rw-r--r--libexec/ld.so/i386/rtld_machine.c41
-rw-r--r--libexec/ld.so/powerpc/rtld_machine.c52
-rw-r--r--libexec/ld.so/sparc/rtld_machine.c3
-rw-r--r--libexec/ld.so/sparc64/rtld_machine.c14
5 files changed, 74 insertions, 73 deletions
diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c
index 5dfd9864f13..67fe783a0f0 100644
--- a/libexec/ld.so/alpha/rtld_machine.c
+++ b/libexec/ld.so/alpha/rtld_machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtld_machine.c,v 1.27 2003/09/04 19:33:49 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.28 2003/09/04 19:37:07 drahn Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -283,25 +283,26 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
if (object->obj_type == OBJTYPE_LDR || !lazy || pltgot == NULL) {
_dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ);
- return;
- }
-
- if (object->obj_type != OBJTYPE_EXE) {
- int i, size;
- Elf_Addr *addr;
- Elf_RelA *rela;
-
- size = object->Dyn.info[DT_PLTRELSZ] / sizeof(Elf_RelA);
- rela = (Elf_RelA *)(object->Dyn.info[DT_JMPREL]);
-
- for (i = 0; i < size; i++) {
- addr = (Elf_Addr *)(object->load_offs + rela[i].r_offset);
- *addr += object->load_offs;
+ } else {
+ if (object->obj_type != OBJTYPE_EXE) {
+ int i, size;
+ Elf_Addr *addr;
+ Elf_RelA *rela;
+
+ size = object->Dyn.info[DT_PLTRELSZ] /
+ sizeof(Elf_RelA);
+ rela = (Elf_RelA *)(object->Dyn.info[DT_JMPREL]);
+
+ for (i = 0; i < size; i++) {
+ addr = (Elf_Addr *)(object->load_offs +
+ rela[i].r_offset);
+ *addr += object->load_offs;
+ }
}
- }
- pltgot[2] = (Elf_Addr)_dl_bind_start;
- pltgot[3] = (Elf_Addr)object;
+ pltgot[2] = (Elf_Addr)_dl_bind_start;
+ pltgot[3] = (Elf_Addr)object;
+ }
if (object->got_size != 0)
_dl_mprotect((void*)object->got_addr, object->got_size,
PROT_READ);
diff --git a/libexec/ld.so/i386/rtld_machine.c b/libexec/ld.so/i386/rtld_machine.c
index 326321ef763..743678d09ae 100644
--- a/libexec/ld.so/i386/rtld_machine.c
+++ b/libexec/ld.so/i386/rtld_machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtld_machine.c,v 1.12 2003/09/04 19:33:49 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.13 2003/09/04 19:37:07 drahn Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
@@ -438,27 +438,28 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
if (!lazy) {
_dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ);
- return;
- }
+ } else {
+ rel = (Elf_Rel *)(object->Dyn.info[DT_JMPREL]);
+ num = (object->Dyn.info[DT_PLTRELSZ]);
+ for (llist = object->load_list; llist != NULL;
+ llist = llist->next) {
+ if (!(llist->prot & PROT_WRITE))
+ _dl_mprotect(llist->start, llist->size,
+ llist->prot|PROT_WRITE);
+ }
+ for (i = 0; i < num/sizeof(Elf_Rel); i++, rel++) {
+ Elf_Addr *where;
+ where = (Elf_Addr *)(rel->r_offset + object->load_offs);
+ *where += object->load_offs;
+ }
+ for (llist = object->load_list; llist != NULL;
+ llist = llist->next) {
+ if (!(llist->prot & PROT_WRITE))
+ _dl_mprotect(llist->start, llist->size,
+ llist->prot);
+ }
- rel = (Elf_Rel *)(object->Dyn.info[DT_JMPREL]);
- num = (object->Dyn.info[DT_PLTRELSZ]);
- for (llist = object->load_list; llist != NULL; llist = llist->next) {
- if (!(llist->prot & PROT_WRITE))
- _dl_mprotect(llist->start, llist->size,
- llist->prot|PROT_WRITE);
}
- for (i = 0; i < num/sizeof(Elf_Rel); i++, rel++) {
- Elf_Addr *where;
- where = (Elf_Addr *)(rel->r_offset + object->load_offs);
- *where += object->load_offs;
- }
- for (llist = object->load_list; llist != NULL; llist = llist->next) {
- if (!(llist->prot & PROT_WRITE))
- _dl_mprotect(llist->start, llist->size,
- llist->prot);
- }
-
/* PLT is already RO on i386, no point in mprotecting it, just GOT */
if (object->got_size != 0)
_dl_mprotect((void*)object->got_start, object->got_size,
diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c
index 3500e888f53..c8aee7ba5db 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.31 2003/09/04 19:33:49 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.32 2003/09/04 19:37:07 drahn Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -511,31 +511,33 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
if (!lazy) {
_dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ);
- return;
- }
- first_rela = (Elf32_Addr *)
- (((Elf32_Rela *)(object->Dyn.info[DT_JMPREL]))->r_offset +
- object->load_offs);
- pltresolve = (Elf32_Addr *)(first_rela) - 18;
-
- relas = (Elf32_Rela *)(object->Dyn.info[DT_JMPREL]);
- numrela = object->Dyn.info[DT_PLTRELSZ] / sizeof(Elf32_Rela);
- r_addr = (Elf32_Addr *)(relas->r_offset + object->load_offs);
-
- for (i = 0, index = 0; i < numrela; i++, r_addr+=2, index++) {
- if (index >= (2 << 12)) {
- /* addis r11,r11,.PLTtable@ha*/
- r_addr[0] = ADDIS_R11_R0 | HA(index*4);
- r_addr[1] = ADDI_R11_R11 | L(index*4);
- BR(r_addr[2], pltresolve);
- /* only every other slot is used after index == 2^14 */
- r_addr += 2;
- } else {
- r_addr[0] = LI_R11 | (index * 4);
- BR(r_addr[1], pltresolve);
+ } else {
+ first_rela = (Elf32_Addr *)
+ (((Elf32_Rela *)(object->Dyn.info[DT_JMPREL]))->r_offset +
+ object->load_offs);
+ pltresolve = (Elf32_Addr *)(first_rela) - 18;
+
+ relas = (Elf32_Rela *)(object->Dyn.info[DT_JMPREL]);
+ numrela = object->Dyn.info[DT_PLTRELSZ] / sizeof(Elf32_Rela);
+ r_addr = (Elf32_Addr *)(relas->r_offset + object->load_offs);
+
+ for (i = 0, index = 0; i < numrela; i++, r_addr+=2, index++) {
+ if (index >= (2 << 12)) {
+ /* addis r11,r0,.PLTtable@ha*/
+ r_addr[0] = ADDIS_R11_R0 | HA(index*4);
+ r_addr[1] = ADDI_R11_R11 | L(index*4);
+ BR(r_addr[2], pltresolve);
+ /* only every other slot is used after
+ * index == 2^14
+ */
+ r_addr += 2;
+ } else {
+ r_addr[0] = LI_R11 | (index * 4);
+ BR(r_addr[1], pltresolve);
+ }
+ _dl_dcbf(&r_addr[0]);
+ _dl_dcbf(&r_addr[2]);
}
- _dl_dcbf(&r_addr[0]);
- _dl_dcbf(&r_addr[2]);
}
if (object->got_size != 0) {
diff --git a/libexec/ld.so/sparc/rtld_machine.c b/libexec/ld.so/sparc/rtld_machine.c
index 3ec0a6705df..69331213591 100644
--- a/libexec/ld.so/sparc/rtld_machine.c
+++ b/libexec/ld.so/sparc/rtld_machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtld_machine.c,v 1.19 2003/09/04 19:33:49 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.20 2003/09/04 19:37:08 drahn Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -455,7 +455,6 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
if (object->obj_type == OBJTYPE_LDR || !lazy || pltgot == NULL) {
_dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ);
- return;
}
if (object->got_size != 0)
diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c
index 9e4fa21efed..e2d6e6a183a 100644
--- a/libexec/ld.so/sparc64/rtld_machine.c
+++ b/libexec/ld.so/sparc64/rtld_machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtld_machine.c,v 1.30 2003/09/04 19:33:50 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.31 2003/09/04 19:37:08 drahn Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -748,14 +748,12 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
if (!lazy) {
_dl_md_reloc(object, DT_JMPREL, DT_PLTRELSZ);
- return;
- }
-
- _dl_install_plt(&entry[0], (Elf_Addr)&_dl_bind_start_0);
- _dl_install_plt(&entry[8], (Elf_Addr)&_dl_bind_start_1);
-
- pltgot[8] = (Elf_Addr)object;
+ } else {
+ _dl_install_plt(&entry[0], (Elf_Addr)&_dl_bind_start_0);
+ _dl_install_plt(&entry[8], (Elf_Addr)&_dl_bind_start_1);
+ pltgot[8] = (Elf_Addr)object;
+ }
if (object->got_size != 0)
_dl_mprotect((void*)object->got_addr, object->got_size,
PROT_READ);