* [PATCH] Fix has_holes mprotect in dl-load.c
@ 2004-07-06 20:40 Jakub Jelinek
2004-07-06 22:42 ` Andreas Schwab
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-07-06 20:40 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix has_holes mprotect in dl-load.c
2004-07-06 20:40 [PATCH] Fix has_holes mprotect in dl-load.c Jakub Jelinek
@ 2004-07-06 22:42 ` Andreas Schwab
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2004-07-06 22:42 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers
Jakub Jelinek <jakub@redhat.com> writes:
> 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.
See <http://sources.redhat.com/ml/libc-hacker/2004-05/msg00033.html>.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-07-06 22:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-06 20:40 [PATCH] Fix has_holes mprotect in dl-load.c Jakub Jelinek
2004-07-06 22:42 ` Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).