Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/sys Enable traceme_raise1 in the...



details:   https://anonhg.NetBSD.org/src/rev/a8cad617a1b9
branches:  trunk
changeset: 318549:a8cad617a1b9
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat Apr 28 19:00:25 2018 +0000
description:
Enable traceme_raise1 in the ATF ptrace(2) tests

This test checks raise(SIGKILL). If we enter the kernel with this signal
we report a signaled child in a debugger, not stopped with an option to
make an action.

FreeBSD behaves differently and allows intercepting this event in a tracer.
Follow the Linux behavior.

If we really want to prevent raise(SIGKILL) from signaling the tracee, we
still can breakpoint raise(3) and alter the syscall arguments (or use
the PT_SYSCALL mode). If we are already in the kernel, SIGKILL always means
killing the process, whether or not traced and the source of SIGKILL.

This tests passes on NetBSD without kernel changes.

Sponsored by <The NetBSD Foundation>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.c |  44 ++++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 16 deletions(-)

diffs (85 lines):

diff -r ea3baa2422b9 -r a8cad617a1b9 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c        Sat Apr 28 18:47:53 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c        Sat Apr 28 19:00:25 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_ptrace_wait.c,v 1.35 2018/04/28 18:07:15 kamil Exp $ */
+/*     $NetBSD: t_ptrace_wait.c,v 1.36 2018/04/28 19:00:25 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.35 2018/04/28 18:07:15 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.36 2018/04/28 19:00:25 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -101,24 +101,36 @@
                DPRINTF("Before raising %s from child\n", strsignal(sigval));
                FORKEE_ASSERT(raise(sigval) == 0);
 
-               DPRINTF("Before exiting of the child process\n");
-               _exit(exitval);
+               switch (sigval) {
+               case SIGKILL:
+                       /* NOTREACHED */
+                       FORKEE_ASSERTX(0 && "This shall not be reached");
+               default:
+                       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 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);
+       switch (sigval) {
+       case SIGKILL:
+               validate_status_signaled(status, sigval, 0);
+               break;
+       default:
+               validate_status_stopped(status, sigval);
+
+               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);
+               break;
+       }
 
        DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
        TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
@@ -138,7 +150,7 @@
        traceme_raise(sig);                                                     \
 }
 
-//TRACEME_RAISE(traceme_raise1, SIGKILL) /* non-maskable */ // not yet
+TRACEME_RAISE(traceme_raise1, SIGKILL) /* non-maskable */
 TRACEME_RAISE(traceme_raise2, SIGSTOP) /* non-maskable */
 TRACEME_RAISE(traceme_raise3, SIGABRT) /* regular abort trap */
 TRACEME_RAISE(traceme_raise4, SIGHUP)  /* hangup */
@@ -6753,7 +6765,7 @@
        setvbuf(stdout, NULL, _IONBF, 0);
        setvbuf(stderr, NULL, _IONBF, 0);
 
-//     ATF_TP_ADD_TC(tp, traceme_raise1); // not yet
+       ATF_TP_ADD_TC(tp, traceme_raise1);
        ATF_TP_ADD_TC(tp, traceme_raise2);
        ATF_TP_ADD_TC(tp, traceme_raise3);
        ATF_TP_ADD_TC(tp, traceme_raise4);



Home | Main Index | Thread Index | Old Index