Module Name: src Committed By: mgorny Date: Mon Oct 21 17:07:01 UTC 2019
Modified Files: src/sys/kern: kern_sig.c src/tests/lib/libc/sys: t_ptrace_wait.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.375 -r1.376 src/sys/kern/kern_sig.c cvs rdiff -u -r1.137 -r1.138 src/tests/lib/libc/sys/t_ptrace_wait.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.