diff options
author | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-12-01 10:12:32 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2020-12-11 15:04:39 +0000 |
commit | 8b8f616e6a594b91d0afb152384bf2a9f72b7288 (patch) | |
tree | e6794186d9bad40f51692338fedcc902e079259d /sysdeps/aarch64 | |
parent | 72739c79f61989a76b7dd719f34fcfb7b8eadde9 (diff) | |
download | glibc-8b8f616e6a594b91d0afb152384bf2a9f72b7288.tar.gz glibc-8b8f616e6a594b91d0afb152384bf2a9f72b7288.tar.xz glibc-8b8f616e6a594b91d0afb152384bf2a9f72b7288.zip |
aarch64: align address for BTI protection [BZ #26988]
Handle unaligned executable load segments (the bfd linker is not expected to produce such binaries, but other linkers may). Computing the mapping bounds follows _dl_map_object_from_fd more closely now. Fixes bug 26988. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/aarch64')
-rw-r--r-- | sysdeps/aarch64/dl-bti.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c index 56c097210a..779d0fe488 100644 --- a/sysdeps/aarch64/dl-bti.c +++ b/sysdeps/aarch64/dl-bti.c @@ -20,19 +20,22 @@ #include <libintl.h> #include <ldsodefs.h> -static int +static void enable_bti (struct link_map *map, const char *program) { + const size_t pagesz = GLRO(dl_pagesize); const ElfW(Phdr) *phdr; - unsigned prot; for (phdr = map->l_phdr; phdr < &map->l_phdr[map->l_phnum]; ++phdr) if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X)) { - void *start = (void *) (phdr->p_vaddr + map->l_addr); - size_t len = phdr->p_memsz; + size_t vstart = ALIGN_DOWN (phdr->p_vaddr, pagesz); + size_t vend = ALIGN_UP (phdr->p_vaddr + phdr->p_filesz, pagesz); + off_t off = ALIGN_DOWN (phdr->p_offset, pagesz); + void *start = (void *) (vstart + map->l_addr); + size_t len = vend - vstart; - prot = PROT_EXEC | PROT_BTI; + unsigned prot = PROT_EXEC | PROT_BTI; if (phdr->p_flags & PF_R) prot |= PROT_READ; if (phdr->p_flags & PF_W) @@ -48,7 +51,6 @@ enable_bti (struct link_map *map, const char *program) N_("mprotect failed to turn on BTI")); } } - return 0; } /* Enable BTI for L and its dependencies. */ |