修订版 | ae56f3a633860a984d42dd9a6959e1d5983296e5 (tree) |
---|---|
时间 | 2018-01-16 05:01:39 |
作者 | Guo Ren <ren_guo@c-sk...> |
Commiter | Waldemar Brodkorb |
libpthread/nptl: bugfix malloc segfault in race conditions.
In libc/sysdeps/linux/common/bits/uClibc_pthread.h:
extern void weak_function _pthread_cleanup_push_defer(...)
This *weak_function* declaration will cause nptl/cleanup_defer_compat.c:
strong_alias (...) !!!FAIL!!!, because it include pthreadP.h->pthread.h
->uClibc_pthread.h
That means:
Readelf -s libpthread/nptl/cleanup_defer_compat.o you will get:
18: 00000000 198 FUNC WEAK DEFAULT 1 _pthread_cleanup_push_def
Readelf -s libc/misc/internals/uClibc_main.o you will also get:
32: 00000038 58 FUNC WEAK DEFAULT 1 _pthread_cleanup_push_def
Final: gcc malloc_pthread_test.c -lpthread
The libc/stdlib/malloc-standard/malloc.c:839 (MALLOC_LOCK->
_pthread_cleanup_push_def) will use the one in uClibc_main.o
!!!not in cleanup_defer_compat.o!!!, becasue two cleanup_defer_compat in
libc.a with the same weak declarations and the uClibc_main.o is close
to front.
All of malloc/free will failed in muti-threads' race conditions
probabilistic.
As it happens, uClibc-0.9.33.2 is OK, Becasue:
It's seperated in libpthread.a and libc.a, and the libc.a is the
last lib for ld internal-cmd, and malloc will get right cleanup_defer_compat
from libpthread.a.
This BUG is from 2016-09-24 to now:
>>>
commit 29ff9055c80efe77a7130767a9fcb3ab8c67e8ce
Author: Waldemar Brodkorb <wbx@uclibc-ng.org>
Date: Sat Sep 24 02:55:31 2016 +0200
<<<
Perharps we need carefully check all of the impact about that commit.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
@@ -29,7 +29,7 @@ | ||
29 | 29 | #include <bits/pthreadtypes.h> |
30 | 30 | #include <bits/setjmp.h> |
31 | 31 | #include <bits/wordsize.h> |
32 | -#if defined _LIBC && ( defined IS_IN_libc || defined NOT_IN_libc ) | |
32 | +#if defined _LIBC && ( defined IS_IN_libc || !defined NOT_IN_libc ) | |
33 | 33 | #include <bits/uClibc_pthread.h> |
34 | 34 | #endif |
35 | 35 |