Bug 14333 - Fix the race between atexit() and exit()
: Fix the race between atexit() and exit()
Status: NEW
Product: glibc
Classification: Unclassified
Component: libc
: unspecified
: P2 normal
: ---
Assigned To: Not yet assigned to anyone
:
:
:
:
  Show dependency treegraph
 
Reported: 2012-07-06 01:52 UTC by Peng Haitao
Modified: 2012-12-03 23:58 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
The Patch can fix the race betweent atexit() and exit() (6.39 KB, text/plain)
2012-07-06 01:52 UTC, Peng Haitao
Details
The Patch can fix the race betweent atexit() and exit() (8.42 KB, patch)
2012-10-12 02:41 UTC, Peng Haitao
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peng Haitao 2012-07-06 01:52:47 UTC
Created attachment 6511 [details]
The Patch can fix the race betweent atexit() and exit()

exit() uses global variable __exit_funcs indirectly, which are not protected.
It is not safe in multithread circumstance.

When call exit() and atexit() simultaneously in multithread circumstance,
the following case will cause unsafe.
The case has main process A and thread B.

a. thread B call atexit()
b. process A call exit() to traverse the __exit_funcs list
c. thread B call calloc() to create a new entry p, and next to listp:
   p->next = *listp;
d. process A modify listp to cur's next, then free cur:
   *listp = cur->next;
e. thread B modify listp to p:
   *listp = p;
f. when get f, the f is undefined:
   const struct exit_function *const f =
     &cur->fns[--cur->idx];
g. programme may be Segmentation fault
Comment 1 Carlos O'Donell 2012-10-11 14:16:56 UTC
We're seeing failures on hppa in this area while running some of gcc's
testsuite and it looks like a similar issue. John David Anglin is investigating
for me on the gcc side.
Comment 2 Peng Haitao 2012-10-12 02:41:37 UTC
Created attachment 6682 [details]
The Patch can fix the race betweent atexit() and exit()
Comment 3 Siddhesh Poyarekar 2012-10-18 03:09:57 UTC
Please post the patch on libc-alpha.  If you've posted before and not got a
response, then please repost it.
Comment 4 Peng Haitao 2012-10-22 07:52:53 UTC
(In reply to comment #3)
> Please post the patch on libc-alpha.  If you've posted before and not got a
> response, then please repost it.

I have reposted the patch to libc-alpha, please review.
URL: http://sourceware.org/ml/libc-alpha/2012-10/msg00567.html

Thanks.