Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ld.elf_so really unmap the gap between the text and ...



details:   https://anonhg.NetBSD.org/src/rev/81e13aaaab12
branches:  trunk
changeset: 351986:81e13aaaab12
user:      chs <chs%NetBSD.org@localhost>
date:      Thu Mar 09 00:43:50 2017 +0000

description:
really unmap the gap between the text and data rather than just removing
all access with mprotect().  the latter results in the kernel having to
keep track of that range separately since the permissions are different.
avoid calling mmap() with a size of zero.

diffstat:

 libexec/ld.elf_so/map_object.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (60 lines):

diff -r 92f870a43fd4 -r 81e13aaaab12 libexec/ld.elf_so/map_object.c
--- a/libexec/ld.elf_so/map_object.c    Thu Mar 09 00:21:55 2017 +0000
+++ b/libexec/ld.elf_so/map_object.c    Thu Mar 09 00:43:50 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: map_object.c,v 1.55 2016/06/16 11:34:13 christos Exp $  */
+/*     $NetBSD: map_object.c,v 1.56 2017/03/09 00:43:50 chs Exp $       */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.55 2016/06/16 11:34:13 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.56 2017/03/09 00:43:50 chs Exp $");
 #endif /* not lint */
 
 #include <errno.h>
@@ -88,8 +88,10 @@
        Elf_Off          data_offset;
        Elf_Addr         data_vaddr;
        Elf_Addr         data_vlimit;
+       size_t           data_size;
        int              data_flags;
        caddr_t          data_addr;
+       size_t           bss_size;
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
        Elf_Addr         tls_vaddr = 0; /* Noise GCC */
 #endif
@@ -361,7 +363,8 @@
 
        /* Overlay the data segment onto the proper region. */
        data_addr = mapbase + (data_vaddr - base_vaddr);
-       if (mmap(data_addr, data_vlimit - data_vaddr, data_flags,
+       data_size = data_vlimit - data_vaddr;
+       if (data_size != 0 && mmap(data_addr, data_size, data_flags,
            MAP_FILE | MAP_PRIVATE | MAP_FIXED, fd, data_offset) ==
            MAP_FAILED) {
                _rtld_error("mmap of data failed: %s", xstrerror(errno));
@@ -369,7 +372,8 @@
        }
 
        /* Overlay the bss segment onto the proper region. */
-       if (mmap(mapbase + data_vlimit - base_vaddr, base_vlimit - data_vlimit,
+       bss_size = base_vlimit - data_vlimit;
+       if (bss_size != 0 && mmap(mapbase + data_vlimit - base_vaddr, bss_size,
            data_flags, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) ==
            MAP_FAILED) {
                _rtld_error("mmap of bss failed: %s", xstrerror(errno));
@@ -379,8 +383,8 @@
        /* Unmap the gap between the text and data. */
        gap_addr = mapbase + round_up(text_vlimit - base_vaddr);
        gap_size = data_addr - gap_addr;
-       if (gap_size != 0 && mprotect(gap_addr, gap_size, PROT_NONE) == -1) {
-               _rtld_error("mprotect of text -> data gap failed: %s",
+       if (gap_size != 0 && munmap(gap_addr, gap_size) == -1) {
+               _rtld_error("munmap of text -> data gap failed: %s",
                    xstrerror(errno));
                goto bad;
        }



Home | Main Index | Thread Index | Old Index