This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix has_holes mprotect in dl-load.c


Hi!

l_text_end is not set at this point yet and even if it would,
if first PT_LOAD segment is not executable, it would still be 0.
Doing mprotect (0, up to few MB, PROT_NONE) is bad and
mprotecting l->l_laddr + c->mapend is really what is needed.
Before this patch ld.so did:
strace /lib64/ld-linux-x86-64.so.2 /bin/echo
...
open("/lib64/tls/libc.so.6", O_RDONLY)  = 4
...
mmap(0x3072d00000, 2137672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0x3072d00000
mprotect(0, 970312, PROT_NONE)          = -1 ENOMEM (Cannot allocate memory)
mmap(0x3072f00000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0x200000) = 0x3072f00000
...
mprotect(0x3072f00000, 16384, PROT_READ) = 0
...

for libc.so.6:
readelf -Wl /lib64/tls/libc.so.6 | egrep LOAD\|RELRO
  LOAD           0x000000 0x0000003072d00000 0x0000003072d00000 0x11c72b 0x11c72b R E 0x100000
  LOAD           0x200f30 0x0000003072f00f30 0x0000003072f00f30 0x004ad0 0x008f18 RW  0x100000
  GNU_RELRO      0x200f30 0x0000003072f00f30 0x0000003072f00f30 0x0030d0 0x0030d0 R   0x1
With this patch:
strace elf/ld.so /bin/echo
...
open("/lib64/tls/libc.so.6", O_RDONLY)  = 4
...
mmap(0x3072d00000, 2137672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 4, 0) = 0x3072d00000
mprotect(0x3072e1d000, 970312, PROT_NONE) = 0
mmap(0x3072f00000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 4, 0x200000) = 0x3072f00000
...
mprotect(0x3072f00000, 16384, PROT_READ) = 0
...

2004-07-06  Jakub Jelinek  <jakub@redhat.com>

	* elf/dl-load.c (_dl_map_object_from_fd): If has_holes, mprotect
	l->l_addr + c->mapend instead of l->l_text_end.

--- libc/elf/dl-load.c.jj	2004-05-26 16:04:38.000000000 +0200
+++ libc/elf/dl-load.c	2004-07-06 22:21:04.054995231 +0200
@@ -1117,7 +1117,7 @@ cannot allocate TLS data structures for 
 	     unallocated.  Then jump into the normal segment-mapping loop to
 	     handle the portion of the segment past the end of the file
 	     mapping.  */
-	  __mprotect ((caddr_t) l->l_text_end,
+	  __mprotect ((caddr_t) (l->l_addr + c->mapend),
 		      loadcmds[nloadcmds - 1].allocend - c->mapend,
 		      PROT_NONE);
 

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]