public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "prekgeo at yahoo dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug dynamic-link/29740] New: Race condition between pthread_exit and fork
Date: Tue, 01 Nov 2022 14:12:51 +0000	[thread overview]
Message-ID: <bug-29740-131@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 29740
           Summary: Race condition between pthread_exit and fork
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: dynamic-link
          Assignee: unassigned at sourceware dot org
          Reporter: prekgeo at yahoo dot com
  Target Milestone: ---

Created attachment 14427
  --> https://sourceware.org/bugzilla/attachment.cgi?id=14427&action=edit
glibc patch to add delay in do_lookup_x

I have observed a crash in a Python program that uses threads and fork. Below,
I attach the following:

* a patch for the latest glibc master (commit
b4174c28d21e1672ef3cc15a058558e97b8471c6) that introduces a delay to force the
race condition.
* a minimal C reproduction.

My understanding of the problem is that the following sequence of events takes
place:

parent: main-thread: starts thread-1
parent: thread-1: exits
parent: thread-1: tries to call _Unwind_Find_FDE
parent: thread-1: ld.so loads libgcc_s.so in memory
parent: main-thread: fork()
parent: thread-1: resolves _Unwind_Find_FDE@got.plt
child: main-thread: starts thread-1
child: thread-1: exits
child: thread-1: calls _Unwind_Find_FDE using the unresolved
_Unwind_Find_FDE@got.plt

The child process crashes with a SIGSEGV with the following backtrace:

#0  0x0000000000003230 in ?? ()
#1  0x00007ffff75c2868 in uw_frame_state_for (context=0x7ffff7dcdc70,
fs=0x7ffff7dcdab0) at ../../../src/libgcc/unwind-dw2.c:1263
#2  0x00007ffff75c3a20 in uw_init_context_1 (context=0x7ffff7dcdc70,
outer_cfa=0x7ffff7dcdea0,
    outer_ra=0x7ffff7e64e36 <__GI___pthread_unwind+70>) at
../../../src/libgcc/unwind-dw2.c:1592
#3  0x00007ffff75c431a in _Unwind_ForcedUnwind (exc=0x7ffff7dced30,
stop=stop@entry=0x7ffff7e64ca0 <unwind_stop>,
    stop_argument=0x7ffff7dcdef0) at ../../../src/libgcc/unwind.inc:211
#4  0x00007ffff7e64e36 in __GI___pthread_unwind (buf=<optimized out>) at
unwind.c:130
#5  0x00007ffff7e5ddba in __do_cancel () at ../sysdeps/nptl/pthreadP.h:276
#6  __GI___pthread_exit (value=0x0) at pthread_exit.c:36
#7  0x00007ffff7fbf283 in ?? ()
#8  0x0000000000000000 in ?? ()

0x3230 is the value of _Unwind_Find_FDE@got.plt in the binary:

$ gdb -q /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
(gdb) p '_Unwind_Find_FDE@got.plt'
$1 = (<text from jump slot in .got.plt, no debug info>) 0x3230

I have also a Python reproduction that fails without the forced delay and by
just enabling LD_DEBUG=all (which seems to add the needed delays). Let me know
if it's valuable to attach in this bug.

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

             reply	other threads:[~2022-11-01 14:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-01 14:12 prekgeo at yahoo dot com [this message]
2022-11-01 14:14 ` [Bug dynamic-link/29740] " prekgeo at yahoo dot com
2022-11-01 14:15 ` prekgeo at yahoo dot com
2022-11-01 15:03 ` schwab@linux-m68k.org
2022-11-01 16:38 ` fw at deneb dot enyo.de
2022-11-01 16:50 ` prekgeo at yahoo dot com
2022-11-01 17:01 ` fw at deneb dot enyo.de

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-29740-131@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).