diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2022-10-07 15:04:53 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2022-10-07 15:04:53 +0000 |
commit | d84b2f71567c468b7f2769f79a0af1327195910f (patch) | |
tree | b6fad20e138e250832697afebcdb3a36fc9231f3 /gnu/usr.bin/binutils-2.17 | |
parent | c7304b2b8d4c6bb3e2222fa3795e3ffd2c0eb2f3 (diff) |
In the linkers, collect objects in section "openbsd.mutable" and place
them into a page-aligned region in the bss, with the right markers for
kernel/ld.so to identify the region and skip making it immutable.
While here, fix readelf/objdump versions to show all of this.
ok miod kettenis
Diffstat (limited to 'gnu/usr.bin/binutils-2.17')
-rw-r--r-- | gnu/usr.bin/binutils-2.17/bfd/elf.c | 30 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/binutils/readelf.c | 2 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/include/elf/common.h | 1 | ||||
-rw-r--r-- | gnu/usr.bin/binutils-2.17/ld/ldgram.y | 2 |
4 files changed, 34 insertions, 1 deletions
diff --git a/gnu/usr.bin/binutils-2.17/bfd/elf.c b/gnu/usr.bin/binutils-2.17/bfd/elf.c index f8658be09fe..2d2ed030eca 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/elf.c +++ b/gnu/usr.bin/binutils-2.17/bfd/elf.c @@ -1103,6 +1103,7 @@ get_segment_type (unsigned int p_type) case PT_OPENBSD_RANDOMIZE: pt = "OPENBSD_RANDOMIZE"; break; case PT_OPENBSD_WXNEEDED: pt = "OPENBSD_WXNEEDED"; break; case PT_OPENBSD_BOOTDATA: pt = "OPENBSD_BOOTDATA"; break; + case PT_OPENBSD_MUTABLE: pt = "OPENBSD_MUTABLE"; break; default: pt = NULL; break; } return pt; @@ -2645,6 +2646,9 @@ bfd_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int index) return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "openbsd_wxneeded"); + case PT_OPENBSD_MUTABLE: + return _bfd_elf_make_section_from_phdr (abfd, hdr, index, + "openbsd_mutable"); default: /* Check for any processor-specific program segment types. */ bed = get_elf_backend_data (abfd); @@ -3649,7 +3653,7 @@ map_sections_to_segments (bfd *abfd) bfd_boolean writable; int tls_count = 0; asection *first_tls = NULL; - asection *dynsec, *eh_frame_hdr, *randomdata; + asection *dynsec, *eh_frame_hdr, *randomdata, *mutabledata; bfd_size_type amt; if (elf_tdata (abfd)->segment_map != NULL) @@ -4002,6 +4006,24 @@ map_sections_to_segments (bfd *abfd) pm = &m->next; } + /* If there is a .openbsd.mutable section, throw in a PT_OPENBSD_MUTABLE + segment. */ + mutabledata = bfd_get_section_by_name (abfd, ".openbsd.mutable"); + if (mutabledata != NULL && (mutabledata->flags & SEC_LOAD) != 0) + { + amt = sizeof (struct elf_segment_map); + m = bfd_zalloc (abfd, amt); + if (m == NULL) + goto error_return; + m->next = NULL; + m->p_type = PT_OPENBSD_MUTABLE; + m->count = 1; + m->sections[0] = mutabledata->output_section; + + *pm = m; + pm = &m->next; + } + if (elf_tdata (abfd)->relro) { amt = sizeof (struct elf_segment_map); @@ -4747,6 +4769,12 @@ get_program_header_size (bfd *abfd) ++segs; } + if (bfd_get_section_by_name (abfd, ".openbsd.mutable") != NULL) + { + /* We need a PT_OPENBSD_MUTABLE segment. */ + ++segs; + } + if (elf_tdata (abfd)->eh_frame_hdr) { /* We need a PT_GNU_EH_FRAME segment. */ diff --git a/gnu/usr.bin/binutils-2.17/binutils/readelf.c b/gnu/usr.bin/binutils-2.17/binutils/readelf.c index 716b2768e2e..d0f16f3b6dd 100644 --- a/gnu/usr.bin/binutils-2.17/binutils/readelf.c +++ b/gnu/usr.bin/binutils-2.17/binutils/readelf.c @@ -2708,6 +2708,8 @@ get_segment_type (unsigned long p_type) return "OPENBSD_WXNEEDED"; case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA"; + case PT_OPENBSD_MUTABLE: + return "OPENBSD_MUTABLE"; default: if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) diff --git a/gnu/usr.bin/binutils-2.17/include/elf/common.h b/gnu/usr.bin/binutils-2.17/include/elf/common.h index 1e535ef0b2d..8ceb3d21d45 100644 --- a/gnu/usr.bin/binutils-2.17/include/elf/common.h +++ b/gnu/usr.bin/binutils-2.17/include/elf/common.h @@ -313,6 +313,7 @@ #define PT_OPENBSD_RANDOMIZE 0x65a3dbe6 /* Fill with random data. */ #define PT_OPENBSD_WXNEEDED 0x65a3dbe7 /* Program does W^X violations */ #define PT_OPENBSD_BOOTDATA 0x65a41be6 /* Section for boot arguments */ +#define PT_OPENBSD_MUTABLE 0x65a3dbe5 /* Section for boot arguments */ /* Program segment permissions, in program header p_flags field. */ diff --git a/gnu/usr.bin/binutils-2.17/ld/ldgram.y b/gnu/usr.bin/binutils-2.17/ld/ldgram.y index 33ccd4d60f5..86924249835 100644 --- a/gnu/usr.bin/binutils-2.17/ld/ldgram.y +++ b/gnu/usr.bin/binutils-2.17/ld/ldgram.y @@ -1097,6 +1097,8 @@ phdr_type: $$ = exp_intop (0x65a3dbe7); else if (strcmp (s, "PT_OPENBSD_BOOTDATA") == 0) $$ = exp_intop (0x65a41be6); + else if (strcmp (s, "PT_OPENBSD_MUTABLE") == 0) + $$ = exp_intop (0x65a3dbe5); else { einfo (_("\ |