summaryrefslogtreecommitdiff
path: root/libexec/ld.so/loader.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2022-11-06 12:00:21 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2022-11-06 12:00:21 +0000
commitb187a0aed507f7d86e2ecb1db455ede7e489ab53 (patch)
tree3d3fdead2020f15a13310cd88745449142c58aca /libexec/ld.so/loader.c
parent0848b2ba1e3479b6661e32a3471a6202c1321d12 (diff)
TEXTREL binaries are loaded without immutable on un-writeable sections.
After text relocations are finished, these regions (in the binary) can become immutable. OPENBSD_MUTABLE section always overlaps writeable LOADs, so don't be afraid of that case, it's covered.
Diffstat (limited to 'libexec/ld.so/loader.c')
-rw-r--r--libexec/ld.so/loader.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c
index c23ea6d7ad1..1a34127ab81 100644
--- a/libexec/ld.so/loader.c
+++ b/libexec/ld.so/loader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: loader.c,v 1.199 2022/11/06 11:43:19 deraadt Exp $ */
+/* $OpenBSD: loader.c,v 1.200 2022/11/06 12:00:20 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -757,6 +757,18 @@ _dl_rtld(elf_object_t *object)
}
}
+ /*
+ * TEXTREL binaries are loaded without immutable on un-writeable sections.
+ * After text relocations are finished, these regions can become
+ * immutable. OPENBSD_MUTABLE section always overlaps writeable LOADs,
+ * so don't be afraid.
+ */
+ if (object->dyn.textrel) {
+ for (llist = object->load_list; llist != NULL; llist = llist->next)
+ if ((llist->prot & PROT_WRITE) == 0)
+ _dl_mimmutable(llist->start, llist->size);
+ }
+
if (fails == 0)
object->status |= STAT_RELOC_DONE;