Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Passed - Unit
No Test Coverage - Build Status
Buildable 80115 Build 76998: arc lint + arc unit
Event Timeline
Well, llm-postcr shows me this, which I believe is what this PR aiming to solve:
This mail was generated by an LLM (claude-opus-5-5, xhigh effort). It may be wrong. Contact Mark Johnston <markj@FreeBSD.org> with any complaints or suggestions.
Please add the following line to the log message of any commit which fixes a bug reported here:
Reported by: llm-postcr
commit d419e4933f7c157756e497fbda17ee2a5fbf5d22
https://cgit.freebsd.org/src/commit/?id=d419e4933f7c157756e497fbda17ee2a5fbf5d22
POSTCR-d419e4933f7c157756e497fbda17ee2a5fbf5d22-1: pre-existing: exit_common() passes mask instead of &set to sigprocmask(SIG_UNBLOCK), so SIGCANCEL stays blocked for a thread cancelled in sigsuspend() while it exits
This bug was not introduced by this commit. It is in lib/libthr/thread/thr_exit.c:246:
SIGEMPTYSET(set); SIGADDSET(set, SIGCANCEL); __sys_sigprocmask(SIG_UNBLOCK, mask, NULL); /* should be &set */
It dates from 02c3c85869f7 ("Add signal handler wrapper…", David Xu, 2010). The code builds set but never uses it.
How it triggers:
- A thread is cancelled while it is blocked in sigsuspend().
- check_cancel() adds SIGCANCEL to ucp->uc_sigmask and sets unblock_sigcancel = 1 (thr_sig.c:377-378). The thread returns from the handler with SIGCANCEL blocked.
- thr_sigsuspend() then calls _thr_cancel_leave(curthread, 1), which calls _pthread_exit(PTHREAD_CANCELED). This happens before thr_sigsuspend() gets to its own unblock at thr_sig.c:700-704.
- exit_common() is entered with mask == NULL, so the SIG_UNBLOCK call does nothing.
Consequences:
- The thread runs its cleanup handlers, the C++ forced unwind, the TSD destructors and the __cxa_thread_atexit destructors with SIGCANCEL blocked.
- If pthread_suspend_np() or pthread_suspend_all_np() targets that thread, suspend_common() waits until the thread reaches exit_thread(), because the cycle wakeup only happens there.
- If one of those handlers or destructors blocks on something the suspending thread holds or will provide later, the suspend deadlocks.
- In the theoretical mask != NULL case, the call would also unblock every signal in *mask right after it was installed. The review notes that, as far as the reviewer can tell, check_cancel() never produces that combination.
Fix: change the call to __sys_sigprocmask(SIG_UNBLOCK, &set, NULL);