Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Remove PT_GET_SIGMASK / PT_SET_SIGMASK



details:   https://anonhg.NetBSD.org/src/rev/c1313744bd00
branches:  trunk
changeset: 830352:c1313744bd00
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Mar 05 11:24:34 2018 +0000

description:
Remove PT_GET_SIGMASK / PT_SET_SIGMASK

These operations cloned Linux's specific PTRACE_GETSIGMASK / PTRACE_SETSIGMASK.
This feature was useful in applications like rr/criu/reptyr-like, where
the ptrace(2) interface is abused for the purpose of constructing an arbitrary
process. It's not reliable and not portable. For the NetBSD case it will be
better to invent something dedicated for serializing and deserializing a
process with threads.

Noted on tech-toolchain@ and blog entry

"LLDB restoration and return to ptrace(2)"
https://blog.netbsd.org/tnf/entry/lldb_restoration_and_return_to

diffstat:

 doc/CHANGES.prev                   |    5 +-
 lib/libc/sys/ptrace.2              |   27 +-
 sys/kern/sys_ptrace_common.c       |   31 +--
 sys/sys/ptrace.h                   |   14 +-
 tests/lib/libc/sys/t_ptrace_wait.c |  500 +------------------------------------
 5 files changed, 11 insertions(+), 566 deletions(-)

diffs (truncated from 700 to 300 lines):

diff -r cfebd3182e4e -r c1313744bd00 doc/CHANGES.prev
--- a/doc/CHANGES.prev  Mon Mar 05 10:54:05 2018 +0000
+++ b/doc/CHANGES.prev  Mon Mar 05 11:24:34 2018 +0000
@@ -1,4 +1,4 @@
-LIST OF CHANGES FROM PREVIOUS RELEASES:                        <$Revision: 1.137 $>
+LIST OF CHANGES FROM PREVIOUS RELEASES:                        <$Revision: 1.138 $>
 
 
 Changes from 386bsd 0.1 + patchkit 0.2.2 to NetBSD 0.8:
@@ -12169,8 +12169,6 @@
        bpf(4): Make it MP-safe [ozaki-r 20170209]
        file(1): Upgraded to 5.30. [christos 20170210]
        byacc: update to 20170201 [christos 20170211]
-       ptrace(2): Add signal mask information accessors API:
-               PT_GET_SIGMASK and PT_SET_SIGMASK [kamil 20170212]
        postfix(1): Import version 3.1.4. [christos 20170213]
        l2tp(4): Add L2TPv3 interface. [knakahara 20170216]
        siginfo(2): Add new si_code for SIGTRAP: TRAP_DBREG [kamil 20170217]
@@ -12228,4 +12226,3 @@
        opencrypto(9): Complete MP-ification [knakahara 20170731]
        ipsec(4): Make it MP-safe [ozaki-r 20170809]
        evbmips: Merge sbmips port into evbmips. [mrg 20170815]
-
diff -r cfebd3182e4e -r c1313744bd00 lib/libc/sys/ptrace.2
--- a/lib/libc/sys/ptrace.2     Mon Mar 05 10:54:05 2018 +0000
+++ b/lib/libc/sys/ptrace.2     Mon Mar 05 11:24:34 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ptrace.2,v 1.67 2017/06/03 19:41:14 abhinav Exp $
+.\"    $NetBSD: ptrace.2,v 1.68 2018/03/05 11:24:35 kamil Exp $
 .\"
 .\" This file is in the public domain.
 .Dd April 7, 2017
@@ -561,31 +561,6 @@
 .Fa data
 argument should be set to
 .Li sizeof(struct ptrace_siginfo) .
-.It Dv PT_SET_SIGMASK
-This request loads the traced process' signal mask from
-.Dq Li "sigset_t"
-(defined in
-.In sys/sigtypes.h )
-pointed to by
-.Fa addr .
-The
-.Fa data
-argument contains the LWP ID of the thread whose registers are to
-be written.
-If zero is supplied, the first thread of the process is written.
-.It Dv PT_GET_SIGMASK
-This request is the converse of
-.Dv PT_SET_SIGMASK ;
-it reads the traced process' signal mask into
-.Dq Li "sigset_t"
-(defined in
-.In sys/sigtypes.h )
-pointed to by
-.Fa addr .
-The
-.Fa data
-argument contains the LWP ID of the thread whose mask is to be read.
-If zero is supplied, the first thread of the process is read.
 .It Dv PT_RESUME
 Allow execution of a specified thread,
 change its state from suspended to continued.
