emscripten-core / emscripten-core/emscripten

Terminating threads with pthread_kill is wildly unsafe

Open
#18,695 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Currently using `pthread_kill` with any signal except `SIGCANCEL` will violently kill the thread by terminating its worker and freeing its pthread struct without running any cleanup. Since worker termination is asynchronous, this can cause UAF bugs if the terminated worker accesses its pthread struct before dying. Further, killing a thread in this manner without running the TSD destructors can leave the program in an inconsistent state and potentially lead to deadlocks.

If we can get away with it, it would be nice if we could avoid supporting violently killing threads at all. If we must have it, perhaps it should be implemented as a variant of async cancellation to at least avoid the UAF bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.