public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "prince.cse99 at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug nptl/2644] Race condition during unwind code after thread cancellation
Date: Fri, 22 Jul 2011 22:53:00 -0000	[thread overview]
Message-ID: <bug-2644-131-719g26RaWo@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-2644-131@http.sourceware.org/bugzilla/>

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

Abdullah Muzahid <prince.cse99 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |prince.cse99 at gmail dot
                   |                            |com
         Resolution|FIXED                       |

--- Comment #12 from Abdullah Muzahid <prince.cse99 at gmail dot com> 2011-07-22 22:52:50 UTC ---
Hi,
I am a phd student in University of Illinois in CS dept. Recently I have been
working on memory model related bugs in software. I was experimenting with this
bug. And I found out that the bug is not properly fixed. pthread_cancel_init()
uses libgcc_s_getcfa as a flag. To make it work, we need to use 2 barrier - one
before writing into libgcc_s_getcfa and one after reading it in line 40 (just
before returning). The fix puts the first barrier but not the second one. Now
consider the following scenario where Thread 1 in inside pthread_cancel_init
and is actually initializing the pointers. Thread 2 is in _Unwind_Resume, finds
libgcc_s_resume to be NULL and calls the init function.
     Thread 1                                 Thread 2
libgcc_s_resume = resume;      if(__builtin_expect(libgcc_s_getcfa != NULL,1)) 
...                            ...
atomic_write_barrier();
libgcc_s_getcfa = getcfa;      libgcc_s_resume(exc);

Now in Power-PC memory model, it is perfectly valid to execute read operations
to different addresses out of order as long as there is no barrier in between
them. Although thread 2 issues the instructions in order, it is possible that
the second read (i.e. reading of the pointer libgcc_s_resume) will execute
before the first read of libgcc_s_getcfa. This is shown here.

     Thread 1                             Thread 2
                                 libgcc_s_resume(exc);
libgcc_s_resume = resume;
...
atomic_write_barrier();
libgcc_s_getcfa = getcfa;            
                                 if(__builtin_expect(libgcc_s_getcfa !=
NULL,1))

As a result, although the condition of the if statement for thread 2 becomes 
true, it will end up using NULL value for libgcc_s_resume. This will crash the
program. So, you need to put a read_barrier after reading libgcc_s_getcfa in
the if statement (i.e at line 42 before returning from pthread_cancel_init).
This pattern is very similar to double checked locking (DCL) which also
requires 2 barrier to make it work. More on DCL can be found here
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Thanks.
-Abdullah Muzahid
 PhD Student
 CS, UIUC

-- 
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-07-22 22:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-2644-131@http.sourceware.org/bugzilla/>
2011-07-22 22:53 ` prince.cse99 at gmail dot com [this message]
2011-07-23  3:50 ` drepper.fsp at gmail dot com
2014-02-16 16:56 ` jackie.rosen at hushmail dot com
2014-05-28 19:41 ` schwab at sourceware dot org
2006-05-07 13:56 [Bug nptl/2644] New: " batneil at thebatcave dot org dot uk
2006-05-07 14:02 ` [Bug nptl/2644] " batneil at thebatcave dot org dot uk
2006-05-07 14:05 ` batneil at thebatcave dot org dot uk
2006-05-07 14:14 ` batneil at thebatcave dot org dot uk
2006-05-07 17:33 ` drepper at redhat dot com
2006-05-07 18:37 ` batneil at thebatcave dot org dot uk
2006-05-07 22:15 ` batneil at thebatcave dot org dot uk
2006-05-07 22:19 ` batneil at thebatcave dot org dot uk
2006-05-08  1:00 ` drepper at redhat dot com
2006-05-08  9:36 ` batneil at thebatcave dot org dot uk
2006-05-08 11:28 ` jakub at redhat dot com
2006-11-28 10:31 ` jakub 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-2644-131-719g26RaWo@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).