diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2006-10-28 16:06:06 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2006-10-28 16:06:06 +0000 |
commit | 58cc71066429de8fbbe70b20d8fec58b7a0cf210 (patch) | |
tree | 9b4683b9e5da68e5eb0e93717c4ac900aff1af1e /libexec | |
parent | 2274ecbafc5feccc47349e9aa0a163415fae4626 (diff) |
Only mprotect pages during relocation if the library is marked TEXTREL
mips64 version still needs testing.
Diffstat (limited to 'libexec')
-rw-r--r-- | libexec/ld.so/alpha/rtld_machine.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/amd64/rtld_machine.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/i386/rtld_machine.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/powerpc/rtld_machine.c | 31 | ||||
-rw-r--r-- | libexec/ld.so/sparc/rtld_machine.c | 6 | ||||
-rw-r--r-- | libexec/ld.so/sparc64/rtld_machine.c | 6 |
6 files changed, 32 insertions, 29 deletions
diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c index f4fe41643cd..328d9515b19 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.37 2006/08/06 21:45:46 kettenis Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.38 2006/10/28 16:06:05 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -65,7 +65,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) * XXX - we unprotect way to much. only the text can have cow * relocations. */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) { _dl_mprotect(llist->start, llist->size, @@ -152,7 +152,7 @@ resolve_failed: __asm __volatile("imb" : : : "memory"); /* reprotect the unprotected segments */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, diff --git a/libexec/ld.so/amd64/rtld_machine.c b/libexec/ld.so/amd64/rtld_machine.c index f6cefd666ec..fdeaf40a848 100644 --- a/libexec/ld.so/amd64/rtld_machine.c +++ b/libexec/ld.so/amd64/rtld_machine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtld_machine.c,v 1.10 2005/09/22 01:33:08 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.11 2006/10/28 16:06:05 drahn Exp $ */ /* * Copyright (c) 2002,2004 Dale Rahn @@ -187,7 +187,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) /* * unprotect some segments if we need it. */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, @@ -310,7 +310,7 @@ resolve_failed: } /* reprotect the unprotected segments */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, diff --git a/libexec/ld.so/i386/rtld_machine.c b/libexec/ld.so/i386/rtld_machine.c index 6b953bf9f1b..6662056ae20 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.19 2005/09/22 01:33:08 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.20 2006/10/28 16:06:05 drahn Exp $ */ /* * Copyright (c) 2002 Dale Rahn @@ -185,7 +185,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz) /* * unprotect some segments if we need it. */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, @@ -304,7 +304,7 @@ resolve_failed: } /* reprotect the unprotected segments */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c index c97e166efea..dbff78876ce 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.41 2006/05/08 20:37:01 deraadt Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.42 2006/10/28 16:06:05 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -78,7 +78,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) int i; int numrela; int fails = 0; - struct load_list *load_list; + struct load_list *llist; Elf32_Addr loff; Elf32_Rela *relas; /* for jmp table relocations */ @@ -159,12 +159,13 @@ _dl_printf("object relocation size %x, numrela %x\n", * so we can do relocations such as REL24, REL16 etc. After * relocation restore protection. */ - load_list = object->load_list; - while (load_list != NULL) { - if ((load_list->prot & PROT_WRITE) == 0) - _dl_mprotect(load_list->start, load_list->size, - load_list->prot|PROT_WRITE); - load_list = load_list->next; + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { + 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); + } + } } @@ -409,12 +410,14 @@ _dl_printf(" found other symbol at %x size %d\n", _dl_exit(1); } } - load_list = object->load_list; - while (load_list != NULL) { - if ((load_list->prot & PROT_WRITE) == 0) - _dl_mprotect(load_list->start, load_list->size, - load_list->prot); - load_list = load_list->next; + + /* reprotect the unprotected segments */ + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { + for (llist = object->load_list; llist != NULL; llist = llist->next) { + if (!(llist->prot & PROT_WRITE)) + _dl_mprotect(llist->start, llist->size, + llist->prot); + } } return(fails); } diff --git a/libexec/ld.so/sparc/rtld_machine.c b/libexec/ld.so/sparc/rtld_machine.c index 541d5840e01..f14d49a69b1 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.26 2005/09/22 01:33:08 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.27 2006/10/28 16:06:05 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -194,7 +194,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) /* * unprotect some segments if we need it. */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, @@ -294,7 +294,7 @@ resolve_failed: } /* reprotect the unprotected segments */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c index 9d0e03db27b..8d8b12a24b1 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.37 2005/09/22 01:33:09 drahn Exp $ */ +/* $OpenBSD: rtld_machine.c,v 1.38 2006/10/28 16:06:05 drahn Exp $ */ /* * Copyright (c) 1999 Dale Rahn @@ -220,7 +220,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz) /* * unprotect some segments if we need it. */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, @@ -338,7 +338,7 @@ resolve_failed: } /* reprotect the unprotected segments */ - if ((rel == DT_REL || rel == DT_RELA)) { + if ((object->dyn.textrel == 1) && (rel == DT_REL || rel == DT_RELA)) { for (llist = object->load_list; llist != NULL; llist = llist->next) { if (!(llist->prot & PROT_WRITE)) _dl_mprotect(llist->start, llist->size, |