summaryrefslogtreecommitdiff
path: root/bin/ps
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2016-07-28 08:41:13 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2016-07-28 08:41:13 +0000
commitb7a25e63b6fc922b197e9daf4c7f545c3560b8fa (patch)
treec4b29cade0d6c8efea10cb4873099b53cc681abc /bin/ps
parent7d8ee480c4ffe6892b53873d34f20ddd3d2e7416 (diff)
downloadsrc-test2-b7a25e63b6fc922b197e9daf4c7f545c3560b8fa.tar.gz
src-test2-b7a25e63b6fc922b197e9daf4c7f545c3560b8fa.zip
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
Notes
Notes: svn path=/head/; revision=303423
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/ps.13
1 files changed, 2 insertions, 1 deletions
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 3d7c7382cab6..ea094bccbcb1 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -29,7 +29,7 @@
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd December 1, 2015
+.Dd July 28, 2016
.Dt PS 1
.Os
.Sh NAME
@@ -360,6 +360,7 @@ the include file
.It Dv "P2_NOTRACE" Ta No "0x00000002" Ta "No ptrace(2) attach or coredumps"
.It Dv "P2_NOTRACE_EXEC" Ta No "0x00000004" Ta "Keep P2_NOPTRACE on exec(2)"
.It Dv "P2_AST_SU" Ta No "0x00000008" Ta "Handles SU ast for kthreads"
+.It Dv "P2_PTRACE_FSTP" Ta No "0x00000010" Ta "SIGSTOP from PT_ATTACH not yet handled"
.El
.It Cm label
The MAC label of the process.