--- - branch: MAIN date: Mon Oct 21 17:07:01 UTC 2019 files: - new: '1.376' old: '1.375' path: src/sys/kern/kern_sig.c pathrev: src/sys/kern/kern_sig.c@1.376 type: modified - new: '1.138' old: '1.137' path: src/tests/lib/libc/sys/t_ptrace_wait.c pathrev: src/tests/lib/libc/sys/t_ptrace_wait.c@1.138 type: modified id: 20191021T170701Z.8a9ea96460e07ba93b261585714b2bae601d82a6 log: | Fix a race condition when handling concurrent LWP signals and add a test Fix a race condition that caused PT_GET_SIGINFO to return incorrect information when multiple signals were delivered concurrently to different LWPs. Add a regression test that verifies that when 50 threads concurrently use pthread_kill() on themselves, the debugger receives all signals with correct information. The kernel uses separate signal queues for each LWP. However, the signal context used to implement PT_GET_SIGINFO is stored in 'struct proc' and therefore common to all LWPs in the process. Previously, this member was filled in kpsignal2(), i.e. when the signal was sent. This meant that if another LWP managed to send another signal concurrently, the data was overwritten before the process was stopped. As a result, PT_GET_SIGINFO did not report the correct LWP and signal (it could even report a different signal than wait()). This can be quite reliably reproduced with the number of 20 LWPs, however it can also occur with 10. This patch moves setting of signal context to issignal(), just before the process is actually stopped. The data is taken from per-LWP or per-process signal queue. The added test confirms that the debugger correctly receives all signals, and PT_GET_SIGINFO reports both correct LWP and signal number. Reviewed by kamil. module: src subject: 'CVS commit: src' unixtime: '1571677621' user: mgorny