svn commit: r342704 - in stable: 10/sys/kern 10/tests/sys/kern 11/sys/kern 11/tests/sys/kern 12/sys/kern 12/tests/sys/kern
John Baldwin
jhb at FreeBSD.org
Wed Jan 2 19:11:51 UTC 2019
Author: jhb
Date: Wed Jan 2 19:11:49 2019
New Revision: 342704
URL: https://svnweb.freebsd.org/changeset/base/342704
Log:
MFC 341800: Don't report stale signal information in ptrace_lwpinfo.
Once a signal's siginfo was copied to 'td_si' as part of the signal
exchange in issignal(), it was never cleared. This caused future
thread events that are reported as SIGTRAP events without signal
information to report the stale siginfo in 'td_si'. For example, if a
debugger created a new process and used SIGSTOP to stop it after
PT_ATTACH, future system call entry / exit events would set PL_FLAG_SI
with the SIGSTOP siginfo in pl_siginfo. This broke 'catch syscall' in
current versions of gdb as it assumed PL_FLAG_SI with SIGTRAP
indicates a breakpoint or single step trap.
Modified:
stable/12/sys/kern/kern_sig.c
stable/12/tests/sys/kern/ptrace_test.c
Directory Properties:
stable/12/ (props changed)
Changes in other areas also in this revision:
Modified:
stable/10/sys/kern/kern_sig.c
stable/10/tests/sys/kern/ptrace_test.c
stable/11/sys/kern/kern_sig.c
stable/11/tests/sys/kern/ptrace_test.c
Directory Properties:
stable/10/ (props changed)
stable/11/ (props changed)
Modified: stable/12/sys/kern/kern_sig.c
==============================================================================
--- stable/12/sys/kern/kern_sig.c Wed Jan 2 18:35:40 2019 (r342703)
+++ stable/12/sys/kern/kern_sig.c Wed Jan 2 19:11:49 2019 (r342704)
@@ -2847,6 +2847,8 @@ issignal(struct thread *td)
sig = ptracestop(td, sig, &ksi);
mtx_lock(&ps->ps_mtx);
+ td->td_si.si_signo = 0;
+
/*
* Keep looking if the debugger discarded or
* replaced the signal.
Modified: stable/12/tests/sys/kern/ptrace_test.c
==============================================================================
--- stable/12/tests/sys/kern/ptrace_test.c Wed Jan 2 18:35:40 2019 (r342703)
+++ stable/12/tests/sys/kern/ptrace_test.c Wed Jan 2 19:11:49 2019 (r342704)
@@ -3772,6 +3772,78 @@ ATF_TC_BODY(ptrace__PT_CONTINUE_different_thread, tc)
}
#endif
+/*
+ * Verify that PT_LWPINFO doesn't return stale siginfo.
+ */
+ATF_TC_WITHOUT_HEAD(ptrace__PT_LWPINFO_stale_siginfo);
+ATF_TC_BODY(ptrace__PT_LWPINFO_stale_siginfo, tc)
+{
+ struct ptrace_lwpinfo pl;
+ pid_t fpid, wpid;
+ int events, status;
+
+ ATF_REQUIRE((fpid = fork()) != -1);
+ if (fpid == 0) {
+ trace_me();
+ raise(SIGABRT);
+ exit(1);
+ }
+
+ /* The first wait() should report the stop from SIGSTOP. */
+ wpid = waitpid(fpid, &status, 0);
+ ATF_REQUIRE(wpid == fpid);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+
+ ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
+
+ /* The next stop should report the SIGABRT in the child body. */
+ wpid = waitpid(fpid, &status, 0);
+ ATF_REQUIRE(wpid == fpid);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ ATF_REQUIRE(WSTOPSIG(status) == SIGABRT);
+
+ ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
+ ATF_REQUIRE(pl.pl_flags & PL_FLAG_SI);
+ ATF_REQUIRE(pl.pl_siginfo.si_signo == SIGABRT);
+
+ /*
+ * Continue the process ignoring the signal, but enabling
+ * syscall traps.
+ */
+ ATF_REQUIRE(ptrace(PT_SYSCALL, fpid, (caddr_t)1, 0) == 0);
+
+ /*
+ * The next stop should report a system call entry from
+ * exit(). PL_FLAGS_SI should not be set.
+ */
+ wpid = waitpid(fpid, &status, 0);
+ ATF_REQUIRE(wpid == fpid);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
+
+ ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl, sizeof(pl)) != -1);
+ ATF_REQUIRE(pl.pl_flags & PL_FLAG_SCE);
+ ATF_REQUIRE((pl.pl_flags & PL_FLAG_SI) == 0);
+
+ /* Disable syscall tracing and continue the child to let it exit. */
+ ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, fpid, (caddr_t)&events,
+ sizeof(events)) == 0);
+ events &= ~PTRACE_SYSCALL;
+ ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, fpid, (caddr_t)&events,
+ sizeof(events)) == 0);
+ ATF_REQUIRE(ptrace(PT_CONTINUE, fpid, (caddr_t)1, 0) == 0);
+
+ /* The last event should be for the child process's exit. */
+ wpid = waitpid(fpid, &status, 0);
+ ATF_REQUIRE(WIFEXITED(status));
+ ATF_REQUIRE(WEXITSTATUS(status) == 1);
+
+ wpid = wait(&status);
+ ATF_REQUIRE(wpid == -1);
+ ATF_REQUIRE(errno == ECHILD);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -3831,6 +3903,7 @@ ATF_TP_ADD_TCS(tp)
#if defined(HAVE_BREAKPOINT) && defined(SKIP_BREAK)
ATF_TP_ADD_TC(tp, ptrace__PT_CONTINUE_different_thread);
#endif
+ ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo);
return (atf_no_error());
}
More information about the svn-src-stable
mailing list