From d23cb5cdfb49313df5a4726a06417274ef34b0c0 Mon Sep 17 00:00:00 2001 From: deraadt Date: Sun, 6 Nov 2022 12:00:20 +0000 Subject: [PATCH] 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. --- libexec/ld.so/loader.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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; -- 2.20.1