public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/18801] New: PIE binary with STT_GNU_IFUNC symbol and TEXTREL segfaults on x86_64
@ 2015-08-10 20:12 tmsriram at google dot com
  2015-08-10 20:12 ` [Bug libc/18801] " tmsriram at google dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: tmsriram at google dot com @ 2015-08-10 20:12 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18801

            Bug ID: 18801
           Summary: PIE binary with STT_GNU_IFUNC symbol and TEXTREL
                    segfaults on x86_64
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: tmsriram at google dot com
                CC: drepper.fsp at gmail dot com, hjl.tools at gmail dot com,
                    ppluzhnikov at google dot com
  Target Milestone: ---

Created attachment 8500
  --> https://sourceware.org/bugzilla/attachment.cgi?id=8500&action=edit
Preserve the original segment's execute permissions when protecting the page
for writing it.

We have a PIE binary with TEXTREL and a STT_GNU_IFUNC symbol that segfaults at
start-up.

How to reproduce the problem:

zoo.cc
-------
int zoo_1 () {
  return 0;
}

extern "C"
void *selector () {
  return (void *)&zoo_1;
}

int zoo() __attribute__ ((ifunc ("selector")));

int main() {
  return zoo ();
}

$ g++ -mcmodel=large -pie foo.cc

$readelf -Wta ./a.out | grep TEXTREL
0x0000000000000016 (TEXTREL)            0x0
0x000000000000001e (FLAGS)              TEXTREL

$ ./a.out
Segmentation Fault

Notes:
* Use mcmodel=large and -pie to create Text relocations.

$ gdb ./a.out
bt

(gdb) bt
#0  0x000055555555476b in selector ()
#1  0x00007ffff7de6638 in _dl_relocate_object () from
/usr/grte/v4/lib64/ld-linux-x86-64.so.2
#2  0x00007ffff7ddc84d in dl_main () from
/usr/grte/v4/lib64/ld-linux-x86-64.so.2


The segfault happens due to this:

 if (__glibc_unlikely (l->l_info[DT_TEXTREL] != NULL)) 
    {
       .....

           if (__mprotect (newp->start, newp->len, PROT_READ|PROT_WRITE) < 0)
             {
               ...
             }

The execute permission of the PT_LOAD segment is removed in the process of
marking for write.  

The attached patch seems to fix the problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-08-11 21:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 20:12 [Bug libc/18801] New: PIE binary with STT_GNU_IFUNC symbol and TEXTREL segfaults on x86_64 tmsriram at google dot com
2015-08-10 20:12 ` [Bug libc/18801] " tmsriram at google dot com
2015-08-10 20:13 ` ppluzhnikov at google dot com
2015-08-10 20:21 ` hjl.tools at gmail dot com
2015-08-11 20:11 ` tmsriram at google dot com
2015-08-11 20:20 ` ppluzhnikov at google dot com
2015-08-11 20:28 ` hjl.tools at gmail dot com
2015-08-11 20:43 ` tmsriram at google dot com
2015-08-11 20:43 ` tmsriram at google dot com
2015-08-11 20:56 ` hjl.tools at gmail dot com
2015-08-11 21:03 ` tmsriram at google dot com
2015-08-11 21:05 ` hjl.tools at gmail dot com

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).