diff -r cfebd3182e4e -r c1313744bd00 sys/kern/sys_ptrace_common.c
--- a/sys/kern/sys_ptrace_common.c      Mon Mar 05 10:54:05 2018 +0000
+++ b/sys/kern/sys_ptrace_common.c      Mon Mar 05 11:24:34 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_ptrace_common.c,v 1.34 2018/01/08 06:10:30 christos Exp $  */
+/*     $NetBSD: sys_ptrace_common.c,v 1.35 2018/03/05 11:24:34 kamil Exp $     */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.34 2018/01/08 06:10:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.35 2018/03/05 11:24:34 kamil Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -249,8 +249,6 @@
        case PT_GET_PROCESS_STATE:
        case PT_SET_SIGINFO:
        case PT_GET_SIGINFO:
-       case PT_SET_SIGMASK:
-       case PT_GET_SIGMASK:
 #ifdef __HAVE_PTRACE_MACHDEP
        PTRACE_MACHDEP_REQUEST_CASES
 #endif
@@ -411,8 +409,6 @@
        case PT_IO:
        case PT_SET_SIGINFO:
        case PT_GET_SIGINFO:
-       case PT_SET_SIGMASK:
-       case PT_GET_SIGMASK:
        case_PT_GETREGS
        case_PT_SETREGS
        case_PT_GETFPREGS
@@ -714,24 +710,6 @@
 }
 
 static int
