public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "carlos at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/16291] feature request: provide simpler ways to compute stack and tls boundaries
Date: Thu, 16 Jan 2014 15:07:00 -0000	[thread overview]
Message-ID: <bug-16291-131-noPDzxqVns@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-16291-131@http.sourceware.org/bugzilla/>

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

Carlos O'Donell <carlos at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carlos at redhat dot com

--- Comment #13 from Carlos O'Donell <carlos at redhat dot com> ---
(In reply to Kostya Serebryany from comment #0)
> This is both a feature request and a request for a suggestion. 
> We are developing dynamic testing tools like AddressSanitizer and
> ThreadSanitizer
> which are now part of both LLVM and GCC distributions. 
> The tools have a run-time library that needs to compute thread's stack and 
> tls boundaries. Right now it is done with a series of ugly hacks.

This is something I think we can help with by providing implementation
symbols internally that ASAN and other tools can rely upon as part of
an agreement we have with those tools.

> For non-main threads we get the stack boundaries by querying
> pthread_getattr_np and pthread_attr_getstack. This works, 
> but is problematic because pthread_getattr_np calls malloc and we intercept
> malloc. 

OK.

> For the main thread we get the stack boundaries by querying 
> getrlimit, /proc/self/maps, and an address of a local variable because at
> the point when we need the info libpthread might not have initialized
> itself. 

OK.

> Getting TLS boundaries is even more involved. 
> Today we use the glibc's private symbol _dl_get_tls_static_info
> and then subtract a magic constant (size of the glibc's thread descriptor).

That's ugly, and we could do better there.

However, you're only talking about static TLS there.

There is dynamic TLS also that is not within the static tls block.

Do you need information about that? Such information is racy, prone to
change as libraries are loaded and unloaded etc.

> This works for us on a system we are testing (Ubuntu 12.04),
> but this is very fragile and is often broken on older Linux distros. 

Understood.

> Is it possible to compute the stack and tls boundaries more reliably today?

It is possible to compute at least one end of the main thread stack.

It is possible to compute the boundaries of the non-main thread stack easily.

It is also possible to know the boundaries of static tls for all threads.

It is harder to know the boundaries of dynamic tls for all threads, but
potentially possible. The information once you have it though could
immediately become stale (given the dynamic nature).

Perhaps we can start by addressing the first three in a reliable way.

> If not, would it be possible to add some new functions to do that?

Could you suggest an API?

> For every thread (including the main one) we need to know its stack and tls
> boundaries and the functions that compute it for us should not call malloc
> or any other public library functions. For the main thread, these functions
> should
> work reliably very early (in pre_init functions)

Understood.

As I said, if you designed an API for this, we could look at it and say
if it's possible to fill it in from our end?

You also need to think about what security implications there are about
such an API, if any.

Stability of the API, etc.

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


  parent reply	other threads:[~2014-01-16 15:07 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04  4:49 [Bug libc/16291] New: " konstantin.s.serebryany at gmail dot com
2013-12-04  9:19 ` [Bug libc/16291] " bugdal at aerifal dot cx
2013-12-04  9:34 ` konstantin.s.serebryany at gmail dot com
2013-12-04  9:56 ` bugdal at aerifal dot cx
2013-12-04 10:24 ` konstantin.s.serebryany at gmail dot com
2013-12-04 14:35 ` neleai at seznam dot cz
2013-12-04 14:49 ` konstantin.s.serebryany at gmail dot com
2013-12-04 15:46 ` bugdal at aerifal dot cx
2013-12-04 17:20 ` konstantin.s.serebryany at gmail dot com
2013-12-04 17:33 ` bugdal at aerifal dot cx
2013-12-05  3:54 ` konstantin.s.serebryany at gmail dot com
2013-12-11 11:01 ` konstantin.s.serebryany at gmail dot com
2013-12-11 15:14 ` bugdal at aerifal dot cx
2014-01-16 15:07 ` carlos at redhat dot com [this message]
2014-01-22  8:50 ` eugeni.stepanov at gmail dot com
2014-01-22 19:54 ` earthdok at google dot com
2014-01-23 15:45 ` konstantin.s.serebryany at gmail dot com
2014-01-23 15:57 ` konstantin.s.serebryany at gmail dot com
2014-01-23 16:07 ` ppluzhnikov at google dot com
2014-01-24  8:46 ` konstantin.s.serebryany at gmail dot com
2014-01-27  1:28 ` bugdal at aerifal dot cx
2014-01-27  7:16 ` konstantin.s.serebryany at gmail dot com
2014-01-29 10:00 ` konstantin.s.serebryany at gmail dot com
2014-01-29 10:26 ` bugdal at aerifal dot cx
2014-01-29 10:40 ` konstantin.s.serebryany at gmail dot com
2014-01-29 14:25 ` bugdal at aerifal dot cx
2014-01-29 15:23 ` konstantin.s.serebryany at gmail dot com
2014-01-29 18:21 ` bugdal at aerifal dot cx
2014-01-29 18:35 ` konstantin.s.serebryany at gmail dot com
2014-01-29 18:50 ` earthdok at google dot com
2014-01-30  5:10 ` bugdal at aerifal dot cx
2014-01-30  5:13 ` konstantin.s.serebryany at gmail dot com
2014-01-30 19:06 ` earthdok at google dot com
2014-01-30 19:21 ` carlos at redhat dot com
2014-01-30 19:43 ` earthdok at google dot com
2014-01-31  5:05 ` konstantin.s.serebryany at gmail dot com
2014-01-31  5:31 ` carlos at redhat dot com
2014-01-31  5:50 ` konstantin.s.serebryany at gmail dot com
2014-01-31  6:08 ` carlos at redhat dot com
2014-01-31  7:02 ` konstantin.s.serebryany at gmail dot com
2014-01-31  8:57 ` carlos at redhat dot com
2014-01-31 19:00 ` carlos at redhat dot com
2014-01-31 19:23 ` fche at redhat dot com
2014-01-31 19:40 ` bugdal at aerifal dot cx
2014-01-31 20:43 ` carlos at redhat dot com
2014-01-31 22:33 ` earthdok at google dot com
2014-02-03  8:14 ` konstantin.s.serebryany at gmail dot com
2014-02-03  9:11 ` octoploid at yandex dot com
2014-02-03 14:35 ` carlos at redhat dot com
2014-02-03 15:59 ` bugdal at aerifal dot cx
2014-02-04 14:18 ` konstantin.s.serebryany at gmail dot com
2014-02-04 14:30 ` joseph at codesourcery dot com
2014-02-04 18:50 ` bugdal at aerifal dot cx
2014-02-04 19:08 ` konstantin.s.serebryany at gmail dot com
2014-04-04  8:50 ` konstantin.s.serebryany at gmail dot com
2014-04-04 20:43 ` carlos at redhat dot com
2014-04-22 10:24 ` konstantin.s.serebryany at gmail dot com
2014-06-13 11:48 ` 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-16291-131-noPDzxqVns@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /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).