emscripten-core / emscripten-core/emscripten
ASan doesn't properly detect stack overflow
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Instead of emitting "AddressSanitizer: stack-overflow on address", ASan in Emscripten produces weird messages like these:
* "ASan is ignoring requested __asan_handle_no_return";
* "AddressSanitizer: nested bug in the same thread, aborting";
* ... or just hangs forever.
Sample program:
```
#include
#include
#include
#include
#include
const int kStackSize = 0x40000;
const int kBufSize = kStackSize * 2;
void* func(void*) {
fprintf(stderr, "Thread started.\n");
char buf[kBufSize];
fprintf(stderr, "Buffer allocated!\n");
memset(buf, 1, kBufSize);
fprintf(stderr, "Buffer written!\n");
fprintf(stderr, "Exiting.\n");
exit(0);
return NULL;
}
int main() {
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, kStackSize);
pthread_t tid;
fprintf(stderr, "Spawning a thread.\n");
pthread_create(&tid, &attr, &func, NULL);
sleep(1);
}
```
Result when running using Emscripten 2.0.26:
```
$ emcc -O0 main-stackoverflow.cc -pthread -s INITIAL_MEMORY=134217728 -g -s PTHREAD_POOL_SIZE=2 -fsanitize=address -s PROXY_TO_PTHREAD && node --experimental-wasm-threads --experimental-wasm-bulk-memory a.out.js
Spawning a thread.
Thread started.
Buffer allocated!
Buffer written!
Exiting.
==42==WARNING: ASan is ignoring requested __asan_handle_no_return: stack type: default top: 0x01010101; bottom 0x04260000; size: 0xfcdb0101 (-52756223)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
Pthread 0x3f03d80 called exit(), posting exitProcess.
```
For comparison, this is the expected result -when same program using stock g++ 10.2.1 or Clang 11:
```
$ g++ -O0 -pthread -fsanitize=address main-stackoverflow.cc && ./a.out
Spawning a thread.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2062640==ERROR: AddressSanitizer: stack-overflow on address 0x7f98c6b2ed78 (pc 0x56428a31d211 bp 0x7f98c6baeeb0 sp 0x7f98c6b2ed70 T1)
#0 0x56428a31d211 in func(void*) (/ssd/smartcard/chromeos_smart_card_connector/emscripten-test/a.out+0x1211)
#1 0x7f98c9a48ea6 in start_thread nptl/pthread_create.c:477
#2 0x7f98c9978dee in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xfddee)
SUMMARY: AddressSanitizer: stack-overflow (/ssd/smartcard/chromeos_smart_card_connector/emscripten-test/a.out+0x1211) in func(void*)
Thread T1 created by T0 here:
#0 0x7f98c9ab72a2 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:214
#1 0x56428a31d4d6 in main (/ssd/smartcard/chromeos_smart_card_connector/emscripten-test/a.out+0x14d6)
#2 0x7f98c98a1d09 in __libc_start_main ../csu/libc-start.c:308
==2062640==ABORTING
```
P.S. In order to repro the hang under Emscripten, change the `* 2` multiplier to `* 10` in the sample program.
Contributor guide
Assessment
This issue has not been assessed yet.