-ptrace_sigmask(struct proc *t, struct lwp **lt, int rq, void *addr, size_t data)
-{
-       int error;
-
-       if ((error = ptrace_update_lwp(t, lt, data)) != 0)
-               return error;
-
-       if (rq == PT_GET_SIGMASK)
-               return copyout(&(*lt)->l_sigmask, addr, sizeof(sigset_t));
-
-       error = copyin(addr, &(*lt)->l_sigmask, sizeof(sigset_t));
-       if (error)
-               return error;
-       sigminusset(&sigcantmask, &(*lt)->l_sigmask);
-       return 0;
-}
-
-static int
 ptrace_startstop(struct proc *t, struct lwp **lt, int rq, void *addr,
     size_t data)
 {
@@ -1290,11 +1268,6 @@
                error = ptrace_get_siginfo(t, ptm, addr, data);
                break;
 
-       case PT_SET_SIGMASK:
-       case PT_GET_SIGMASK:
-               error = ptrace_sigmask(t, &lt, req, addr, data);
-               break;
-
        case PT_RESUME:
        case PT_SUSPEND:
                error = ptrace_startstop(t, &lt, req, addr, data);
diff -r cfebd3182e4e -r c1313744bd00 sys/sys/ptrace.h
--- a/sys/sys/ptrace.h  Mon Mar 05 10:54:05 2018 +0000
+++ b/sys/sys/ptrace.h  Mon Mar 05 11:24:34 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.62 2017/12/17 20:59:28 christos Exp $     */
+/*     $NetBSD: ptrace.h,v 1.63 2018/03/05 11:24:34 kamil Exp $        */
 
 /*-
  * Copyright (c) 1984, 1993
@@ -55,10 +55,8 @@
 #define        PT_GET_PROCESS_STATE    18      /* get process state, defined below */
 #define        PT_SET_SIGINFO          19      /* set signal state, defined below */
 #define        PT_GET_SIGINFO          20      /* get signal state, defined below */
-#define        PT_SET_SIGMASK          21      /* set signal mask */
-#define        PT_GET_SIGMASK          22      /* get signal mask */
-#define        PT_RESUME               23      /* allow execution of the LWP */
-#define        PT_SUSPEND              24      /* prevent execution of the LWP */
+#define        PT_RESUME               21      /* allow execution of the LWP */
+#define        PT_SUSPEND              22      /* prevent execution of the LWP */
 
 #define        PT_FIRSTMACH            32      /* for machine-specific requests */
 #include <machine/ptrace.h>            /* machine-specific requests, if any */
@@ -85,10 +83,8 @@
 /* 18 */    "PT_GET_PROCESS_STATE", \
 /* 19 */    "PT_SET_SIGINFO", \
 /* 20 */    "PT_GET_SIGINFO", \
-/* 21 */    "PT_GET_SIGMASK", \
-/* 22 */    "PT_GET_SIGMASK", \
-/* 23 */    "PT_RESUME", \
-/* 24 */    "PT_SUSPEND",
+/* 21 */    "PT_RESUME", \
+/* 22 */    "PT_SUSPEND",
 
 /* PT_{G,S}EVENT_MASK */
 typedef struct ptrace_event {
diff -r cfebd3182e4e -r c1313744bd00 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Mon Mar 05 10:54:05 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Mon Mar 05 11:24:34 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.22 2017/12/28 18:41:33 christos Exp $      */
+/*     $NetBSD: t_ptrace_wait.c,v 1.23 2018/03/05 11:24:34 kamil Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.22 2017/12/28 18:41:33 christos Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.23 2018/03/05 11:24:34 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -6555,492 +6555,6 @@
        TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
 }
 
-ATF_TC(getsigmask1);
-ATF_TC_HEAD(getsigmask1, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify that plain PT_SET_SIGMASK can be called");
-}
-
-ATF_TC_BODY(getsigmask1, tc)
-{
-       const int exitval = 5;
-       const int sigval = SIGSTOP;
-       pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-       int status;
-#endif
-       sigset_t mask;
-
-       DPRINTF("Before forking process PID=%d\n", getpid());
-       SYSCALL_REQUIRE((child = fork()) != -1);
-       if (child == 0) {
-               DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
-               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-               DPRINTF("Before raising %s from child\n", strsignal(sigval));
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               DPRINTF("Before exiting of the child process\n");
-               _exit(exitval);
-       }
-       DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-       validate_status_stopped(status, sigval);
-
-       DPRINTF("Before calling PT_GET_SIGMASK\n");
-       SYSCALL_REQUIRE(ptrace(PT_GET_SIGMASK, child, &mask, 0) != -1);
-
-       DPRINTF("Before resuming the child process where it left off and "
-           "without signal to be sent\n");
-       SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-       validate_status_exited(status, exitval);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-
-ATF_TC(getsigmask2);
-ATF_TC_HEAD(getsigmask2, tc)
-{
-       atf_tc_set_md_var(tc, "descr",
-           "Verify that PT_SET_SIGMASK reports correct mask from tracee");
-}
-
-ATF_TC_BODY(getsigmask2, tc)
-{
-       const int exitval = 5;
-       const int sigval = SIGSTOP;
-       const int sigmasked = SIGTRAP;
-       pid_t child, wpid;
-#if defined(TWAIT_HAVE_STATUS)
-       int status;
-#endif
-       sigset_t mask;
-       sigset_t expected_mask;
-       ATF_REQUIRE(sigemptyset(&mask) == 0);
-       ATF_REQUIRE(sigemptyset(&expected_mask) == 0);
-       ATF_REQUIRE(sigaddset(&expected_mask, sigmasked) == 0);
-
-       DPRINTF("Before forking process PID=%d\n", getpid());
-       SYSCALL_REQUIRE((child = fork()) != -1);
-       if (child == 0) {
-               DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
-               FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
-               sigaddset(&mask, sigmasked);
-               sigprocmask(SIG_BLOCK, &mask, NULL);
-
-               DPRINTF("Before raising %s from child\n", strsignal(sigval));
-               FORKEE_ASSERT(raise(sigval) == 0);
-
-               DPRINTF("Before exiting of the child process\n");
-               _exit(exitval);
-       }
-       DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
-       TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
-       validate_status_stopped(status, sigval);
-
-       DPRINTF("Before calling PT_GET_SIGMASK\n");
-       SYSCALL_REQUIRE(ptrace(PT_GET_SIGMASK, child, &mask, 0) != -1);
-
-       ATF_REQUIRE(memcmp(&mask, &expected_mask, sizeof(sigset_t)) == 0);
-
-       DPRINTF("Before resuming the child process where it left off and "
-           "without signal to be sent\n");
-       SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
-       DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);



Home | Main Index | Thread Index | Old Index