public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix has_holes mprotect in dl-load.c
Date: Tue, 06 Jul 2004 20:40:00 -0000	[thread overview]
Message-ID: <20040706182508.GF5191@sunsite.ms.mff.cuni.cz> (raw)

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

             reply	other threads:[~2004-07-06 20:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-06 20:40 Jakub Jelinek [this message]
2004-07-06 22:42 ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040706182508.GF5191@sunsite.ms.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).