Skip to content

Commit 92c001d

Browse files
committed
ASan: build an uninstrumented version of pthread_join
Reading `t->self` will somehow trigger an heap-use-after-free by ASan.
1 parent 1f6d9d5 commit 92c001d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

system/lib/libc/musl/src/thread/pthread_detach.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
static int __pthread_detach(pthread_t t)
55
{
66
#ifdef __EMSCRIPTEN__ // XXX Emscripten return ESRCH when attempting to detach invalid threads
7-
if (!t || t->self != t) {
8-
return ESRCH;
9-
}
7+
if (!t || t->self != t) return ESRCH;
108
#endif
119
/* If the cas fails, detach state is either already-detached
1210
* or exiting/exited, and pthread_join will trap or cleanup. */

system/lib/libc/musl/src/thread/pthread_join.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ static void dummy1(pthread_t t)
77
}
88
weak_alias(dummy1, __tl_sync);
99

10+
// XXX Emscripten ASan: build an uninstrumented version of pthread_join
11+
#if defined(__EMSCRIPTEN__) && defined(__has_feature)
12+
#if __has_feature(address_sanitizer)
13+
__attribute__((no_sanitize("address")))
14+
#endif
15+
#endif
1016
static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at)
1117
{
1218
#ifdef __EMSCRIPTEN__ // XXX Emscripten return ESRCH when attempting to join invalid threads (see test_pthread_join_6_2)
13-
if (!t || t->self != t) {
14-
return ESRCH;
15-
}
19+
if (!t || t->self != t) return ESRCH;
1620
#endif
1721

1822
int state, cs, r = 0;

0 commit comments

Comments
 (0)