]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
When a debugger attaches to the process, SIGSTOP is sent to the
authorKonstantin Belousov <kib@FreeBSD.org>
Thu, 28 Jul 2016 08:41:13 +0000 (08:41 +0000)
committerKonstantin Belousov <kib@FreeBSD.org>
Thu, 28 Jul 2016 08:41:13 +0000 (08:41 +0000)
commitb7a25e63b6fc922b197e9daf4c7f545c3560b8fa
treec4b29cade0d6c8efea10cb4873099b53cc681abc
parent7d8ee480c4ffe6892b53873d34f20ddd3d2e7416
When a debugger attaches to the process, SIGSTOP is sent to the
target.  Due to a way issignal() selects the next signal to deliver
and report, if the simultaneous or already pending another signal
exists, that signal might be reported by the next waitpid(2) call.
This causes minor annoyance for debuggers, which must be prepared to
take any signal as the first event, then filter SIGSTOP later.

More importantly, for tools like gcore(1), which attach and then
detach without processing events, SIGSTOP might leak to be delivered
after PT_DETACH.  This results in the process being unintentionally
stopped after detach, which is fatal for automatic tools.

The solution is to force SIGSTOP to be the first signal reported after
the attach.  Attach code is modified to set P2_PTRACE_FSTP to indicate
that the attaching ritual was not yet finished, and issignal() prefers
SIGSTOP in that condition.  Also, the thread which handles
P2_PTRACE_FSTP is made to guarantee to own p_xthread during the first
waitpid(2).  All that ensures that SIGSTOP is consumed first.

Additionally, if P2_PTRACE_FSTP is still set on detach, which means
that waitpid(2) was not called at all, SIGSTOP is removed from the
queue, ensuring that the process is resumed on detach.

In issignal(), when acting on STOPing signals, remove the signal from
queue before suspending.  Otherwise parallel attach could result in
ptracestop() acting on that STOP as if it was the STOP signal from the
attach.  Then SIGSTOP from attach leaks again.

As a minor refactoring, some bits of the common attach code is moved
to new helper proc_set_traced().

Reported by: markj
Reviewed by: jhb, markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D7256
bin/ps/ps.1
sys/kern/kern_exit.c
sys/kern/kern_fork.c
sys/kern/kern_sig.c
sys/kern/sys_process.c
sys/sys/proc.h