public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kumpera at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug nptl/12416] New: Dynamic linker incorrectly reduces the stack size when making it executable
Date: Wed, 19 Jan 2011 18:29:00 -0000	[thread overview]
Message-ID: <bug-12416-131@http.sourceware.org/bugzilla/> (raw)

http://sourceware.org/bugzilla/show_bug.cgi?id=12416

           Summary: Dynamic linker incorrectly reduces the stack size when
                    making it executable
           Product: glibc
           Version: 2.11
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: kumpera@gmail.com


If one dlopen a DSO that is not annotated with non executable stack, the
dynamic linker will have to make all stacks executables and when doing so for
the main thread it sometimes unmap a few pages from the botton of the stack.

This is on amd64 linux with kernel 2.6.34.7 and glibc 2.11.2.

Using the following program one can notice this happening:

#include <stdio.h>
#include <dlfcn.h>
#include <string.h>

size_t proc_self () {
    FILE *proc = fopen ("/proc/self/maps", "r");
    char *l = NULL;
    size_t size, stack_ptr;
    stack_ptr = (size_t)&size;
    while (getline (&l, &size, proc) != -1) {
        size_t start, end;
        sscanf (l, "%lx-%lx", &start, &end);
        if (strstr (l, "[stack]")){
            printf ("found stack: %s", l);
            return end;
        }
    }
    return 0;

}

void main (int argc, char *argv[]) {
    size_t r = proc_self ();
    void *handle = dlopen (argc [1], RTLD_LAZY);
    printf ("handle is %p\n", handle);
    size_t r2 = proc_self ();

    if (r != r2)
        printf ("KILLED %lx bytes\n", r - r2);
}



To see this behavior any DSO with execstack set must be used.
The output will be something like:

found stack: 7fff831a9000-7fff831ca000 rw-p 00000000 00:00 0                   
      [stack]
found stack: 7fff831a9000-7fff831c9000 rwxp 00000000 00:00 0                   
      [stack]
KILLED 1000 bytes


As you can see a one page has been unmapped from the bottom of the stack and
this does affect programs that expect the stack bounds to be sane. This makes
pthread_getattr_np return value be unreliable in face of dynamic loading.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


             reply	other threads:[~2011-01-19 17:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19 18:29 kumpera at gmail dot com [this message]
2011-01-19 18:53 ` [Bug nptl/12416] " drepper.fsp at gmail dot com
2011-01-19 19:25 ` roland at gnu dot org
2011-01-19 20:35 ` kumpera at gmail dot com
2012-05-26  4:32 ` siddhesh at redhat dot com
2012-05-26 15:31 ` kumpera at gmail dot com
2012-05-28  5:27 ` siddhesh at redhat dot com
2012-10-03 18:18 ` siddhesh at redhat dot com
2014-06-27 14:03 ` fweimer at redhat dot com

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=bug-12416-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).