t_ptrace_wait.c revision 1.70
1/* $NetBSD: t_ptrace_wait.c,v 1.70 2019/02/03 03:19:28 mrg Exp $ */ 2 3/*- 4 * Copyright (c) 2016 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> 30__RCSID("$NetBSD: t_ptrace_wait.c,v 1.70 2019/02/03 03:19:28 mrg Exp $"); 31 32#include <sys/param.h> 33#include <sys/types.h> 34#include <sys/mman.h> 35#include <sys/ptrace.h> 36#include <sys/resource.h> 37#include <sys/stat.h> 38#include <sys/syscall.h> 39#include <sys/sysctl.h> 40#include <sys/wait.h> 41#include <machine/reg.h> 42#include <elf.h> 43#include <err.h> 44#include <errno.h> 45#include <lwp.h> 46#include <sched.h> 47#include <signal.h> 48#include <stdint.h> 49#include <stdio.h> 50#include <stdlib.h> 51#include <strings.h> 52#include <time.h> 53#include <unistd.h> 54 55#include <atf-c.h> 56 57#include "h_macros.h" 58 59#include "t_ptrace_wait.h" 60#include "msg.h" 61 62#define PARENT_TO_CHILD(info, fds, msg) \ 63 SYSCALL_REQUIRE(msg_write_child(info " to child " # fds, &fds, &msg, \ 64 sizeof(msg)) == 0) 65 66#define CHILD_FROM_PARENT(info, fds, msg) \ 67 FORKEE_ASSERT(msg_read_parent(info " from parent " # fds, &fds, &msg, \ 68 sizeof(msg)) == 0) 69 70#define CHILD_TO_PARENT(info, fds, msg) \ 71 FORKEE_ASSERT(msg_write_parent(info " to parent " # fds, &fds, &msg, \ 72 sizeof(msg)) == 0) 73 74#define PARENT_FROM_CHILD(info, fds, msg) \ 75 SYSCALL_REQUIRE(msg_read_child(info " from parent " # fds, &fds, &msg, \ 76 sizeof(msg)) == 0) 77 78#define SYSCALL_REQUIRE(expr) ATF_REQUIRE_MSG(expr, "%s: %s", # expr, \ 79 strerror(errno)) 80#define SYSCALL_REQUIRE_ERRNO(res, exp) ATF_REQUIRE_MSG(res == exp, \ 81 "%d(%s) != %d", res, strerror(res), exp) 82 83static int debug = 0; 84 85#define DPRINTF(a, ...) do \ 86 if (debug) printf(a, ##__VA_ARGS__); \ 87 while (/*CONSTCOND*/0) 88 89/// ---------------------------------------------------------------------------- 90 91static void 92traceme_raise(int sigval) 93{ 94 const int exitval = 5; 95 pid_t child, wpid; 96#if defined(TWAIT_HAVE_STATUS) 97 int status; 98#endif 99 100 struct ptrace_siginfo info; 101 memset(&info, 0, sizeof(info)); 102 103 DPRINTF("Before forking process PID=%d\n", getpid()); 104 SYSCALL_REQUIRE((child = fork()) != -1); 105 if (child == 0) { 106 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 107 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 108 109 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 110 FORKEE_ASSERT(raise(sigval) == 0); 111 112 switch (sigval) { 113 case SIGKILL: 114 /* NOTREACHED */ 115 FORKEE_ASSERTX(0 && "This shall not be reached"); 116 __unreachable(); 117 default: 118 DPRINTF("Before exiting of the child process\n"); 119 _exit(exitval); 120 } 121 } 122 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 123 124 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 125 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 126 127 switch (sigval) { 128 case SIGKILL: 129 validate_status_signaled(status, sigval, 0); 130 break; 131 default: 132 validate_status_stopped(status, sigval); 133 134 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " 135 "child\n"); 136 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, 137 sizeof(info)) != -1); 138 139 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 140 DPRINTF("Signal properties: si_signo=%#x si_code=%#x " 141 "si_errno=%#x\n", 142 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 143 info.psi_siginfo.si_errno); 144 145 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 146 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 147 148 DPRINTF("Before resuming the child process where it left off " 149 "and without signal to be sent\n"); 150 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 151 152 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 153 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 154 child); 155 break; 156 } 157 158 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 159 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 160} 161 162#define TRACEME_RAISE(test, sig) \ 163ATF_TC(test); \ 164ATF_TC_HEAD(test, tc) \ 165{ \ 166 atf_tc_set_md_var(tc, "descr", \ 167 "Verify " #sig " followed by _exit(2) in a child"); \ 168} \ 169 \ 170ATF_TC_BODY(test, tc) \ 171{ \ 172 \ 173 traceme_raise(sig); \ 174} 175 176TRACEME_RAISE(traceme_raise1, SIGKILL) /* non-maskable */ 177TRACEME_RAISE(traceme_raise2, SIGSTOP) /* non-maskable */ 178TRACEME_RAISE(traceme_raise3, SIGABRT) /* regular abort trap */ 179TRACEME_RAISE(traceme_raise4, SIGHUP) /* hangup */ 180TRACEME_RAISE(traceme_raise5, SIGCONT) /* continued? */ 181 182/// ---------------------------------------------------------------------------- 183 184static void 185traceme_crash(int sig) 186{ 187 pid_t child, wpid; 188#if defined(TWAIT_HAVE_STATUS) 189 int status; 190#endif 191 struct ptrace_siginfo info; 192 193 memset(&info, 0, sizeof(info)); 194 195 DPRINTF("Before forking process PID=%d\n", getpid()); 196 SYSCALL_REQUIRE((child = fork()) != -1); 197 if (child == 0) { 198 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 199 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 200 201 DPRINTF("Before executing a trap\n"); 202 switch (sig) { 203 case SIGTRAP: 204 trigger_trap(); 205 break; 206 case SIGSEGV: 207 trigger_segv(); 208 break; 209 case SIGILL: 210 trigger_ill(); 211 break; 212 case SIGFPE: 213 trigger_fpe(); 214 break; 215 case SIGBUS: 216 trigger_bus(); 217 break; 218 default: 219 /* NOTREACHED */ 220 FORKEE_ASSERTX(0 && "This shall not be reached"); 221 } 222 223 /* NOTREACHED */ 224 FORKEE_ASSERTX(0 && "This shall not be reached"); 225 } 226 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 227 228 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 229 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 230 231 validate_status_stopped(status, sig); 232 233 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child"); 234 SYSCALL_REQUIRE( 235 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 236 237 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 238 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 239 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 240 info.psi_siginfo.si_errno); 241 242 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sig); 243 switch (sig) { 244 case SIGTRAP: 245 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_BRKPT); 246 break; 247 case SIGSEGV: 248 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR); 249 break; 250// case SIGILL: 251// ATF_REQUIRE_EQ(info.psi_siginfo.si_code, ILL_ILLOP); 252// break; 253 case SIGFPE: 254 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); 255 break; 256 case SIGBUS: 257 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); 258 break; 259 } 260 261 SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); 262 263 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 264 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 265 266 validate_status_signaled(status, SIGKILL, 0); 267 268 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 269 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 270} 271 272#define TRACEME_CRASH(test, sig) \ 273ATF_TC(test); \ 274ATF_TC_HEAD(test, tc) \ 275{ \ 276 atf_tc_set_md_var(tc, "descr", \ 277 "Verify crash signal " #sig " in a child after PT_TRACE_ME"); \ 278} \ 279 \ 280ATF_TC_BODY(test, tc) \ 281{ \ 282 \ 283 traceme_crash(sig); \ 284} 285 286TRACEME_CRASH(traceme_crash_trap, SIGTRAP) 287TRACEME_CRASH(traceme_crash_segv, SIGSEGV) 288//TRACEME_CRASH(traceme_crash_ill, SIGILL) 289TRACEME_CRASH(traceme_crash_fpe, SIGFPE) 290TRACEME_CRASH(traceme_crash_bus, SIGBUS) 291 292/// ---------------------------------------------------------------------------- 293 294static void 295traceme_sendsignal_handle(int sigsent, void (*sah)(int a), int *traceme_caught) 296{ 297 const int exitval = 5; 298 const int sigval = SIGSTOP; 299 pid_t child, wpid; 300 struct sigaction sa; 301#if defined(TWAIT_HAVE_STATUS) 302 int status; 303#endif 304 struct ptrace_siginfo info; 305 306 memset(&info, 0, sizeof(info)); 307 308 DPRINTF("Before forking process PID=%d\n", getpid()); 309 SYSCALL_REQUIRE((child = fork()) != -1); 310 if (child == 0) { 311 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 312 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 313 314 sa.sa_handler = sah; 315 sa.sa_flags = SA_SIGINFO; 316 sigemptyset(&sa.sa_mask); 317 318 FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1); 319 320 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 321 FORKEE_ASSERT(raise(sigval) == 0); 322 323 FORKEE_ASSERT_EQ(*traceme_caught, 1); 324 325 DPRINTF("Before exiting of the child process\n"); 326 _exit(exitval); 327 } 328 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 329 330 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 331 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 332 333 validate_status_stopped(status, sigval); 334 335 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 336 SYSCALL_REQUIRE( 337 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 338 339 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 340 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 341 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 342 info.psi_siginfo.si_errno); 343 344 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 345 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 346 347 DPRINTF("Before resuming the child process where it left off and with " 348 "signal %s to be sent\n", strsignal(sigsent)); 349 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 350 351 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 352 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 353 354 validate_status_exited(status, exitval); 355 356 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 357 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 358} 359 360#define TRACEME_SENDSIGNAL_HANDLE(test, sig) \ 361ATF_TC(test); \ 362ATF_TC_HEAD(test, tc) \ 363{ \ 364 atf_tc_set_md_var(tc, "descr", \ 365 "Verify that a signal " #sig " emitted by a tracer to a child is " \ 366 "handled correctly and caught by a signal handler"); \ 367} \ 368 \ 369static int test##_caught = 0; \ 370 \ 371static void \ 372test##_sighandler(int arg) \ 373{ \ 374 FORKEE_ASSERT_EQ(arg, sig); \ 375 \ 376 ++ test##_caught; \ 377} \ 378 \ 379ATF_TC_BODY(test, tc) \ 380{ \ 381 \ 382 traceme_sendsignal_handle(sig, test##_sighandler, & test##_caught); \ 383} 384 385// A signal handler for SIGKILL and SIGSTOP cannot be registered. 386TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle1, SIGABRT) /* abort trap */ 387TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle2, SIGHUP) /* hangup */ 388TRACEME_SENDSIGNAL_HANDLE(traceme_sendsignal_handle3, SIGCONT) /* continued? */ 389 390/// ---------------------------------------------------------------------------- 391 392static void 393traceme_sendsignal_masked(int sigsent) 394{ 395 const int exitval = 5; 396 const int sigval = SIGSTOP; 397 pid_t child, wpid; 398 sigset_t set; 399#if defined(TWAIT_HAVE_STATUS) 400 int status; 401#endif 402 struct ptrace_siginfo info; 403 404 memset(&info, 0, sizeof(info)); 405 406 DPRINTF("Before forking process PID=%d\n", getpid()); 407 SYSCALL_REQUIRE((child = fork()) != -1); 408 if (child == 0) { 409 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 410 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 411 412 sigemptyset(&set); 413 sigaddset(&set, sigsent); 414 FORKEE_ASSERT(sigprocmask(SIG_BLOCK, &set, NULL) != -1); 415 416 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 417 FORKEE_ASSERT(raise(sigval) == 0); 418 419 _exit(exitval); 420 } 421 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 422 423 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 424 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 425 426 validate_status_stopped(status, sigval); 427 428 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 429 SYSCALL_REQUIRE( 430 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 431 432 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 433 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 434 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 435 info.psi_siginfo.si_errno); 436 437 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 438 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 439 440 DPRINTF("Before resuming the child process where it left off and with " 441 "signal %s to be sent\n", strsignal(sigsent)); 442 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 443 444 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 445 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 446 447 validate_status_exited(status, exitval); 448 449 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 450 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 451} 452 453#define TRACEME_SENDSIGNAL_MASKED(test, sig) \ 454ATF_TC(test); \ 455ATF_TC_HEAD(test, tc) \ 456{ \ 457 atf_tc_set_md_var(tc, "descr", \ 458 "Verify that a signal " #sig " emitted by a tracer to a child is " \ 459 "handled correctly and the signal is masked by SIG_BLOCK"); \ 460} \ 461 \ 462ATF_TC_BODY(test, tc) \ 463{ \ 464 \ 465 traceme_sendsignal_masked(sig); \ 466} 467 468// A signal handler for SIGKILL and SIGSTOP cannot be masked. 469TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked1, SIGABRT) /* abort trap */ 470TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked2, SIGHUP) /* hangup */ 471TRACEME_SENDSIGNAL_MASKED(traceme_sendsignal_masked3, SIGCONT) /* continued? */ 472 473/// ---------------------------------------------------------------------------- 474 475static void 476traceme_sendsignal_ignored(int sigsent) 477{ 478 const int exitval = 5; 479 const int sigval = SIGSTOP; 480 pid_t child, wpid; 481 struct sigaction sa; 482#if defined(TWAIT_HAVE_STATUS) 483 int status; 484#endif 485 struct ptrace_siginfo info; 486 487 memset(&info, 0, sizeof(info)); 488 489 DPRINTF("Before forking process PID=%d\n", getpid()); 490 SYSCALL_REQUIRE((child = fork()) != -1); 491 if (child == 0) { 492 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 493 494 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 495 496 memset(&sa, 0, sizeof(sa)); 497 sa.sa_handler = SIG_IGN; 498 sigemptyset(&sa.sa_mask); 499 FORKEE_ASSERT(sigaction(sigsent, &sa, NULL) != -1); 500 501 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 502 FORKEE_ASSERT(raise(sigval) == 0); 503 504 _exit(exitval); 505 } 506 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 507 508 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 509 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 510 511 validate_status_stopped(status, sigval); 512 513 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 514 SYSCALL_REQUIRE( 515 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 516 517 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 518 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 519 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 520 info.psi_siginfo.si_errno); 521 522 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 523 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 524 525 DPRINTF("Before resuming the child process where it left off and with " 526 "signal %s to be sent\n", strsignal(sigsent)); 527 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 528 529 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 530 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 531 532 validate_status_exited(status, exitval); 533 534 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 535 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 536} 537 538#define TRACEME_SENDSIGNAL_IGNORED(test, sig) \ 539ATF_TC(test); \ 540ATF_TC_HEAD(test, tc) \ 541{ \ 542 atf_tc_set_md_var(tc, "descr", \ 543 "Verify that a signal " #sig " emitted by a tracer to a child is " \ 544 "handled correctly and the signal is masked by SIG_IGN"); \ 545} \ 546 \ 547ATF_TC_BODY(test, tc) \ 548{ \ 549 \ 550 traceme_sendsignal_ignored(sig); \ 551} 552 553// A signal handler for SIGKILL and SIGSTOP cannot be ignored. 554TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored1, SIGABRT) /* abort */ 555TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored2, SIGHUP) /* hangup */ 556TRACEME_SENDSIGNAL_IGNORED(traceme_sendsignal_ignored3, SIGCONT) /* continued */ 557 558/// ---------------------------------------------------------------------------- 559 560static void 561traceme_sendsignal_simple(int sigsent) 562{ 563 const int sigval = SIGSTOP; 564 int exitval = 0; 565 pid_t child, wpid; 566#if defined(TWAIT_HAVE_STATUS) 567 int status; 568 int expect_core = (sigsent == SIGABRT) ? 1 : 0; 569#endif 570 struct ptrace_siginfo info; 571 572 memset(&info, 0, sizeof(info)); 573 574 DPRINTF("Before forking process PID=%d\n", getpid()); 575 SYSCALL_REQUIRE((child = fork()) != -1); 576 if (child == 0) { 577 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 578 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 579 580 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 581 FORKEE_ASSERT(raise(sigval) == 0); 582 583 switch (sigsent) { 584 case SIGCONT: 585 case SIGSTOP: 586 _exit(exitval); 587 default: 588 /* NOTREACHED */ 589 FORKEE_ASSERTX(0 && "This shall not be reached"); 590 } 591 } 592 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 593 594 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 595 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 596 597 validate_status_stopped(status, sigval); 598 599 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 600 SYSCALL_REQUIRE( 601 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 602 603 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 604 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 605 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 606 info.psi_siginfo.si_errno); 607 608 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 609 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 610 611 DPRINTF("Before resuming the child process where it left off and with " 612 "signal %s to be sent\n", strsignal(sigsent)); 613 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 614 615 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 616 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 617 618 switch (sigsent) { 619 case SIGSTOP: 620 validate_status_stopped(status, sigsent); 621 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for " 622 "child\n"); 623 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, 624 sizeof(info)) != -1); 625 626 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 627 DPRINTF("Signal properties: si_signo=%#x si_code=%#x " 628 "si_errno=%#x\n", 629 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 630 info.psi_siginfo.si_errno); 631 632 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 633 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 634 635 DPRINTF("Before resuming the child process where it left off " 636 "and with signal %s to be sent\n", strsignal(sigsent)); 637 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 638 639 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 640 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 641 child); 642 /* FALLTHROUGH */ 643 case SIGCONT: 644 validate_status_exited(status, exitval); 645 break; 646 default: 647 validate_status_signaled(status, sigsent, expect_core); 648 break; 649 } 650 651 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 652 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 653} 654 655#define TRACEME_SENDSIGNAL_SIMPLE(test, sig) \ 656ATF_TC(test); \ 657ATF_TC_HEAD(test, tc) \ 658{ \ 659 atf_tc_set_md_var(tc, "descr", \ 660 "Verify that a signal " #sig " emitted by a tracer to a child is " \ 661 "handled correctly in a child without a signal handler"); \ 662} \ 663 \ 664ATF_TC_BODY(test, tc) \ 665{ \ 666 \ 667 traceme_sendsignal_simple(sig); \ 668} 669 670TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple1, SIGKILL) /* non-maskable*/ 671TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple2, SIGSTOP) /* non-maskable*/ 672TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple3, SIGABRT) /* abort trap */ 673TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple4, SIGHUP) /* hangup */ 674TRACEME_SENDSIGNAL_SIMPLE(traceme_sendsignal_simple5, SIGCONT) /* continued? */ 675 676/// ---------------------------------------------------------------------------- 677 678ATF_TC(traceme_pid1_parent); 679ATF_TC_HEAD(traceme_pid1_parent, tc) 680{ 681 atf_tc_set_md_var(tc, "descr", 682 "Verify that PT_TRACE_ME is not allowed when our parent is PID1"); 683} 684 685ATF_TC_BODY(traceme_pid1_parent, tc) 686{ 687 struct msg_fds parent_child; 688 int exitval_child1 = 1, exitval_child2 = 2; 689 pid_t child1, child2, wpid; 690 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 691#if defined(TWAIT_HAVE_STATUS) 692 int status; 693#endif 694 695 SYSCALL_REQUIRE(msg_open(&parent_child) == 0); 696 697 DPRINTF("Before forking process PID=%d\n", getpid()); 698 SYSCALL_REQUIRE((child1 = fork()) != -1); 699 if (child1 == 0) { 700 DPRINTF("Before forking process PID=%d\n", getpid()); 701 SYSCALL_REQUIRE((child2 = fork()) != -1); 702 if (child2 != 0) { 703 DPRINTF("Parent process PID=%d, child2's PID=%d\n", 704 getpid(), child2); 705 _exit(exitval_child1); 706 } 707 CHILD_FROM_PARENT("exit child1", parent_child, msg); 708 709 DPRINTF("Assert that our parent is PID1 (initproc)\n"); 710 FORKEE_ASSERT_EQ(getppid(), 1); 711 712 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 713 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) == -1); 714 SYSCALL_REQUIRE_ERRNO(errno, EPERM); 715 716 CHILD_TO_PARENT("child2 exiting", parent_child, msg); 717 718 _exit(exitval_child2); 719 } 720 DPRINTF("Parent process PID=%d, child1's PID=%d\n", getpid(), child1); 721 722 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 723 TWAIT_REQUIRE_SUCCESS( 724 wpid = TWAIT_GENERIC(child1, &status, WEXITED), child1); 725 726 validate_status_exited(status, exitval_child1); 727 728 DPRINTF("Notify that child1 is dead\n"); 729 PARENT_TO_CHILD("exit child1", parent_child, msg); 730 731 DPRINTF("Wait for exiting of child2\n"); 732 PARENT_FROM_CHILD("child2 exiting", parent_child, msg); 733} 734 735/// ---------------------------------------------------------------------------- 736 737static void 738traceme_vfork_raise(int sigval) 739{ 740 const int exitval = 5, exitval_watcher = 10; 741 pid_t child, parent, watcher, wpid; 742 int rv; 743#if defined(TWAIT_HAVE_STATUS) 744 int status; 745 int expect_core = (sigval == SIGABRT) ? 1 : 0; 746#endif 747 748 /* 749 * Spawn a dedicated thread to watch for a stopped child and emit 750 * the SIGKILL signal to it. 751 * 752 * vfork(2) might clobber watcher, this means that it's safer and 753 * simpler to reparent this process to initproc and forget about it. 754 */ 755 if (sigval == SIGSTOP) { 756 parent = getpid(); 757 758 watcher = fork(); 759 ATF_REQUIRE(watcher != 1); 760 if (watcher == 0) { 761 /* Double fork(2) trick to reparent to initproc */ 762 watcher = fork(); 763 FORKEE_ASSERT_NEQ(watcher, -1); 764 if (watcher != 0) 765 _exit(exitval_watcher); 766 767 child = await_stopped_child(parent); 768 769 errno = 0; 770 rv = kill(child, SIGKILL); 771 FORKEE_ASSERT_EQ(rv, 0); 772 FORKEE_ASSERT_EQ(errno, 0); 773 774 /* This exit value will be collected by initproc */ 775 _exit(0); 776 } 777 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 778 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(watcher, &status, 0), 779 watcher); 780 781 validate_status_exited(status, exitval_watcher); 782 783 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 784 TWAIT_REQUIRE_FAILURE(ECHILD, 785 wpid = TWAIT_GENERIC(watcher, &status, 0)); 786 } 787 788 DPRINTF("Before forking process PID=%d\n", getpid()); 789 SYSCALL_REQUIRE((child = vfork()) != -1); 790 if (child == 0) { 791 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 792 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 793 794 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 795 FORKEE_ASSERT(raise(sigval) == 0); 796 797 switch (sigval) { 798 case SIGSTOP: 799 case SIGKILL: 800 case SIGABRT: 801 case SIGHUP: 802 /* NOTREACHED */ 803 FORKEE_ASSERTX(0 && "This shall not be reached"); 804 __unreachable(); 805 default: 806 DPRINTF("Before exiting of the child process\n"); 807 _exit(exitval); 808 } 809 } 810 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 811 812 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 813 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 814 815 switch (sigval) { 816 case SIGKILL: 817 case SIGABRT: 818 case SIGHUP: 819 validate_status_signaled(status, sigval, expect_core); 820 break; 821 case SIGSTOP: 822 validate_status_signaled(status, SIGKILL, 0); 823 break; 824 case SIGCONT: 825 case SIGTSTP: 826 case SIGTTIN: 827 case SIGTTOU: 828 validate_status_exited(status, exitval); 829 break; 830 default: 831 /* NOTREACHED */ 832 ATF_REQUIRE(0 && "NOT IMPLEMENTED"); 833 break; 834 } 835 836 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 837 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 838} 839 840#define TRACEME_VFORK_RAISE(test, sig) \ 841ATF_TC(test); \ 842ATF_TC_HEAD(test, tc) \ 843{ \ 844 atf_tc_set_md_var(tc, "descr", \ 845 "Verify PT_TRACE_ME followed by raise of " #sig " in a " \ 846 "vfork(2)ed child"); \ 847} \ 848 \ 849ATF_TC_BODY(test, tc) \ 850{ \ 851 \ 852 traceme_vfork_raise(sig); \ 853} 854 855TRACEME_VFORK_RAISE(traceme_vfork_raise1, SIGKILL) /* non-maskable */ 856TRACEME_VFORK_RAISE(traceme_vfork_raise2, SIGSTOP) /* non-maskable */ 857TRACEME_VFORK_RAISE(traceme_vfork_raise3, SIGTSTP) /* ignored in vfork(2) */ 858TRACEME_VFORK_RAISE(traceme_vfork_raise4, SIGTTIN) /* ignored in vfork(2) */ 859TRACEME_VFORK_RAISE(traceme_vfork_raise5, SIGTTOU) /* ignored in vfork(2) */ 860TRACEME_VFORK_RAISE(traceme_vfork_raise6, SIGABRT) /* regular abort trap */ 861TRACEME_VFORK_RAISE(traceme_vfork_raise7, SIGHUP) /* hangup */ 862TRACEME_VFORK_RAISE(traceme_vfork_raise8, SIGCONT) /* continued? */ 863 864/// ---------------------------------------------------------------------------- 865 866static void 867traceme_vfork_crash(int sig) 868{ 869 pid_t child, wpid; 870#if defined(TWAIT_HAVE_STATUS) 871 int status; 872#endif 873 874 DPRINTF("Before forking process PID=%d\n", getpid()); 875 SYSCALL_REQUIRE((child = vfork()) != -1); 876 if (child == 0) { 877 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 878 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 879 880 DPRINTF("Before executing a trap\n"); 881 switch (sig) { 882 case SIGTRAP: 883 trigger_trap(); 884 break; 885 case SIGSEGV: 886 trigger_segv(); 887 break; 888 case SIGILL: 889 trigger_ill(); 890 break; 891 case SIGFPE: 892 trigger_fpe(); 893 break; 894 case SIGBUS: 895 trigger_bus(); 896 break; 897 default: 898 /* NOTREACHED */ 899 FORKEE_ASSERTX(0 && "This shall not be reached"); 900 } 901 902 /* NOTREACHED */ 903 FORKEE_ASSERTX(0 && "This shall not be reached"); 904 } 905 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 906 907 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 908 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 909 910 validate_status_signaled(status, sig, 1); 911 912 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 913 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 914} 915 916#define TRACEME_VFORK_CRASH(test, sig) \ 917ATF_TC(test); \ 918ATF_TC_HEAD(test, tc) \ 919{ \ 920 atf_tc_set_md_var(tc, "descr", \ 921 "Verify PT_TRACE_ME followed by a crash signal " #sig " in a " \ 922 "vfork(2)ed child"); \ 923} \ 924 \ 925ATF_TC_BODY(test, tc) \ 926{ \ 927 \ 928 traceme_vfork_crash(sig); \ 929} 930 931TRACEME_VFORK_CRASH(traceme_vfork_crash_trap, SIGTRAP) 932TRACEME_VFORK_CRASH(traceme_vfork_crash_segv, SIGSEGV) 933//TRACEME_VFORK_CRASH(traceme_vfork_crash_ill, SIGILL) 934TRACEME_VFORK_CRASH(traceme_vfork_crash_fpe, SIGFPE) 935TRACEME_VFORK_CRASH(traceme_vfork_crash_bus, SIGBUS) 936 937/// ---------------------------------------------------------------------------- 938 939ATF_TC(traceme_vfork_exec); 940ATF_TC_HEAD(traceme_vfork_exec, tc) 941{ 942 atf_tc_set_md_var(tc, "descr", 943 "Verify PT_TRACE_ME followed by exec(3) in a vfork(2)ed child"); 944} 945 946ATF_TC_BODY(traceme_vfork_exec, tc) 947{ 948 const int sigval = SIGTRAP; 949 pid_t child, wpid; 950#if defined(TWAIT_HAVE_STATUS) 951 int status; 952#endif 953 struct ptrace_siginfo info; 954 955 memset(&info, 0, sizeof(info)); 956 957 DPRINTF("Before forking process PID=%d\n", getpid()); 958 SYSCALL_REQUIRE((child = vfork()) != -1); 959 if (child == 0) { 960 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 961 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 962 963 DPRINTF("Before calling execve(2) from child\n"); 964 execlp("/bin/echo", "/bin/echo", NULL); 965 966 /* NOTREACHED */ 967 FORKEE_ASSERTX(0 && "Not reached"); 968 } 969 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 970 971 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 972 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 973 974 validate_status_stopped(status, sigval); 975 976 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 977 SYSCALL_REQUIRE( 978 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 979 980 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 981 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 982 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 983 info.psi_siginfo.si_errno); 984 985 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 986 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); 987 988 DPRINTF("Before resuming the child process where it left off and " 989 "without signal to be sent\n"); 990 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 991 992 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 993 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 994 995 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 996 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 997} 998 999/// ---------------------------------------------------------------------------- 1000 1001#if defined(TWAIT_HAVE_PID) 1002static void 1003unrelated_tracer_sees_crash(int sig) 1004{ 1005 struct msg_fds parent_tracee, parent_tracer; 1006 const int exitval = 10; 1007 pid_t tracee, tracer, wpid; 1008 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 1009#if defined(TWAIT_HAVE_STATUS) 1010 int status; 1011#endif 1012 struct ptrace_siginfo info; 1013 1014 memset(&info, 0, sizeof(info)); 1015 1016 DPRINTF("Spawn tracee\n"); 1017 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 1018 tracee = atf_utils_fork(); 1019 if (tracee == 0) { 1020 // Wait for parent to let us crash 1021 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); 1022 1023 DPRINTF("Before executing a trap\n"); 1024 switch (sig) { 1025 case SIGTRAP: 1026 trigger_trap(); 1027 break; 1028 case SIGSEGV: 1029 trigger_segv(); 1030 break; 1031 case SIGILL: 1032 trigger_ill(); 1033 break; 1034 case SIGFPE: 1035 trigger_fpe(); 1036 break; 1037 case SIGBUS: 1038 trigger_bus(); 1039 break; 1040 default: 1041 /* NOTREACHED */ 1042 FORKEE_ASSERTX(0 && "This shall not be reached"); 1043 } 1044 1045 /* NOTREACHED */ 1046 FORKEE_ASSERTX(0 && "This shall not be reached"); 1047 } 1048 1049 DPRINTF("Spawn debugger\n"); 1050 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 1051 tracer = atf_utils_fork(); 1052 if (tracer == 0) { 1053 /* Fork again and drop parent to reattach to PID 1 */ 1054 tracer = atf_utils_fork(); 1055 if (tracer != 0) 1056 _exit(exitval); 1057 1058 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 1059 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 1060 1061 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 1062 FORKEE_REQUIRE_SUCCESS( 1063 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1064 1065 forkee_status_stopped(status, SIGSTOP); 1066 1067 /* Resume tracee with PT_CONTINUE */ 1068 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 1069 1070 /* Inform parent that tracer has attached to tracee */ 1071 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 1072 1073 /* Wait for parent to tell use that tracee should have exited */ 1074 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); 1075 1076 /* Wait for tracee and assert that it exited */ 1077 FORKEE_REQUIRE_SUCCESS( 1078 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1079 1080 validate_status_stopped(status, sig); 1081 1082 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for the " 1083 "traced process\n"); 1084 SYSCALL_REQUIRE( 1085 ptrace(PT_GET_SIGINFO, tracee, &info, sizeof(info)) != -1); 1086 1087 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 1088 DPRINTF("Signal properties: si_signo=%#x si_code=%#x " 1089 "si_errno=%#x\n", info.psi_siginfo.si_signo, 1090 info.psi_siginfo.si_code, info.psi_siginfo.si_errno); 1091 1092 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sig); 1093 switch (sig) { 1094 case SIGTRAP: 1095 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_BRKPT); 1096 break; 1097 case SIGSEGV: 1098 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SEGV_MAPERR); 1099 break; 1100// case SIGILL: 1101// ATF_REQUIRE_EQ(info.psi_siginfo.si_code, ILL_ILLOP); 1102// break; 1103 case SIGFPE: 1104 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, FPE_INTDIV); 1105 break; 1106 case SIGBUS: 1107 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, BUS_ADRERR); 1108 break; 1109 } 1110 1111 FORKEE_ASSERT(ptrace(PT_KILL, tracee, NULL, 0) != -1); 1112 DPRINTF("Before calling %s() for the tracee\n", TWAIT_FNAME); 1113 TWAIT_REQUIRE_SUCCESS( 1114 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1115 1116 validate_status_signaled(status, SIGKILL, 0); 1117 1118 DPRINTF("Before calling %s() for tracee\n", TWAIT_FNAME); 1119 TWAIT_REQUIRE_FAILURE(ECHILD, 1120 wpid = TWAIT_GENERIC(tracee, &status, 0)); 1121 1122 DPRINTF("Before exiting of the tracer process\n"); 1123 _exit(0 /* collect by initproc */); 1124 } 1125 1126 DPRINTF("Wait for the tracer process (direct child) to exit " 1127 "calling %s()\n", TWAIT_FNAME); 1128 TWAIT_REQUIRE_SUCCESS( 1129 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer); 1130 1131 validate_status_exited(status, exitval); 1132 1133 DPRINTF("Wait for the non-exited tracee process with %s()\n", 1134 TWAIT_FNAME); 1135 TWAIT_REQUIRE_SUCCESS( 1136 wpid = TWAIT_GENERIC(tracee, NULL, WNOHANG), 0); 1137 1138 DPRINTF("Wait for the tracer to attach to the tracee\n"); 1139 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 1140 1141 DPRINTF("Resume the tracee and let it crash\n"); 1142 PARENT_TO_CHILD("exit tracee", parent_tracee, msg); 1143 1144 DPRINTF("Resume the tracer and let it detect crashed tracee\n"); 1145 PARENT_TO_CHILD("Message 2", parent_tracer, msg); 1146 1147 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 1148 TWAIT_FNAME); 1149 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1150 1151 validate_status_signaled(status, SIGKILL, 0); 1152 1153 msg_close(&parent_tracer); 1154 msg_close(&parent_tracee); 1155} 1156 1157#define UNRELATED_TRACER_SEES_CRASH(test, sig) \ 1158ATF_TC(test); \ 1159ATF_TC_HEAD(test, tc) \ 1160{ \ 1161 atf_tc_set_md_var(tc, "descr", \ 1162 "Assert that an unrelated tracer sees crash signal from the " \ 1163 "debuggee"); \ 1164} \ 1165 \ 1166ATF_TC_BODY(test, tc) \ 1167{ \ 1168 \ 1169 unrelated_tracer_sees_crash(sig); \ 1170} 1171 1172UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_trap, SIGTRAP) 1173UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_segv, SIGSEGV) 1174//UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_ill, SIGILL) 1175UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_fpe, SIGFPE) 1176UNRELATED_TRACER_SEES_CRASH(unrelated_tracer_sees_crash_bus, SIGBUS) 1177#endif 1178 1179/// ---------------------------------------------------------------------------- 1180 1181#if defined(TWAIT_HAVE_PID) 1182static void 1183tracer_sees_terminaton_before_the_parent_raw(bool notimeout, bool unrelated, 1184 bool stopped) 1185{ 1186 /* 1187 * notimeout - disable timeout in await zombie function 1188 * unrelated - attach from unrelated tracer reparented to initproc 1189 * stopped - attach to a stopped process 1190 */ 1191 1192 struct msg_fds parent_tracee, parent_tracer; 1193 const int exitval_tracee = 5; 1194 const int exitval_tracer = 10; 1195 pid_t tracee, tracer, wpid; 1196 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 1197#if defined(TWAIT_HAVE_STATUS) 1198 int status; 1199#endif 1200 1201 /* 1202 * Only a subset of options are supported. 1203 */ 1204 ATF_REQUIRE((!notimeout && !unrelated && !stopped) || 1205 (!notimeout && unrelated && !stopped) || 1206 (notimeout && !unrelated && !stopped) || 1207 (!notimeout && unrelated && stopped)); 1208 1209 DPRINTF("Spawn tracee\n"); 1210 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 1211 tracee = atf_utils_fork(); 1212 if (tracee == 0) { 1213 if (stopped) { 1214 DPRINTF("Stop self PID %d\n", getpid()); 1215 raise(SIGSTOP); 1216 } 1217 1218 // Wait for parent to let us exit 1219 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); 1220 _exit(exitval_tracee); 1221 } 1222 1223 DPRINTF("Spawn debugger\n"); 1224 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 1225 tracer = atf_utils_fork(); 1226 if (tracer == 0) { 1227 if(unrelated) { 1228 /* Fork again and drop parent to reattach to PID 1 */ 1229 tracer = atf_utils_fork(); 1230 if (tracer != 0) 1231 _exit(exitval_tracer); 1232 } 1233 1234 if (stopped) { 1235 DPRINTF("Await for a stopped parent PID %d\n", tracee); 1236 await_stopped(tracee); 1237 } 1238 1239 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 1240 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 1241 1242 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 1243 FORKEE_REQUIRE_SUCCESS( 1244 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1245 1246 forkee_status_stopped(status, SIGSTOP); 1247 1248 /* Resume tracee with PT_CONTINUE */ 1249 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 1250 1251 /* Inform parent that tracer has attached to tracee */ 1252 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 1253 1254 /* Wait for parent to tell use that tracee should have exited */ 1255 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); 1256 1257 /* Wait for tracee and assert that it exited */ 1258 FORKEE_REQUIRE_SUCCESS( 1259 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1260 1261 forkee_status_exited(status, exitval_tracee); 1262 DPRINTF("Tracee %d exited with %d\n", tracee, exitval_tracee); 1263 1264 DPRINTF("Before exiting of the tracer process\n"); 1265 _exit(unrelated ? 0 /* collect by initproc */ : exitval_tracer); 1266 } 1267 1268 if (unrelated) { 1269 DPRINTF("Wait for the tracer process (direct child) to exit " 1270 "calling %s()\n", TWAIT_FNAME); 1271 TWAIT_REQUIRE_SUCCESS( 1272 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer); 1273 1274 validate_status_exited(status, exitval_tracer); 1275 1276 DPRINTF("Wait for the non-exited tracee process with %s()\n", 1277 TWAIT_FNAME); 1278 TWAIT_REQUIRE_SUCCESS( 1279 wpid = TWAIT_GENERIC(tracee, NULL, WNOHANG), 0); 1280 } 1281 1282 DPRINTF("Wait for the tracer to attach to the tracee\n"); 1283 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 1284 1285 DPRINTF("Resume the tracee and let it exit\n"); 1286 PARENT_TO_CHILD("exit tracee", parent_tracee, msg); 1287 1288 DPRINTF("Detect that tracee is zombie\n"); 1289 if (notimeout) 1290 await_zombie_raw(tracee, 0); 1291 else 1292 await_zombie(tracee); 1293 1294 DPRINTF("Assert that there is no status about tracee %d - " 1295 "Tracer must detect zombie first - calling %s()\n", tracee, 1296 TWAIT_FNAME); 1297 TWAIT_REQUIRE_SUCCESS( 1298 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 1299 1300 if (unrelated) { 1301 DPRINTF("Resume the tracer and let it detect exited tracee\n"); 1302 PARENT_TO_CHILD("Message 2", parent_tracer, msg); 1303 } else { 1304 DPRINTF("Tell the tracer child should have exited\n"); 1305 PARENT_TO_CHILD("wait for tracee exit", parent_tracer, msg); 1306 DPRINTF("Wait for tracer to finish its job and exit - calling " 1307 "%s()\n", TWAIT_FNAME); 1308 1309 DPRINTF("Wait from tracer child to complete waiting for " 1310 "tracee\n"); 1311 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 1312 tracer); 1313 1314 validate_status_exited(status, exitval_tracer); 1315 } 1316 1317 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 1318 TWAIT_FNAME); 1319 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1320 1321 validate_status_exited(status, exitval_tracee); 1322 1323 msg_close(&parent_tracer); 1324 msg_close(&parent_tracee); 1325} 1326 1327ATF_TC(tracer_sees_terminaton_before_the_parent); 1328ATF_TC_HEAD(tracer_sees_terminaton_before_the_parent, tc) 1329{ 1330 atf_tc_set_md_var(tc, "descr", 1331 "Assert that tracer sees process termination before the parent"); 1332} 1333 1334ATF_TC_BODY(tracer_sees_terminaton_before_the_parent, tc) 1335{ 1336 1337 tracer_sees_terminaton_before_the_parent_raw(false, false, false); 1338} 1339 1340ATF_TC(tracer_sysctl_lookup_without_duplicates); 1341ATF_TC_HEAD(tracer_sysctl_lookup_without_duplicates, tc) 1342{ 1343 atf_tc_set_md_var(tc, "descr", 1344 "Assert that await_zombie() in attach1 always finds a single " 1345 "process and no other error is reported"); 1346} 1347 1348ATF_TC_BODY(tracer_sysctl_lookup_without_duplicates, tc) 1349{ 1350 time_t start, end; 1351 double diff; 1352 unsigned long N = 0; 1353 1354 /* 1355 * Reuse this test with tracer_sees_terminaton_before_the_parent_raw(). 1356 * This test body isn't specific to this race, however it's just good 1357 * enough for this purposes, no need to invent a dedicated code flow. 1358 */ 1359 1360 start = time(NULL); 1361 while (true) { 1362 DPRINTF("Step: %lu\n", N); 1363 tracer_sees_terminaton_before_the_parent_raw(true, false, 1364 false); 1365 end = time(NULL); 1366 diff = difftime(end, start); 1367 if (diff >= 5.0) 1368 break; 1369 ++N; 1370 } 1371 DPRINTF("Iterations: %lu\n", N); 1372} 1373 1374ATF_TC(unrelated_tracer_sees_terminaton_before_the_parent); 1375ATF_TC_HEAD(unrelated_tracer_sees_terminaton_before_the_parent, tc) 1376{ 1377 atf_tc_set_md_var(tc, "descr", 1378 "Assert that tracer sees process termination before the parent"); 1379} 1380 1381ATF_TC_BODY(unrelated_tracer_sees_terminaton_before_the_parent, tc) 1382{ 1383 1384 tracer_sees_terminaton_before_the_parent_raw(false, true, false); 1385} 1386 1387ATF_TC(tracer_attach_to_unrelated_stopped_process); 1388ATF_TC_HEAD(tracer_attach_to_unrelated_stopped_process, tc) 1389{ 1390 atf_tc_set_md_var(tc, "descr", 1391 "Assert that tracer can attach to an unrelated stopped process"); 1392} 1393 1394ATF_TC_BODY(tracer_attach_to_unrelated_stopped_process, tc) 1395{ 1396 1397 tracer_sees_terminaton_before_the_parent_raw(false, true, true); 1398} 1399#endif 1400 1401/// ---------------------------------------------------------------------------- 1402 1403static void 1404parent_attach_to_its_child(bool stopped) 1405{ 1406 struct msg_fds parent_tracee; 1407 const int exitval_tracee = 5; 1408 pid_t tracee, wpid; 1409 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 1410#if defined(TWAIT_HAVE_STATUS) 1411 int status; 1412#endif 1413 1414 DPRINTF("Spawn tracee\n"); 1415 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 1416 tracee = atf_utils_fork(); 1417 if (tracee == 0) { 1418 CHILD_FROM_PARENT("Message 1", parent_tracee, msg); 1419 DPRINTF("Parent should now attach to tracee\n"); 1420 1421 if (stopped) { 1422 DPRINTF("Stop self PID %d\n", getpid()); 1423 SYSCALL_REQUIRE(raise(SIGSTOP) != -1); 1424 } 1425 1426 CHILD_FROM_PARENT("Message 2", parent_tracee, msg); 1427 /* Wait for message from the parent */ 1428 _exit(exitval_tracee); 1429 } 1430 PARENT_TO_CHILD("Message 1", parent_tracee, msg); 1431 1432 if (stopped) { 1433 DPRINTF("Await for a stopped tracee PID %d\n", tracee); 1434 await_stopped(tracee); 1435 } 1436 1437 DPRINTF("Before calling PT_ATTACH for tracee %d\n", tracee); 1438 SYSCALL_REQUIRE(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 1439 1440 DPRINTF("Wait for the stopped tracee process with %s()\n", 1441 TWAIT_FNAME); 1442 TWAIT_REQUIRE_SUCCESS( 1443 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1444 1445 validate_status_stopped(status, SIGSTOP); 1446 1447 DPRINTF("Resume tracee with PT_CONTINUE\n"); 1448 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 1449 1450 DPRINTF("Let the tracee exit now\n"); 1451 PARENT_TO_CHILD("Message 2", parent_tracee, msg); 1452 1453 DPRINTF("Wait for tracee to exit with %s()\n", TWAIT_FNAME); 1454 TWAIT_REQUIRE_SUCCESS( 1455 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1456 1457 validate_status_exited(status, exitval_tracee); 1458 1459 DPRINTF("Before calling %s() for tracee\n", TWAIT_FNAME); 1460 TWAIT_REQUIRE_FAILURE(ECHILD, 1461 wpid = TWAIT_GENERIC(tracee, &status, 0)); 1462 1463 msg_close(&parent_tracee); 1464} 1465 1466ATF_TC(parent_attach_to_its_child); 1467ATF_TC_HEAD(parent_attach_to_its_child, tc) 1468{ 1469 atf_tc_set_md_var(tc, "descr", 1470 "Assert that tracer parent can PT_ATTACH to its child"); 1471} 1472 1473ATF_TC_BODY(parent_attach_to_its_child, tc) 1474{ 1475 1476 parent_attach_to_its_child(false); 1477} 1478 1479ATF_TC(parent_attach_to_its_stopped_child); 1480ATF_TC_HEAD(parent_attach_to_its_stopped_child, tc) 1481{ 1482 atf_tc_set_md_var(tc, "descr", 1483 "Assert that tracer parent can PT_ATTACH to its stopped child"); 1484} 1485 1486ATF_TC_BODY(parent_attach_to_its_stopped_child, tc) 1487{ 1488 1489 parent_attach_to_its_child(true); 1490} 1491 1492/// ---------------------------------------------------------------------------- 1493 1494static void 1495child_attach_to_its_parent(bool stopped) 1496{ 1497 struct msg_fds parent_tracee; 1498 const int exitval_tracer = 5; 1499 pid_t tracer, wpid; 1500 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 1501#if defined(TWAIT_HAVE_STATUS) 1502 int status; 1503#endif 1504 1505 DPRINTF("Spawn tracer\n"); 1506 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 1507 tracer = atf_utils_fork(); 1508 if (tracer == 0) { 1509 /* Wait for message from the parent */ 1510 CHILD_FROM_PARENT("Message 1", parent_tracee, msg); 1511 1512 if (stopped) { 1513 DPRINTF("Await for a stopped parent PID %d\n", 1514 getppid()); 1515 await_stopped(getppid()); 1516 } 1517 1518 DPRINTF("Attach to parent PID %d with PT_ATTACH from child\n", 1519 getppid()); 1520 FORKEE_ASSERT(ptrace(PT_ATTACH, getppid(), NULL, 0) != -1); 1521 1522 DPRINTF("Wait for the stopped parent process with %s()\n", 1523 TWAIT_FNAME); 1524 FORKEE_REQUIRE_SUCCESS( 1525 wpid = TWAIT_GENERIC(getppid(), &status, 0), getppid()); 1526 1527 forkee_status_stopped(status, SIGSTOP); 1528 1529 DPRINTF("Resume parent with PT_DETACH\n"); 1530 FORKEE_ASSERT(ptrace(PT_DETACH, getppid(), (void *)1, 0) 1531 != -1); 1532 1533 /* Tell parent we are ready */ 1534 CHILD_TO_PARENT("Message 1", parent_tracee, msg); 1535 1536 _exit(exitval_tracer); 1537 } 1538 1539 DPRINTF("Wait for the tracer to become ready\n"); 1540 PARENT_TO_CHILD("Message 1", parent_tracee, msg); 1541 1542 if (stopped) { 1543 DPRINTF("Stop self PID %d\n", getpid()); 1544 SYSCALL_REQUIRE(raise(SIGSTOP) != -1); 1545 } 1546 1547 DPRINTF("Allow the tracer to exit now\n"); 1548 PARENT_FROM_CHILD("Message 1", parent_tracee, msg); 1549 1550 DPRINTF("Wait for tracer to exit with %s()\n", TWAIT_FNAME); 1551 TWAIT_REQUIRE_SUCCESS( 1552 wpid = TWAIT_GENERIC(tracer, &status, 0), tracer); 1553 1554 validate_status_exited(status, exitval_tracer); 1555 1556 DPRINTF("Before calling %s() for tracer\n", TWAIT_FNAME); 1557 TWAIT_REQUIRE_FAILURE(ECHILD, 1558 wpid = TWAIT_GENERIC(tracer, &status, 0)); 1559 1560 msg_close(&parent_tracee); 1561} 1562 1563ATF_TC(child_attach_to_its_parent); 1564ATF_TC_HEAD(child_attach_to_its_parent, tc) 1565{ 1566 atf_tc_set_md_var(tc, "descr", 1567 "Assert that tracer child can PT_ATTACH to its parent"); 1568} 1569 1570ATF_TC_BODY(child_attach_to_its_parent, tc) 1571{ 1572 1573 child_attach_to_its_parent(false); 1574} 1575 1576ATF_TC(child_attach_to_its_stopped_parent); 1577ATF_TC_HEAD(child_attach_to_its_stopped_parent, tc) 1578{ 1579 atf_tc_set_md_var(tc, "descr", 1580 "Assert that tracer child can PT_ATTACH to its stopped parent"); 1581} 1582 1583ATF_TC_BODY(child_attach_to_its_stopped_parent, tc) 1584{ 1585 /* 1586 * The ATF framework (atf-run) does not tolerate raise(SIGSTOP), as 1587 * this causes a pipe (established from atf-run) to be broken. 1588 * atf-run uses this mechanism to monitor whether a test is alive. 1589 * 1590 * As a workaround spawn this test as a subprocess. 1591 */ 1592 1593 const int exitval = 15; 1594 pid_t child, wpid; 1595#if defined(TWAIT_HAVE_STATUS) 1596 int status; 1597#endif 1598 1599 SYSCALL_REQUIRE((child = fork()) != -1); 1600 if (child == 0) { 1601 child_attach_to_its_parent(true); 1602 _exit(exitval); 1603 } else { 1604 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1605 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1606 1607 validate_status_exited(status, exitval); 1608 1609 DPRINTF("Before calling %s() for the exited child\n", TWAIT_FNAME); 1610 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1611 } 1612} 1613 1614/// ---------------------------------------------------------------------------- 1615 1616#if defined(TWAIT_HAVE_PID) 1617 1618enum tracee_sees_its_original_parent_type { 1619 TRACEE_SEES_ITS_ORIGINAL_PARENT_GETPPID, 1620 TRACEE_SEES_ITS_ORIGINAL_PARENT_SYSCTL_KINFO_PROC2, 1621 TRACEE_SEES_ITS_ORIGINAL_PARENT_PROCFS_STATUS 1622}; 1623 1624static void 1625tracee_sees_its_original_parent(enum tracee_sees_its_original_parent_type type) 1626{ 1627 struct msg_fds parent_tracer, parent_tracee; 1628 const int exitval_tracee = 5; 1629 const int exitval_tracer = 10; 1630 pid_t parent, tracee, tracer, wpid; 1631 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 1632#if defined(TWAIT_HAVE_STATUS) 1633 int status; 1634#endif 1635 /* sysctl(3) - kinfo_proc2 */ 1636 int name[CTL_MAXNAME]; 1637 struct kinfo_proc2 kp; 1638 size_t len = sizeof(kp); 1639 unsigned int namelen; 1640 1641 /* procfs - status */ 1642 FILE *fp; 1643 struct stat st; 1644 const char *fname = "/proc/curproc/status"; 1645 char s_executable[MAXPATHLEN]; 1646 int s_pid, s_ppid; 1647 int rv; 1648 1649 if (type == TRACEE_SEES_ITS_ORIGINAL_PARENT_PROCFS_STATUS) { 1650 SYSCALL_REQUIRE( 1651 (rv = stat(fname, &st)) == 0 || (errno == ENOENT)); 1652 if (rv != 0) 1653 atf_tc_skip("/proc/curproc/status not found"); 1654 } 1655 1656 DPRINTF("Spawn tracee\n"); 1657 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 1658 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 1659 tracee = atf_utils_fork(); 1660 if (tracee == 0) { 1661 parent = getppid(); 1662 1663 /* Emit message to the parent */ 1664 CHILD_TO_PARENT("tracee ready", parent_tracee, msg); 1665 CHILD_FROM_PARENT("exit tracee", parent_tracee, msg); 1666 1667 switch (type) { 1668 case TRACEE_SEES_ITS_ORIGINAL_PARENT_GETPPID: 1669 FORKEE_ASSERT_EQ(parent, getppid()); 1670 break; 1671 case TRACEE_SEES_ITS_ORIGINAL_PARENT_SYSCTL_KINFO_PROC2: 1672 namelen = 0; 1673 name[namelen++] = CTL_KERN; 1674 name[namelen++] = KERN_PROC2; 1675 name[namelen++] = KERN_PROC_PID; 1676 name[namelen++] = getpid(); 1677 name[namelen++] = len; 1678 name[namelen++] = 1; 1679 1680 FORKEE_ASSERT_EQ( 1681 sysctl(name, namelen, &kp, &len, NULL, 0), 0); 1682 FORKEE_ASSERT_EQ(parent, kp.p_ppid); 1683 break; 1684 case TRACEE_SEES_ITS_ORIGINAL_PARENT_PROCFS_STATUS: 1685 /* 1686 * Format: 1687 * EXECUTABLE PID PPID ... 1688 */ 1689 FORKEE_ASSERT((fp = fopen(fname, "r")) != NULL); 1690 fscanf(fp, "%s %d %d", s_executable, &s_pid, &s_ppid); 1691 FORKEE_ASSERT_EQ(fclose(fp), 0); 1692 FORKEE_ASSERT_EQ(parent, s_ppid); 1693 break; 1694 } 1695 1696 _exit(exitval_tracee); 1697 } 1698 DPRINTF("Wait for child to record its parent identifier (pid)\n"); 1699 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg); 1700 1701 DPRINTF("Spawn debugger\n"); 1702 tracer = atf_utils_fork(); 1703 if (tracer == 0) { 1704 /* No IPC to communicate with the child */ 1705 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 1706 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 1707 1708 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 1709 FORKEE_REQUIRE_SUCCESS( 1710 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1711 1712 forkee_status_stopped(status, SIGSTOP); 1713 1714 /* Resume tracee with PT_CONTINUE */ 1715 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 1716 1717 /* Inform parent that tracer has attached to tracee */ 1718 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 1719 1720 /* Wait for parent to tell use that tracee should have exited */ 1721 CHILD_FROM_PARENT("wait for tracee exit", parent_tracer, msg); 1722 1723 /* Wait for tracee and assert that it exited */ 1724 FORKEE_REQUIRE_SUCCESS( 1725 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 1726 1727 forkee_status_exited(status, exitval_tracee); 1728 1729 DPRINTF("Before exiting of the tracer process\n"); 1730 _exit(exitval_tracer); 1731 } 1732 1733 DPRINTF("Wait for the tracer to attach to the tracee\n"); 1734 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 1735 1736 DPRINTF("Resume the tracee and let it exit\n"); 1737 PARENT_TO_CHILD("exit tracee", parent_tracee, msg); 1738 1739 DPRINTF("Detect that tracee is zombie\n"); 1740 await_zombie(tracee); 1741 1742 DPRINTF("Assert that there is no status about tracee - " 1743 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 1744 TWAIT_REQUIRE_SUCCESS( 1745 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 1746 1747 DPRINTF("Tell the tracer child should have exited\n"); 1748 PARENT_TO_CHILD("wait for tracee exit", parent_tracer, msg); 1749 1750 DPRINTF("Wait from tracer child to complete waiting for tracee\n"); 1751 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 1752 tracer); 1753 1754 validate_status_exited(status, exitval_tracer); 1755 1756 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 1757 TWAIT_FNAME); 1758 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 1759 tracee); 1760 1761 validate_status_exited(status, exitval_tracee); 1762 1763 msg_close(&parent_tracer); 1764 msg_close(&parent_tracee); 1765} 1766 1767#define TRACEE_SEES_ITS_ORIGINAL_PARENT(test, type, descr) \ 1768ATF_TC(test); \ 1769ATF_TC_HEAD(test, tc) \ 1770{ \ 1771 atf_tc_set_md_var(tc, "descr", \ 1772 "Assert that tracee sees its original parent when being traced " \ 1773 "(check " descr ")"); \ 1774} \ 1775 \ 1776ATF_TC_BODY(test, tc) \ 1777{ \ 1778 \ 1779 tracee_sees_its_original_parent(type); \ 1780} 1781 1782TRACEE_SEES_ITS_ORIGINAL_PARENT( 1783 tracee_sees_its_original_parent_getppid, 1784 TRACEE_SEES_ITS_ORIGINAL_PARENT_GETPPID, 1785 "getppid(2)"); 1786TRACEE_SEES_ITS_ORIGINAL_PARENT( 1787 tracee_sees_its_original_parent_sysctl_kinfo_proc2, 1788 TRACEE_SEES_ITS_ORIGINAL_PARENT_SYSCTL_KINFO_PROC2, 1789 "sysctl(3) and kinfo_proc2"); 1790TRACEE_SEES_ITS_ORIGINAL_PARENT( 1791 tracee_sees_its_original_parent_procfs_status, 1792 TRACEE_SEES_ITS_ORIGINAL_PARENT_PROCFS_STATUS, 1793 "the status file in procfs"); 1794#endif 1795 1796/// ---------------------------------------------------------------------------- 1797 1798static void 1799eventmask_preserved(int event) 1800{ 1801 const int exitval = 5; 1802 const int sigval = SIGSTOP; 1803 pid_t child, wpid; 1804#if defined(TWAIT_HAVE_STATUS) 1805 int status; 1806#endif 1807 ptrace_event_t set_event, get_event; 1808 const int len = sizeof(ptrace_event_t); 1809 1810 DPRINTF("Before forking process PID=%d\n", getpid()); 1811 SYSCALL_REQUIRE((child = fork()) != -1); 1812 if (child == 0) { 1813 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1814 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1815 1816 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1817 FORKEE_ASSERT(raise(sigval) == 0); 1818 1819 DPRINTF("Before exiting of the child process\n"); 1820 _exit(exitval); 1821 } 1822 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1823 1824 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1825 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1826 1827 validate_status_stopped(status, sigval); 1828 1829 set_event.pe_set_event = event; 1830 SYSCALL_REQUIRE( 1831 ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); 1832 SYSCALL_REQUIRE( 1833 ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); 1834 ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); 1835 1836 DPRINTF("Before resuming the child process where it left off and " 1837 "without signal to be sent\n"); 1838 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1839 1840 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1841 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1842 1843 validate_status_exited(status, exitval); 1844 1845 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1846 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 1847} 1848 1849#define EVENTMASK_PRESERVED(test, event) \ 1850ATF_TC(test); \ 1851ATF_TC_HEAD(test, tc) \ 1852{ \ 1853 atf_tc_set_md_var(tc, "descr", \ 1854 "Verify that eventmask " #event " is preserved"); \ 1855} \ 1856 \ 1857ATF_TC_BODY(test, tc) \ 1858{ \ 1859 \ 1860 eventmask_preserved(event); \ 1861} 1862 1863EVENTMASK_PRESERVED(eventmask_preserved_empty, 0) 1864EVENTMASK_PRESERVED(eventmask_preserved_fork, PTRACE_FORK) 1865EVENTMASK_PRESERVED(eventmask_preserved_vfork, PTRACE_VFORK) 1866EVENTMASK_PRESERVED(eventmask_preserved_vfork_done, PTRACE_VFORK_DONE) 1867EVENTMASK_PRESERVED(eventmask_preserved_lwp_create, PTRACE_LWP_CREATE) 1868EVENTMASK_PRESERVED(eventmask_preserved_lwp_exit, PTRACE_LWP_EXIT) 1869 1870/// ---------------------------------------------------------------------------- 1871 1872static void 1873fork_body(pid_t (*fn)(void), bool trackfork, bool trackvfork, 1874 bool trackvforkdone, bool detachchild, bool detachparent) 1875{ 1876 const int exitval = 5; 1877 const int exitval2 = 15; 1878 const int sigval = SIGSTOP; 1879 pid_t child, child2 = 0, wpid; 1880#if defined(TWAIT_HAVE_STATUS) 1881 int status; 1882#endif 1883 ptrace_state_t state; 1884 const int slen = sizeof(state); 1885 ptrace_event_t event; 1886 const int elen = sizeof(event); 1887 1888 DPRINTF("Before forking process PID=%d\n", getpid()); 1889 SYSCALL_REQUIRE((child = fork()) != -1); 1890 if (child == 0) { 1891 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 1892 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 1893 1894 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 1895 FORKEE_ASSERT(raise(sigval) == 0); 1896 1897 FORKEE_ASSERT((child2 = (fn)()) != -1); 1898 1899 if (child2 == 0) 1900 _exit(exitval2); 1901 1902 FORKEE_REQUIRE_SUCCESS 1903 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 1904 1905 forkee_status_exited(status, exitval2); 1906 1907 DPRINTF("Before exiting of the child process\n"); 1908 _exit(exitval); 1909 } 1910 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 1911 1912 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 1913 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 1914 1915 validate_status_stopped(status, sigval); 1916 1917 DPRINTF("Set 0%s%s%s in EVENT_MASK for the child %d\n", 1918 trackfork ? "|PTRACE_FORK" : "", 1919 trackvfork ? "|PTRACE_VFORK" : "", 1920 trackvforkdone ? "|PTRACE_VFORK_DONE" : "", child); 1921 event.pe_set_event = 0; 1922 if (trackfork) 1923 event.pe_set_event |= PTRACE_FORK; 1924 if (trackvfork) 1925 event.pe_set_event |= PTRACE_VFORK; 1926 if (trackvforkdone) 1927 event.pe_set_event |= PTRACE_VFORK_DONE; 1928 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 1929 1930 DPRINTF("Before resuming the child process where it left off and " 1931 "without signal to be sent\n"); 1932 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1933 1934#if defined(TWAIT_HAVE_PID) 1935 if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) { 1936 DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, 1937 child); 1938 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 1939 child); 1940 1941 validate_status_stopped(status, SIGTRAP); 1942 1943 SYSCALL_REQUIRE( 1944 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 1945 if (trackfork && fn == fork) { 1946 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK, 1947 PTRACE_FORK); 1948 } 1949 if (trackvfork && fn == vfork) { 1950 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK, 1951 PTRACE_VFORK); 1952 } 1953 1954 child2 = state.pe_other_pid; 1955 DPRINTF("Reported ptrace event with forkee %d\n", child2); 1956 1957 DPRINTF("Before calling %s() for the forkee %d of the child " 1958 "%d\n", TWAIT_FNAME, child2, child); 1959 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 1960 child2); 1961 1962 validate_status_stopped(status, SIGTRAP); 1963 1964 SYSCALL_REQUIRE( 1965 ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 1966 if (trackfork && fn == fork) { 1967 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_FORK, 1968 PTRACE_FORK); 1969 } 1970 if (trackvfork && fn == vfork) { 1971 ATF_REQUIRE_EQ(state.pe_report_event & PTRACE_VFORK, 1972 PTRACE_VFORK); 1973 } 1974 1975 ATF_REQUIRE_EQ(state.pe_other_pid, child); 1976 1977 DPRINTF("Before resuming the forkee process where it left off " 1978 "and without signal to be sent\n"); 1979 SYSCALL_REQUIRE( 1980 ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 1981 1982 DPRINTF("Before resuming the child process where it left off " 1983 "and without signal to be sent\n"); 1984 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 1985 } 1986#endif 1987 1988 if (trackvforkdone && fn == vfork) { 1989 DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, 1990 child); 1991 TWAIT_REQUIRE_SUCCESS( 1992 wpid = TWAIT_GENERIC(child, &status, 0), child); 1993 1994 validate_status_stopped(status, SIGTRAP); 1995 1996 SYSCALL_REQUIRE( 1997 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 1998 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE); 1999 2000 child2 = state.pe_other_pid; 2001 DPRINTF("Reported PTRACE_VFORK_DONE event with forkee %d\n", 2002 child2); 2003 2004 DPRINTF("Before resuming the child process where it left off " 2005 "and without signal to be sent\n"); 2006 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2007 } 2008 2009#if defined(TWAIT_HAVE_PID) 2010 if ((trackfork && fn == fork) || (trackvfork && fn == vfork)) { 2011 DPRINTF("Before calling %s() for the forkee - expected exited" 2012 "\n", TWAIT_FNAME); 2013 TWAIT_REQUIRE_SUCCESS( 2014 wpid = TWAIT_GENERIC(child2, &status, 0), child2); 2015 2016 validate_status_exited(status, exitval2); 2017 2018 DPRINTF("Before calling %s() for the forkee - expected no " 2019 "process\n", TWAIT_FNAME); 2020 TWAIT_REQUIRE_FAILURE(ECHILD, 2021 wpid = TWAIT_GENERIC(child2, &status, 0)); 2022 } 2023#endif 2024 2025 DPRINTF("Before calling %s() for the child - expected stopped " 2026 "SIGCHLD\n", TWAIT_FNAME); 2027 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2028 2029 validate_status_stopped(status, SIGCHLD); 2030 2031 DPRINTF("Before resuming the child process where it left off and " 2032 "without signal to be sent\n"); 2033 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2034 2035 DPRINTF("Before calling %s() for the child - expected exited\n", 2036 TWAIT_FNAME); 2037 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2038 2039 validate_status_exited(status, exitval); 2040 2041 DPRINTF("Before calling %s() for the child - expected no process\n", 2042 TWAIT_FNAME); 2043 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2044} 2045 2046#define FORK_TEST(name,descr,fun,tfork,tvfork,tvforkdone,detchild,detparent) \ 2047ATF_TC(name); \ 2048ATF_TC_HEAD(name, tc) \ 2049{ \ 2050 atf_tc_set_md_var(tc, "descr", descr); \ 2051} \ 2052 \ 2053ATF_TC_BODY(name, tc) \ 2054{ \ 2055 \ 2056 fork_body(fun, tfork, tvfork, tvforkdone, detchild, detparent); \ 2057} 2058 2059#define F false 2060#define T true 2061 2062#define F_IF__0(x) 2063#define F_IF__1(x) x 2064#define F_IF__(x,y) F_IF__ ## x (y) 2065#define F_IF_(x,y) F_IF__(x,y) 2066#define F_IF(x,y) F_IF_(x,y) 2067 2068#define DSCR(function,forkbit,vforkbit,vforkdonebit,dchildbit,dparentbit) \ 2069 "Verify " #function "(2) called with 0" \ 2070 F_IF(forkbit,"|PTRACE_FORK") \ 2071 F_IF(vforkbit,"|PTRACE_VFORK") \ 2072 F_IF(vforkdonebit,"|PTRACE_VFORK_DONE") \ 2073 " in EVENT_MASK." \ 2074 F_IF(dchildbit," Detach child in this test.") \ 2075 F_IF(dparentbit," Detach parent in this test.") 2076 2077FORK_TEST(fork1, DSCR(fork,0,0,0,0,0), fork, F, F, F, F, F) 2078#if defined(TWAIT_HAVE_PID) 2079FORK_TEST(fork2, DSCR(fork,1,0,0,0,0), fork, T, F, F, F, F) 2080FORK_TEST(fork3, DSCR(fork,0,1,0,0,0), fork, F, T, F, F, F) 2081FORK_TEST(fork4, DSCR(fork,1,1,0,0,0), fork, T, T, F, F, F) 2082#endif 2083FORK_TEST(fork5, DSCR(fork,0,0,1,0,0), fork, F, F, T, F, F) 2084#if defined(TWAIT_HAVE_PID) 2085FORK_TEST(fork6, DSCR(fork,1,0,1,0,0), fork, T, F, T, F, F) 2086FORK_TEST(fork7, DSCR(fork,0,1,1,0,0), fork, F, T, T, F, F) 2087FORK_TEST(fork8, DSCR(fork,1,1,1,0,0), fork, T, T, T, F, F) 2088#endif 2089 2090FORK_TEST(vfork1, DSCR(vfork,0,0,0,0,0), vfork, F, F, F, F, F) 2091#if defined(TWAIT_HAVE_PID) 2092FORK_TEST(vfork2, DSCR(vfork,1,0,0,0,0), vfork, T, F, F, F, F) 2093FORK_TEST(vfork3, DSCR(vfork,0,1,0,0,0), vfork, F, T, F, F, F) 2094FORK_TEST(vfork4, DSCR(vfork,1,1,0,0,0), vfork, T, T, F, F, F) 2095#endif 2096FORK_TEST(vfork5, DSCR(vfork,0,0,1,0,0), vfork, F, F, T, F, F) 2097#if defined(TWAIT_HAVE_PID) 2098FORK_TEST(vfork6, DSCR(vfork,1,0,1,0,0), vfork, T, F, T, F, F) 2099FORK_TEST(vfork7, DSCR(vfork,0,1,1,0,0), vfork, F, T, T, F, F) 2100FORK_TEST(vfork8, DSCR(vfork,1,1,1,0,0), vfork, T, T, T, F, F) 2101#endif 2102 2103/// ---------------------------------------------------------------------------- 2104 2105enum bytes_transfer_type { 2106 BYTES_TRANSFER_DATA, 2107 BYTES_TRANSFER_DATAIO, 2108 BYTES_TRANSFER_TEXT, 2109 BYTES_TRANSFER_TEXTIO, 2110 BYTES_TRANSFER_AUXV 2111}; 2112 2113static int __used 2114bytes_transfer_dummy(int a, int b, int c, int d) 2115{ 2116 int e, f, g, h; 2117 2118 a *= 4; 2119 b += 3; 2120 c -= 2; 2121 d /= 1; 2122 2123 e = strtol("10", NULL, 10); 2124 f = strtol("20", NULL, 10); 2125 g = strtol("30", NULL, 10); 2126 h = strtol("40", NULL, 10); 2127 2128 return (a + b * c - d) + (e * f - g / h); 2129} 2130 2131static void 2132bytes_transfer(int operation, size_t size, enum bytes_transfer_type type) 2133{ 2134 const int exitval = 5; 2135 const int sigval = SIGSTOP; 2136 pid_t child, wpid; 2137 bool skip = false; 2138 2139 int lookup_me = 0; 2140 uint8_t lookup_me8 = 0; 2141 uint16_t lookup_me16 = 0; 2142 uint32_t lookup_me32 = 0; 2143 uint64_t lookup_me64 = 0; 2144 2145 int magic = 0x13579246; 2146 uint8_t magic8 = 0xab; 2147 uint16_t magic16 = 0x1234; 2148 uint32_t magic32 = 0x98765432; 2149 uint64_t magic64 = 0xabcdef0123456789; 2150 2151 struct ptrace_io_desc io; 2152#if defined(TWAIT_HAVE_STATUS) 2153 int status; 2154#endif 2155 /* 513 is just enough, for the purposes of ATF it's good enough */ 2156 AuxInfo ai[513], *aip; 2157 2158 ATF_REQUIRE(size < sizeof(ai)); 2159 2160 /* Prepare variables for .TEXT transfers */ 2161 switch (type) { 2162 case BYTES_TRANSFER_TEXT: 2163 memcpy(&magic, bytes_transfer_dummy, sizeof(magic)); 2164 break; 2165 case BYTES_TRANSFER_TEXTIO: 2166 switch (size) { 2167 case 8: 2168 memcpy(&magic8, bytes_transfer_dummy, sizeof(magic8)); 2169 break; 2170 case 16: 2171 memcpy(&magic16, bytes_transfer_dummy, sizeof(magic16)); 2172 break; 2173 case 32: 2174 memcpy(&magic32, bytes_transfer_dummy, sizeof(magic32)); 2175 break; 2176 case 64: 2177 memcpy(&magic64, bytes_transfer_dummy, sizeof(magic64)); 2178 break; 2179 } 2180 break; 2181 default: 2182 break; 2183 } 2184 2185 /* Prepare variables for PIOD and AUXV transfers */ 2186 switch (type) { 2187 case BYTES_TRANSFER_TEXTIO: 2188 case BYTES_TRANSFER_DATAIO: 2189 io.piod_op = operation; 2190 switch (size) { 2191 case 8: 2192 io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? 2193 (void *)bytes_transfer_dummy : 2194 &lookup_me8; 2195 io.piod_addr = &lookup_me8; 2196 io.piod_len = sizeof(lookup_me8); 2197 break; 2198 case 16: 2199 io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? 2200 (void *)bytes_transfer_dummy : 2201 &lookup_me16; 2202 io.piod_addr = &lookup_me16; 2203 io.piod_len = sizeof(lookup_me16); 2204 break; 2205 case 32: 2206 io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? 2207 (void *)bytes_transfer_dummy : 2208 &lookup_me32; 2209 io.piod_addr = &lookup_me32; 2210 io.piod_len = sizeof(lookup_me32); 2211 break; 2212 case 64: 2213 io.piod_offs = (type == BYTES_TRANSFER_TEXTIO) ? 2214 (void *)bytes_transfer_dummy : 2215 &lookup_me64; 2216 io.piod_addr = &lookup_me64; 2217 io.piod_len = sizeof(lookup_me64); 2218 break; 2219 default: 2220 break; 2221 } 2222 break; 2223 case BYTES_TRANSFER_AUXV: 2224 io.piod_op = operation; 2225 io.piod_offs = 0; 2226 io.piod_addr = ai; 2227 io.piod_len = size; 2228 break; 2229 default: 2230 break; 2231 } 2232 2233 DPRINTF("Before forking process PID=%d\n", getpid()); 2234 SYSCALL_REQUIRE((child = fork()) != -1); 2235 if (child == 0) { 2236 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2237 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2238 2239 switch (type) { 2240 case BYTES_TRANSFER_DATA: 2241 switch (operation) { 2242 case PT_READ_D: 2243 case PT_READ_I: 2244 lookup_me = magic; 2245 break; 2246 default: 2247 break; 2248 } 2249 break; 2250 case BYTES_TRANSFER_DATAIO: 2251 switch (operation) { 2252 case PIOD_READ_D: 2253 case PIOD_READ_I: 2254 switch (size) { 2255 case 8: 2256 lookup_me8 = magic8; 2257 break; 2258 case 16: 2259 lookup_me16 = magic16; 2260 break; 2261 case 32: 2262 lookup_me32 = magic32; 2263 break; 2264 case 64: 2265 lookup_me64 = magic64; 2266 break; 2267 default: 2268 break; 2269 } 2270 break; 2271 default: 2272 break; 2273 } 2274 default: 2275 break; 2276 } 2277 2278 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2279 FORKEE_ASSERT(raise(sigval) == 0); 2280 2281 /* Handle PIOD and PT separately as operation values overlap */ 2282 switch (type) { 2283 case BYTES_TRANSFER_DATA: 2284 switch (operation) { 2285 case PT_WRITE_D: 2286 case PT_WRITE_I: 2287 FORKEE_ASSERT_EQ(lookup_me, magic); 2288 break; 2289 default: 2290 break; 2291 } 2292 break; 2293 case BYTES_TRANSFER_DATAIO: 2294 switch (operation) { 2295 case PIOD_WRITE_D: 2296 case PIOD_WRITE_I: 2297 switch (size) { 2298 case 8: 2299 FORKEE_ASSERT_EQ(lookup_me8, magic8); 2300 break; 2301 case 16: 2302 FORKEE_ASSERT_EQ(lookup_me16, magic16); 2303 break; 2304 case 32: 2305 FORKEE_ASSERT_EQ(lookup_me32, magic32); 2306 break; 2307 case 64: 2308 FORKEE_ASSERT_EQ(lookup_me64, magic64); 2309 break; 2310 default: 2311 break; 2312 } 2313 break; 2314 default: 2315 break; 2316 } 2317 break; 2318 case BYTES_TRANSFER_TEXT: 2319 FORKEE_ASSERT(memcmp(&magic, bytes_transfer_dummy, 2320 sizeof(magic)) == 0); 2321 break; 2322 case BYTES_TRANSFER_TEXTIO: 2323 switch (size) { 2324 case 8: 2325 FORKEE_ASSERT(memcmp(&magic8, 2326 bytes_transfer_dummy, 2327 sizeof(magic8)) == 0); 2328 break; 2329 case 16: 2330 FORKEE_ASSERT(memcmp(&magic16, 2331 bytes_transfer_dummy, 2332 sizeof(magic16)) == 0); 2333 break; 2334 case 32: 2335 FORKEE_ASSERT(memcmp(&magic32, 2336 bytes_transfer_dummy, 2337 sizeof(magic32)) == 0); 2338 break; 2339 case 64: 2340 FORKEE_ASSERT(memcmp(&magic64, 2341 bytes_transfer_dummy, 2342 sizeof(magic64)) == 0); 2343 break; 2344 } 2345 break; 2346 default: 2347 break; 2348 } 2349 2350 DPRINTF("Before exiting of the child process\n"); 2351 _exit(exitval); 2352 } 2353 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2354 2355 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2356 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2357 2358 validate_status_stopped(status, sigval); 2359 2360 /* Check PaX MPROTECT */ 2361 if (!can_we_write_to_text(child)) { 2362 switch (type) { 2363 case BYTES_TRANSFER_TEXTIO: 2364 switch (operation) { 2365 case PIOD_WRITE_D: 2366 case PIOD_WRITE_I: 2367 skip = true; 2368 break; 2369 default: 2370 break; 2371 } 2372 break; 2373 case BYTES_TRANSFER_TEXT: 2374 switch (operation) { 2375 case PT_WRITE_D: 2376 case PT_WRITE_I: 2377 skip = true; 2378 break; 2379 default: 2380 break; 2381 } 2382 break; 2383 default: 2384 break; 2385 } 2386 } 2387 2388 /* Bailout cleanly killing the child process */ 2389 if (skip) { 2390 SYSCALL_REQUIRE(ptrace(PT_KILL, child, (void *)1, 0) != -1); 2391 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2392 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 2393 child); 2394 2395 validate_status_signaled(status, SIGKILL, 0); 2396 2397 atf_tc_skip("PaX MPROTECT setup prevents writes to .text"); 2398 } 2399 2400 DPRINTF("Calling operation to transfer bytes between child=%d and " 2401 "parent=%d\n", child, getpid()); 2402 2403 switch (type) { 2404 case BYTES_TRANSFER_TEXTIO: 2405 case BYTES_TRANSFER_DATAIO: 2406 case BYTES_TRANSFER_AUXV: 2407 switch (operation) { 2408 case PIOD_WRITE_D: 2409 case PIOD_WRITE_I: 2410 switch (size) { 2411 case 8: 2412 lookup_me8 = magic8; 2413 break; 2414 case 16: 2415 lookup_me16 = magic16; 2416 break; 2417 case 32: 2418 lookup_me32 = magic32; 2419 break; 2420 case 64: 2421 lookup_me64 = magic64; 2422 break; 2423 default: 2424 break; 2425 } 2426 break; 2427 default: 2428 break; 2429 } 2430 SYSCALL_REQUIRE(ptrace(PT_IO, child, &io, 0) != -1); 2431 switch (operation) { 2432 case PIOD_READ_D: 2433 case PIOD_READ_I: 2434 switch (size) { 2435 case 8: 2436 ATF_REQUIRE_EQ(lookup_me8, magic8); 2437 break; 2438 case 16: 2439 ATF_REQUIRE_EQ(lookup_me16, magic16); 2440 break; 2441 case 32: 2442 ATF_REQUIRE_EQ(lookup_me32, magic32); 2443 break; 2444 case 64: 2445 ATF_REQUIRE_EQ(lookup_me64, magic64); 2446 break; 2447 default: 2448 break; 2449 } 2450 break; 2451 case PIOD_READ_AUXV: 2452 DPRINTF("Asserting that AUXV length (%zu) is > 0\n", 2453 io.piod_len); 2454 ATF_REQUIRE(io.piod_len > 0); 2455 for (aip = ai; aip->a_type != AT_NULL; aip++) 2456 DPRINTF("a_type=%#llx a_v=%#llx\n", 2457 (long long int)aip->a_type, 2458 (long long int)aip->a_v); 2459 break; 2460 default: 2461 break; 2462 } 2463 break; 2464 case BYTES_TRANSFER_TEXT: 2465 switch (operation) { 2466 case PT_READ_D: 2467 case PT_READ_I: 2468 errno = 0; 2469 lookup_me = ptrace(operation, child, 2470 bytes_transfer_dummy, 0); 2471 ATF_REQUIRE_EQ(lookup_me, magic); 2472 SYSCALL_REQUIRE_ERRNO(errno, 0); 2473 break; 2474 case PT_WRITE_D: 2475 case PT_WRITE_I: 2476 SYSCALL_REQUIRE(ptrace(operation, child, 2477 bytes_transfer_dummy, magic) 2478 != -1); 2479 break; 2480 default: 2481 break; 2482 } 2483 break; 2484 case BYTES_TRANSFER_DATA: 2485 switch (operation) { 2486 case PT_READ_D: 2487 case PT_READ_I: 2488 errno = 0; 2489 lookup_me = ptrace(operation, child, &lookup_me, 0); 2490 ATF_REQUIRE_EQ(lookup_me, magic); 2491 SYSCALL_REQUIRE_ERRNO(errno, 0); 2492 break; 2493 case PT_WRITE_D: 2494 case PT_WRITE_I: 2495 lookup_me = magic; 2496 SYSCALL_REQUIRE(ptrace(operation, child, &lookup_me, 2497 magic) != -1); 2498 break; 2499 default: 2500 break; 2501 } 2502 break; 2503 default: 2504 break; 2505 } 2506 2507 DPRINTF("Before resuming the child process where it left off and " 2508 "without signal to be sent\n"); 2509 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2510 2511 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2512 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2513 2514 validate_status_exited(status, exitval); 2515 2516 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2517 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2518} 2519 2520#define BYTES_TRANSFER(test, operation, size, type) \ 2521ATF_TC(test); \ 2522ATF_TC_HEAD(test, tc) \ 2523{ \ 2524 atf_tc_set_md_var(tc, "descr", \ 2525 "Verify bytes transfer operation" #operation " and size " #size \ 2526 " of type " #type); \ 2527} \ 2528 \ 2529ATF_TC_BODY(test, tc) \ 2530{ \ 2531 \ 2532 bytes_transfer(operation, size, BYTES_TRANSFER_##type); \ 2533} 2534 2535// DATA 2536 2537BYTES_TRANSFER(bytes_transfer_piod_read_d_8, PIOD_READ_D, 8, DATAIO) 2538BYTES_TRANSFER(bytes_transfer_piod_read_d_16, PIOD_READ_D, 16, DATAIO) 2539BYTES_TRANSFER(bytes_transfer_piod_read_d_32, PIOD_READ_D, 32, DATAIO) 2540BYTES_TRANSFER(bytes_transfer_piod_read_d_64, PIOD_READ_D, 64, DATAIO) 2541 2542BYTES_TRANSFER(bytes_transfer_piod_read_i_8, PIOD_READ_I, 8, DATAIO) 2543BYTES_TRANSFER(bytes_transfer_piod_read_i_16, PIOD_READ_I, 16, DATAIO) 2544BYTES_TRANSFER(bytes_transfer_piod_read_i_32, PIOD_READ_I, 32, DATAIO) 2545BYTES_TRANSFER(bytes_transfer_piod_read_i_64, PIOD_READ_I, 64, DATAIO) 2546 2547BYTES_TRANSFER(bytes_transfer_piod_write_d_8, PIOD_WRITE_D, 8, DATAIO) 2548BYTES_TRANSFER(bytes_transfer_piod_write_d_16, PIOD_WRITE_D, 16, DATAIO) 2549BYTES_TRANSFER(bytes_transfer_piod_write_d_32, PIOD_WRITE_D, 32, DATAIO) 2550BYTES_TRANSFER(bytes_transfer_piod_write_d_64, PIOD_WRITE_D, 64, DATAIO) 2551 2552BYTES_TRANSFER(bytes_transfer_piod_write_i_8, PIOD_WRITE_I, 8, DATAIO) 2553BYTES_TRANSFER(bytes_transfer_piod_write_i_16, PIOD_WRITE_I, 16, DATAIO) 2554BYTES_TRANSFER(bytes_transfer_piod_write_i_32, PIOD_WRITE_I, 32, DATAIO) 2555BYTES_TRANSFER(bytes_transfer_piod_write_i_64, PIOD_WRITE_I, 64, DATAIO) 2556 2557BYTES_TRANSFER(bytes_transfer_read_d, PT_READ_D, 32, DATA) 2558BYTES_TRANSFER(bytes_transfer_read_i, PT_READ_I, 32, DATA) 2559BYTES_TRANSFER(bytes_transfer_write_d, PT_WRITE_D, 32, DATA) 2560BYTES_TRANSFER(bytes_transfer_write_i, PT_WRITE_I, 32, DATA) 2561 2562// TEXT 2563 2564BYTES_TRANSFER(bytes_transfer_piod_read_d_8_text, PIOD_READ_D, 8, TEXTIO) 2565BYTES_TRANSFER(bytes_transfer_piod_read_d_16_text, PIOD_READ_D, 16, TEXTIO) 2566BYTES_TRANSFER(bytes_transfer_piod_read_d_32_text, PIOD_READ_D, 32, TEXTIO) 2567BYTES_TRANSFER(bytes_transfer_piod_read_d_64_text, PIOD_READ_D, 64, TEXTIO) 2568 2569BYTES_TRANSFER(bytes_transfer_piod_read_i_8_text, PIOD_READ_I, 8, TEXTIO) 2570BYTES_TRANSFER(bytes_transfer_piod_read_i_16_text, PIOD_READ_I, 16, TEXTIO) 2571BYTES_TRANSFER(bytes_transfer_piod_read_i_32_text, PIOD_READ_I, 32, TEXTIO) 2572BYTES_TRANSFER(bytes_transfer_piod_read_i_64_text, PIOD_READ_I, 64, TEXTIO) 2573 2574BYTES_TRANSFER(bytes_transfer_piod_write_d_8_text, PIOD_WRITE_D, 8, TEXTIO) 2575BYTES_TRANSFER(bytes_transfer_piod_write_d_16_text, PIOD_WRITE_D, 16, TEXTIO) 2576BYTES_TRANSFER(bytes_transfer_piod_write_d_32_text, PIOD_WRITE_D, 32, TEXTIO) 2577BYTES_TRANSFER(bytes_transfer_piod_write_d_64_text, PIOD_WRITE_D, 64, TEXTIO) 2578 2579BYTES_TRANSFER(bytes_transfer_piod_write_i_8_text, PIOD_WRITE_I, 8, TEXTIO) 2580BYTES_TRANSFER(bytes_transfer_piod_write_i_16_text, PIOD_WRITE_I, 16, TEXTIO) 2581BYTES_TRANSFER(bytes_transfer_piod_write_i_32_text, PIOD_WRITE_I, 32, TEXTIO) 2582BYTES_TRANSFER(bytes_transfer_piod_write_i_64_text, PIOD_WRITE_I, 64, TEXTIO) 2583 2584BYTES_TRANSFER(bytes_transfer_read_d_text, PT_READ_D, 32, TEXT) 2585BYTES_TRANSFER(bytes_transfer_read_i_text, PT_READ_I, 32, TEXT) 2586BYTES_TRANSFER(bytes_transfer_write_d_text, PT_WRITE_D, 32, TEXT) 2587BYTES_TRANSFER(bytes_transfer_write_i_text, PT_WRITE_I, 32, TEXT) 2588 2589// AUXV 2590 2591BYTES_TRANSFER(bytes_transfer_piod_read_auxv, PIOD_READ_AUXV, 4096, AUXV) 2592 2593/// ---------------------------------------------------------------------------- 2594 2595#if defined(HAVE_GPREGS) 2596ATF_TC(regs1); 2597ATF_TC_HEAD(regs1, tc) 2598{ 2599 atf_tc_set_md_var(tc, "descr", 2600 "Verify plain PT_GETREGS call without further steps"); 2601} 2602 2603ATF_TC_BODY(regs1, tc) 2604{ 2605 const int exitval = 5; 2606 const int sigval = SIGSTOP; 2607 pid_t child, wpid; 2608#if defined(TWAIT_HAVE_STATUS) 2609 int status; 2610#endif 2611 struct reg r; 2612 2613 DPRINTF("Before forking process PID=%d\n", getpid()); 2614 SYSCALL_REQUIRE((child = fork()) != -1); 2615 if (child == 0) { 2616 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2617 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2618 2619 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2620 FORKEE_ASSERT(raise(sigval) == 0); 2621 2622 DPRINTF("Before exiting of the child process\n"); 2623 _exit(exitval); 2624 } 2625 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2626 2627 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2628 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2629 2630 validate_status_stopped(status, sigval); 2631 2632 DPRINTF("Call GETREGS for the child process\n"); 2633 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 2634 2635 DPRINTF("Before resuming the child process where it left off and " 2636 "without signal to be sent\n"); 2637 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2638 2639 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2640 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2641 2642 validate_status_exited(status, exitval); 2643 2644 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2645 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2646} 2647#endif 2648 2649#if defined(HAVE_GPREGS) 2650ATF_TC(regs2); 2651ATF_TC_HEAD(regs2, tc) 2652{ 2653 atf_tc_set_md_var(tc, "descr", 2654 "Verify plain PT_GETREGS call and retrieve PC"); 2655} 2656 2657ATF_TC_BODY(regs2, tc) 2658{ 2659 const int exitval = 5; 2660 const int sigval = SIGSTOP; 2661 pid_t child, wpid; 2662#if defined(TWAIT_HAVE_STATUS) 2663 int status; 2664#endif 2665 struct reg r; 2666 2667 DPRINTF("Before forking process PID=%d\n", getpid()); 2668 SYSCALL_REQUIRE((child = fork()) != -1); 2669 if (child == 0) { 2670 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2671 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2672 2673 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2674 FORKEE_ASSERT(raise(sigval) == 0); 2675 2676 DPRINTF("Before exiting of the child process\n"); 2677 _exit(exitval); 2678 } 2679 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2680 2681 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2682 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2683 2684 validate_status_stopped(status, sigval); 2685 2686 DPRINTF("Call GETREGS for the child process\n"); 2687 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 2688 2689 DPRINTF("Retrieved PC=%" PRIxREGISTER "\n", PTRACE_REG_PC(&r)); 2690 2691 DPRINTF("Before resuming the child process where it left off and " 2692 "without signal to be sent\n"); 2693 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2694 2695 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2696 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2697 2698 validate_status_exited(status, exitval); 2699 2700 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2701 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2702} 2703#endif 2704 2705#if defined(HAVE_GPREGS) 2706ATF_TC(regs3); 2707ATF_TC_HEAD(regs3, tc) 2708{ 2709 atf_tc_set_md_var(tc, "descr", 2710 "Verify plain PT_GETREGS call and retrieve SP"); 2711} 2712 2713ATF_TC_BODY(regs3, tc) 2714{ 2715 const int exitval = 5; 2716 const int sigval = SIGSTOP; 2717 pid_t child, wpid; 2718#if defined(TWAIT_HAVE_STATUS) 2719 int status; 2720#endif 2721 struct reg r; 2722 2723 DPRINTF("Before forking process PID=%d\n", getpid()); 2724 SYSCALL_REQUIRE((child = fork()) != -1); 2725 if (child == 0) { 2726 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2727 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2728 2729 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2730 FORKEE_ASSERT(raise(sigval) == 0); 2731 2732 DPRINTF("Before exiting of the child process\n"); 2733 _exit(exitval); 2734 } 2735 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2736 2737 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2738 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2739 2740 validate_status_stopped(status, sigval); 2741 2742 DPRINTF("Call GETREGS for the child process\n"); 2743 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 2744 2745 DPRINTF("Retrieved SP=%" PRIxREGISTER "\n", PTRACE_REG_SP(&r)); 2746 2747 DPRINTF("Before resuming the child process where it left off and " 2748 "without signal to be sent\n"); 2749 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2750 2751 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2752 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2753 2754 validate_status_exited(status, exitval); 2755 2756 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2757 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2758} 2759#endif 2760 2761#if defined(HAVE_GPREGS) 2762ATF_TC(regs4); 2763ATF_TC_HEAD(regs4, tc) 2764{ 2765 atf_tc_set_md_var(tc, "descr", 2766 "Verify plain PT_GETREGS call and retrieve INTRV"); 2767} 2768 2769ATF_TC_BODY(regs4, tc) 2770{ 2771 const int exitval = 5; 2772 const int sigval = SIGSTOP; 2773 pid_t child, wpid; 2774#if defined(TWAIT_HAVE_STATUS) 2775 int status; 2776#endif 2777 struct reg r; 2778 2779 DPRINTF("Before forking process PID=%d\n", getpid()); 2780 SYSCALL_REQUIRE((child = fork()) != -1); 2781 if (child == 0) { 2782 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2783 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2784 2785 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2786 FORKEE_ASSERT(raise(sigval) == 0); 2787 2788 DPRINTF("Before exiting of the child process\n"); 2789 _exit(exitval); 2790 } 2791 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2792 2793 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2794 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2795 2796 validate_status_stopped(status, sigval); 2797 2798 DPRINTF("Call GETREGS for the child process\n"); 2799 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 2800 2801 DPRINTF("Retrieved INTRV=%" PRIxREGISTER "\n", PTRACE_REG_INTRV(&r)); 2802 2803 DPRINTF("Before resuming the child process where it left off and " 2804 "without signal to be sent\n"); 2805 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2806 2807 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2808 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2809 2810 validate_status_exited(status, exitval); 2811 2812 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2813 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2814} 2815#endif 2816 2817#if defined(HAVE_GPREGS) 2818ATF_TC(regs5); 2819ATF_TC_HEAD(regs5, tc) 2820{ 2821 atf_tc_set_md_var(tc, "descr", 2822 "Verify PT_GETREGS and PT_SETREGS calls without changing regs"); 2823} 2824 2825ATF_TC_BODY(regs5, tc) 2826{ 2827 const int exitval = 5; 2828 const int sigval = SIGSTOP; 2829 pid_t child, wpid; 2830#if defined(TWAIT_HAVE_STATUS) 2831 int status; 2832#endif 2833 struct reg r; 2834 2835 DPRINTF("Before forking process PID=%d\n", getpid()); 2836 SYSCALL_REQUIRE((child = fork()) != -1); 2837 if (child == 0) { 2838 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2839 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2840 2841 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2842 FORKEE_ASSERT(raise(sigval) == 0); 2843 2844 DPRINTF("Before exiting of the child process\n"); 2845 _exit(exitval); 2846 } 2847 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2848 2849 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2850 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2851 2852 validate_status_stopped(status, sigval); 2853 2854 DPRINTF("Call GETREGS for the child process\n"); 2855 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 2856 2857 DPRINTF("Call SETREGS for the child process (without changed regs)\n"); 2858 SYSCALL_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); 2859 2860 DPRINTF("Before resuming the child process where it left off and " 2861 "without signal to be sent\n"); 2862 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2863 2864 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2865 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2866 2867 validate_status_exited(status, exitval); 2868 2869 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2870 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2871} 2872#endif 2873 2874#if defined(HAVE_FPREGS) 2875ATF_TC(fpregs1); 2876ATF_TC_HEAD(fpregs1, tc) 2877{ 2878 atf_tc_set_md_var(tc, "descr", 2879 "Verify plain PT_GETFPREGS call without further steps"); 2880} 2881 2882ATF_TC_BODY(fpregs1, tc) 2883{ 2884 const int exitval = 5; 2885 const int sigval = SIGSTOP; 2886 pid_t child, wpid; 2887#if defined(TWAIT_HAVE_STATUS) 2888 int status; 2889#endif 2890 struct fpreg r; 2891 2892 DPRINTF("Before forking process PID=%d\n", getpid()); 2893 SYSCALL_REQUIRE((child = fork()) != -1); 2894 if (child == 0) { 2895 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2896 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2897 2898 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2899 FORKEE_ASSERT(raise(sigval) == 0); 2900 2901 DPRINTF("Before exiting of the child process\n"); 2902 _exit(exitval); 2903 } 2904 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2905 2906 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2907 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2908 2909 validate_status_stopped(status, sigval); 2910 2911 DPRINTF("Call GETFPREGS for the child process\n"); 2912 SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, &r, 0) != -1); 2913 2914 DPRINTF("Before resuming the child process where it left off and " 2915 "without signal to be sent\n"); 2916 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2917 2918 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2919 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2920 2921 validate_status_exited(status, exitval); 2922 2923 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2924 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2925} 2926#endif 2927 2928#if defined(HAVE_FPREGS) 2929ATF_TC(fpregs2); 2930ATF_TC_HEAD(fpregs2, tc) 2931{ 2932 atf_tc_set_md_var(tc, "descr", 2933 "Verify PT_GETFPREGS and PT_SETFPREGS calls without changing " 2934 "regs"); 2935} 2936 2937ATF_TC_BODY(fpregs2, tc) 2938{ 2939 const int exitval = 5; 2940 const int sigval = SIGSTOP; 2941 pid_t child, wpid; 2942#if defined(TWAIT_HAVE_STATUS) 2943 int status; 2944#endif 2945 struct fpreg r; 2946 2947 DPRINTF("Before forking process PID=%d\n", getpid()); 2948 SYSCALL_REQUIRE((child = fork()) != -1); 2949 if (child == 0) { 2950 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 2951 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 2952 2953 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 2954 FORKEE_ASSERT(raise(sigval) == 0); 2955 2956 DPRINTF("Before exiting of the child process\n"); 2957 _exit(exitval); 2958 } 2959 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 2960 2961 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2962 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2963 2964 validate_status_stopped(status, sigval); 2965 2966 DPRINTF("Call GETFPREGS for the child process\n"); 2967 SYSCALL_REQUIRE(ptrace(PT_GETFPREGS, child, &r, 0) != -1); 2968 2969 DPRINTF("Call SETFPREGS for the child (without changed regs)\n"); 2970 SYSCALL_REQUIRE(ptrace(PT_SETFPREGS, child, &r, 0) != -1); 2971 2972 DPRINTF("Before resuming the child process where it left off and " 2973 "without signal to be sent\n"); 2974 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 2975 2976 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2977 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 2978 2979 validate_status_exited(status, exitval); 2980 2981 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 2982 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 2983} 2984#endif 2985 2986#if defined(PT_STEP) 2987static void 2988ptrace_step(int N, int setstep) 2989{ 2990 const int exitval = 5; 2991 const int sigval = SIGSTOP; 2992 pid_t child, wpid; 2993#if defined(TWAIT_HAVE_STATUS) 2994 int status; 2995#endif 2996 int happy; 2997 2998#if defined(__arm__) 2999 /* PT_STEP not supported on arm 32-bit */ 3000 atf_tc_expect_fail("PR kern/52119"); 3001#endif 3002 3003 DPRINTF("Before forking process PID=%d\n", getpid()); 3004 SYSCALL_REQUIRE((child = fork()) != -1); 3005 if (child == 0) { 3006 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3007 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3008 3009 happy = check_happy(999); 3010 3011 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3012 FORKEE_ASSERT(raise(sigval) == 0); 3013 3014 FORKEE_ASSERT_EQ(happy, check_happy(999)); 3015 3016 DPRINTF("Before exiting of the child process\n"); 3017 _exit(exitval); 3018 } 3019 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3020 3021 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3022 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3023 3024 validate_status_stopped(status, sigval); 3025 3026 while (N --> 0) { 3027 if (setstep) { 3028 DPRINTF("Before resuming the child process where it " 3029 "left off and without signal to be sent (use " 3030 "PT_SETSTEP and PT_CONTINUE)\n"); 3031 SYSCALL_REQUIRE(ptrace(PT_SETSTEP, child, 0, 0) != -1); 3032 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) 3033 != -1); 3034 } else { 3035 DPRINTF("Before resuming the child process where it " 3036 "left off and without signal to be sent (use " 3037 "PT_STEP)\n"); 3038 SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) 3039 != -1); 3040 } 3041 3042 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3043 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), 3044 child); 3045 3046 validate_status_stopped(status, SIGTRAP); 3047 3048 if (setstep) { 3049 SYSCALL_REQUIRE(ptrace(PT_CLEARSTEP, child, 0, 0) != -1); 3050 } 3051 } 3052 3053 DPRINTF("Before resuming the child process where it left off and " 3054 "without signal to be sent\n"); 3055 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3056 3057 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3058 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3059 3060 validate_status_exited(status, exitval); 3061 3062 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3063 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3064} 3065#endif 3066 3067#if defined(PT_STEP) 3068ATF_TC(step1); 3069ATF_TC_HEAD(step1, tc) 3070{ 3071 atf_tc_set_md_var(tc, "descr", 3072 "Verify single PT_STEP call"); 3073} 3074 3075ATF_TC_BODY(step1, tc) 3076{ 3077 ptrace_step(1, 0); 3078} 3079#endif 3080 3081#if defined(PT_STEP) 3082ATF_TC(step2); 3083ATF_TC_HEAD(step2, tc) 3084{ 3085 atf_tc_set_md_var(tc, "descr", 3086 "Verify PT_STEP called twice"); 3087} 3088 3089ATF_TC_BODY(step2, tc) 3090{ 3091 ptrace_step(2, 0); 3092} 3093#endif 3094 3095#if defined(PT_STEP) 3096ATF_TC(step3); 3097ATF_TC_HEAD(step3, tc) 3098{ 3099 atf_tc_set_md_var(tc, "descr", 3100 "Verify PT_STEP called three times"); 3101} 3102 3103ATF_TC_BODY(step3, tc) 3104{ 3105 ptrace_step(3, 0); 3106} 3107#endif 3108 3109#if defined(PT_STEP) 3110ATF_TC(step4); 3111ATF_TC_HEAD(step4, tc) 3112{ 3113 atf_tc_set_md_var(tc, "descr", 3114 "Verify PT_STEP called four times"); 3115} 3116 3117ATF_TC_BODY(step4, tc) 3118{ 3119 ptrace_step(4, 0); 3120} 3121#endif 3122 3123#if defined(PT_STEP) 3124ATF_TC(setstep1); 3125ATF_TC_HEAD(setstep1, tc) 3126{ 3127 atf_tc_set_md_var(tc, "descr", 3128 "Verify single PT_SETSTEP call"); 3129} 3130 3131ATF_TC_BODY(setstep1, tc) 3132{ 3133 ptrace_step(1, 1); 3134} 3135#endif 3136 3137#if defined(PT_STEP) 3138ATF_TC(setstep2); 3139ATF_TC_HEAD(setstep2, tc) 3140{ 3141 atf_tc_set_md_var(tc, "descr", 3142 "Verify PT_SETSTEP called twice"); 3143} 3144 3145ATF_TC_BODY(setstep2, tc) 3146{ 3147 ptrace_step(2, 1); 3148} 3149#endif 3150 3151#if defined(PT_STEP) 3152ATF_TC(setstep3); 3153ATF_TC_HEAD(setstep3, tc) 3154{ 3155 atf_tc_set_md_var(tc, "descr", 3156 "Verify PT_SETSTEP called three times"); 3157} 3158 3159ATF_TC_BODY(setstep3, tc) 3160{ 3161 ptrace_step(3, 1); 3162} 3163#endif 3164 3165#if defined(PT_STEP) 3166ATF_TC(setstep4); 3167ATF_TC_HEAD(setstep4, tc) 3168{ 3169 atf_tc_set_md_var(tc, "descr", 3170 "Verify PT_SETSTEP called four times"); 3171} 3172 3173ATF_TC_BODY(setstep4, tc) 3174{ 3175 ptrace_step(4, 1); 3176} 3177#endif 3178 3179ATF_TC(kill1); 3180ATF_TC_HEAD(kill1, tc) 3181{ 3182 atf_tc_set_md_var(tc, "descr", 3183 "Verify that PT_CONTINUE with SIGKILL terminates child"); 3184} 3185 3186ATF_TC_BODY(kill1, tc) 3187{ 3188 const int sigval = SIGSTOP, sigsent = SIGKILL; 3189 pid_t child, wpid; 3190#if defined(TWAIT_HAVE_STATUS) 3191 int status; 3192#endif 3193 3194 DPRINTF("Before forking process PID=%d\n", getpid()); 3195 SYSCALL_REQUIRE((child = fork()) != -1); 3196 if (child == 0) { 3197 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3198 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3199 3200 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3201 FORKEE_ASSERT(raise(sigval) == 0); 3202 3203 /* NOTREACHED */ 3204 FORKEE_ASSERTX(0 && 3205 "Child should be terminated by a signal from its parent"); 3206 } 3207 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3208 3209 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3210 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3211 3212 validate_status_stopped(status, sigval); 3213 3214 DPRINTF("Before resuming the child process where it left off and " 3215 "without signal to be sent\n"); 3216 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigsent) != -1); 3217 3218 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3219 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3220 3221 validate_status_signaled(status, sigsent, 0); 3222 3223 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3224 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3225} 3226 3227ATF_TC(kill2); 3228ATF_TC_HEAD(kill2, tc) 3229{ 3230 atf_tc_set_md_var(tc, "descr", 3231 "Verify that PT_KILL terminates child"); 3232} 3233 3234ATF_TC_BODY(kill2, tc) 3235{ 3236 const int sigval = SIGSTOP; 3237 pid_t child, wpid; 3238#if defined(TWAIT_HAVE_STATUS) 3239 int status; 3240#endif 3241 3242 DPRINTF("Before forking process PID=%d\n", getpid()); 3243 SYSCALL_REQUIRE((child = fork()) != -1); 3244 if (child == 0) { 3245 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3246 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3247 3248 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3249 FORKEE_ASSERT(raise(sigval) == 0); 3250 3251 /* NOTREACHED */ 3252 FORKEE_ASSERTX(0 && 3253 "Child should be terminated by a signal from its parent"); 3254 } 3255 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3256 3257 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3258 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3259 3260 validate_status_stopped(status, sigval); 3261 3262 DPRINTF("Before resuming the child process where it left off and " 3263 "without signal to be sent\n"); 3264 SYSCALL_REQUIRE(ptrace(PT_KILL, child, (void*)1, 0) != -1); 3265 3266 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3267 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3268 3269 validate_status_signaled(status, SIGKILL, 0); 3270 3271 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3272 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3273} 3274 3275ATF_TC(lwpinfo1); 3276ATF_TC_HEAD(lwpinfo1, tc) 3277{ 3278 atf_tc_set_md_var(tc, "descr", 3279 "Verify basic LWPINFO call for single thread (PT_TRACE_ME)"); 3280} 3281 3282ATF_TC_BODY(lwpinfo1, tc) 3283{ 3284 const int exitval = 5; 3285 const int sigval = SIGSTOP; 3286 pid_t child, wpid; 3287#if defined(TWAIT_HAVE_STATUS) 3288 int status; 3289#endif 3290 struct ptrace_lwpinfo info = {0, 0}; 3291 3292 DPRINTF("Before forking process PID=%d\n", getpid()); 3293 SYSCALL_REQUIRE((child = fork()) != -1); 3294 if (child == 0) { 3295 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3296 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3297 3298 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3299 FORKEE_ASSERT(raise(sigval) == 0); 3300 3301 DPRINTF("Before exiting of the child process\n"); 3302 _exit(exitval); 3303 } 3304 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3305 3306 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3307 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3308 3309 validate_status_stopped(status, sigval); 3310 3311 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 3312 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &info, sizeof(info)) != -1); 3313 3314 DPRINTF("Assert that there exists a thread\n"); 3315 ATF_REQUIRE(info.pl_lwpid > 0); 3316 3317 DPRINTF("Assert that lwp thread %d received event PL_EVENT_SIGNAL\n", 3318 info.pl_lwpid); 3319 ATF_REQUIRE_EQ_MSG(info.pl_event, PL_EVENT_SIGNAL, 3320 "Received event %d != expected event %d", 3321 info.pl_event, PL_EVENT_SIGNAL); 3322 3323 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 3324 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &info, sizeof(info)) != -1); 3325 3326 DPRINTF("Assert that there are no more lwp threads in child\n"); 3327 ATF_REQUIRE_EQ(info.pl_lwpid, 0); 3328 3329 DPRINTF("Before resuming the child process where it left off and " 3330 "without signal to be sent\n"); 3331 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3332 3333 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3334 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3335 3336 validate_status_exited(status, exitval); 3337 3338 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3339 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3340} 3341 3342#if defined(TWAIT_HAVE_PID) 3343ATF_TC(lwpinfo2); 3344ATF_TC_HEAD(lwpinfo2, tc) 3345{ 3346 atf_tc_set_md_var(tc, "descr", 3347 "Verify basic LWPINFO call for single thread (PT_ATTACH from " 3348 "tracer)"); 3349} 3350 3351ATF_TC_BODY(lwpinfo2, tc) 3352{ 3353 struct msg_fds parent_tracee, parent_tracer; 3354 const int exitval_tracee = 5; 3355 const int exitval_tracer = 10; 3356 pid_t tracee, tracer, wpid; 3357 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 3358#if defined(TWAIT_HAVE_STATUS) 3359 int status; 3360#endif 3361 struct ptrace_lwpinfo info = {0, 0}; 3362 3363 DPRINTF("Spawn tracee\n"); 3364 SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0); 3365 SYSCALL_REQUIRE(msg_open(&parent_tracer) == 0); 3366 tracee = atf_utils_fork(); 3367 if (tracee == 0) { 3368 3369 /* Wait for message from the parent */ 3370 CHILD_TO_PARENT("tracee ready", parent_tracee, msg); 3371 CHILD_FROM_PARENT("tracee exit", parent_tracee, msg); 3372 3373 _exit(exitval_tracee); 3374 } 3375 PARENT_FROM_CHILD("tracee ready", parent_tracee, msg); 3376 3377 DPRINTF("Spawn debugger\n"); 3378 tracer = atf_utils_fork(); 3379 if (tracer == 0) { 3380 /* No IPC to communicate with the child */ 3381 DPRINTF("Before calling PT_ATTACH from tracee %d\n", getpid()); 3382 FORKEE_ASSERT(ptrace(PT_ATTACH, tracee, NULL, 0) != -1); 3383 3384 /* Wait for tracee and assert that it was stopped w/ SIGSTOP */ 3385 FORKEE_REQUIRE_SUCCESS( 3386 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 3387 3388 forkee_status_stopped(status, SIGSTOP); 3389 3390 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 3391 FORKEE_ASSERT(ptrace(PT_LWPINFO, tracee, &info, sizeof(info)) 3392 != -1); 3393 3394 DPRINTF("Assert that there exists a thread\n"); 3395 FORKEE_ASSERTX(info.pl_lwpid > 0); 3396 3397 DPRINTF("Assert that lwp thread %d received event " 3398 "PL_EVENT_SIGNAL\n", info.pl_lwpid); 3399 FORKEE_ASSERT_EQ(info.pl_event, PL_EVENT_SIGNAL); 3400 3401 DPRINTF("Before calling ptrace(2) with PT_LWPINFO for child\n"); 3402 FORKEE_ASSERT(ptrace(PT_LWPINFO, tracee, &info, sizeof(info)) 3403 != -1); 3404 3405 DPRINTF("Assert that there are no more lwp threads in child\n"); 3406 FORKEE_ASSERTX(info.pl_lwpid == 0); 3407 3408 /* Resume tracee with PT_CONTINUE */ 3409 FORKEE_ASSERT(ptrace(PT_CONTINUE, tracee, (void *)1, 0) != -1); 3410 3411 /* Inform parent that tracer has attached to tracee */ 3412 CHILD_TO_PARENT("tracer ready", parent_tracer, msg); 3413 /* Wait for parent */ 3414 CHILD_FROM_PARENT("tracer wait", parent_tracer, msg); 3415 3416 /* Wait for tracee and assert that it exited */ 3417 FORKEE_REQUIRE_SUCCESS( 3418 wpid = TWAIT_GENERIC(tracee, &status, 0), tracee); 3419 3420 forkee_status_exited(status, exitval_tracee); 3421 3422 DPRINTF("Before exiting of the tracer process\n"); 3423 _exit(exitval_tracer); 3424 } 3425 3426 DPRINTF("Wait for the tracer to attach to the tracee\n"); 3427 PARENT_FROM_CHILD("tracer ready", parent_tracer, msg); 3428 3429 DPRINTF("Resume the tracee and let it exit\n"); 3430 PARENT_TO_CHILD("tracee exit", parent_tracee, msg); 3431 3432 DPRINTF("Detect that tracee is zombie\n"); 3433 await_zombie(tracee); 3434 3435 DPRINTF("Assert that there is no status about tracee - " 3436 "Tracer must detect zombie first - calling %s()\n", TWAIT_FNAME); 3437 TWAIT_REQUIRE_SUCCESS( 3438 wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 0); 3439 3440 DPRINTF("Resume the tracer and let it detect exited tracee\n"); 3441 PARENT_TO_CHILD("tracer wait", parent_tracer, msg); 3442 3443 DPRINTF("Wait for tracer to finish its job and exit - calling %s()\n", 3444 TWAIT_FNAME); 3445 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracer, &status, 0), 3446 tracer); 3447 3448 validate_status_exited(status, exitval_tracer); 3449 3450 DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n", 3451 TWAIT_FNAME); 3452 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG), 3453 tracee); 3454 3455 validate_status_exited(status, exitval_tracee); 3456 3457 msg_close(&parent_tracer); 3458 msg_close(&parent_tracee); 3459} 3460#endif 3461 3462ATF_TC(siginfo1); 3463ATF_TC_HEAD(siginfo1, tc) 3464{ 3465 atf_tc_set_md_var(tc, "descr", 3466 "Verify basic PT_GET_SIGINFO call for SIGTRAP from tracee"); 3467} 3468 3469ATF_TC_BODY(siginfo1, tc) 3470{ 3471 const int exitval = 5; 3472 const int sigval = SIGTRAP; 3473 pid_t child, wpid; 3474#if defined(TWAIT_HAVE_STATUS) 3475 int status; 3476#endif 3477 struct ptrace_siginfo info; 3478 memset(&info, 0, sizeof(info)); 3479 3480 DPRINTF("Before forking process PID=%d\n", getpid()); 3481 SYSCALL_REQUIRE((child = fork()) != -1); 3482 if (child == 0) { 3483 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3484 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3485 3486 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3487 FORKEE_ASSERT(raise(sigval) == 0); 3488 3489 DPRINTF("Before exiting of the child process\n"); 3490 _exit(exitval); 3491 } 3492 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3493 3494 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3495 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3496 3497 validate_status_stopped(status, sigval); 3498 3499 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3500 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3501 3502 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 3503 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 3504 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 3505 info.psi_siginfo.si_errno); 3506 3507 DPRINTF("Before resuming the child process where it left off and " 3508 "without signal to be sent\n"); 3509 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3510 3511 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3512 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3513 3514 validate_status_exited(status, exitval); 3515 3516 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3517 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3518} 3519 3520ATF_TC(siginfo2); 3521ATF_TC_HEAD(siginfo2, tc) 3522{ 3523 atf_tc_set_md_var(tc, "descr", 3524 "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls without " 3525 "modification of SIGINT from tracee"); 3526} 3527 3528static int siginfo2_caught = 0; 3529 3530static void 3531siginfo2_sighandler(int sig) 3532{ 3533 FORKEE_ASSERT_EQ(sig, SIGINT); 3534 3535 ++siginfo2_caught; 3536} 3537 3538ATF_TC_BODY(siginfo2, tc) 3539{ 3540 const int exitval = 5; 3541 const int sigval = SIGINT; 3542 pid_t child, wpid; 3543 struct sigaction sa; 3544#if defined(TWAIT_HAVE_STATUS) 3545 int status; 3546#endif 3547 struct ptrace_siginfo info; 3548 memset(&info, 0, sizeof(info)); 3549 3550 DPRINTF("Before forking process PID=%d\n", getpid()); 3551 SYSCALL_REQUIRE((child = fork()) != -1); 3552 if (child == 0) { 3553 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3554 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3555 3556 sa.sa_handler = siginfo2_sighandler; 3557 sa.sa_flags = SA_SIGINFO; 3558 sigemptyset(&sa.sa_mask); 3559 3560 FORKEE_ASSERT(sigaction(sigval, &sa, NULL) != -1); 3561 3562 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3563 FORKEE_ASSERT(raise(sigval) == 0); 3564 3565 FORKEE_ASSERT_EQ(siginfo2_caught, 1); 3566 3567 DPRINTF("Before exiting of the child process\n"); 3568 _exit(exitval); 3569 } 3570 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3571 3572 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3573 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3574 3575 validate_status_stopped(status, sigval); 3576 3577 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3578 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3579 3580 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 3581 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 3582 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 3583 info.psi_siginfo.si_errno); 3584 3585 DPRINTF("Before calling ptrace(2) with PT_SET_SIGINFO for child\n"); 3586 SYSCALL_REQUIRE( 3587 ptrace(PT_SET_SIGINFO, child, &info, sizeof(info)) != -1); 3588 3589 DPRINTF("Before resuming the child process where it left off and " 3590 "without signal to be sent\n"); 3591 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigval) != -1); 3592 3593 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3594 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3595 3596 validate_status_exited(status, exitval); 3597 3598 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3599 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3600} 3601 3602ATF_TC(siginfo3); 3603ATF_TC_HEAD(siginfo3, tc) 3604{ 3605 atf_tc_set_md_var(tc, "descr", 3606 "Verify basic PT_GET_SIGINFO and PT_SET_SIGINFO calls with " 3607 "setting signal to new value"); 3608} 3609 3610static int siginfo3_caught = 0; 3611 3612static void 3613siginfo3_sigaction(int sig, siginfo_t *info, void *ctx) 3614{ 3615 FORKEE_ASSERT_EQ(sig, SIGTRAP); 3616 3617 FORKEE_ASSERT_EQ(info->si_signo, SIGTRAP); 3618 FORKEE_ASSERT_EQ(info->si_code, TRAP_BRKPT); 3619 3620 ++siginfo3_caught; 3621} 3622 3623ATF_TC_BODY(siginfo3, tc) 3624{ 3625 const int exitval = 5; 3626 const int sigval = SIGINT; 3627 const int sigfaked = SIGTRAP; 3628 const int sicodefaked = TRAP_BRKPT; 3629 pid_t child, wpid; 3630 struct sigaction sa; 3631#if defined(TWAIT_HAVE_STATUS) 3632 int status; 3633#endif 3634 struct ptrace_siginfo info; 3635 memset(&info, 0, sizeof(info)); 3636 3637 DPRINTF("Before forking process PID=%d\n", getpid()); 3638 SYSCALL_REQUIRE((child = fork()) != -1); 3639 if (child == 0) { 3640 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3641 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3642 3643 sa.sa_sigaction = siginfo3_sigaction; 3644 sa.sa_flags = SA_SIGINFO; 3645 sigemptyset(&sa.sa_mask); 3646 3647 FORKEE_ASSERT(sigaction(sigfaked, &sa, NULL) != -1); 3648 3649 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3650 FORKEE_ASSERT(raise(sigval) == 0); 3651 3652 FORKEE_ASSERT_EQ(siginfo3_caught, 1); 3653 3654 DPRINTF("Before exiting of the child process\n"); 3655 _exit(exitval); 3656 } 3657 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3658 3659 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3660 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3661 3662 validate_status_stopped(status, sigval); 3663 3664 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3665 SYSCALL_REQUIRE( 3666 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3667 3668 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 3669 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 3670 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 3671 info.psi_siginfo.si_errno); 3672 3673 DPRINTF("Before setting new faked signal to signo=%d si_code=%d\n", 3674 sigfaked, sicodefaked); 3675 info.psi_siginfo.si_signo = sigfaked; 3676 info.psi_siginfo.si_code = sicodefaked; 3677 3678 DPRINTF("Before calling ptrace(2) with PT_SET_SIGINFO for child\n"); 3679 SYSCALL_REQUIRE( 3680 ptrace(PT_SET_SIGINFO, child, &info, sizeof(info)) != -1); 3681 3682 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3683 SYSCALL_REQUIRE( 3684 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3685 3686 DPRINTF("Before checking siginfo_t\n"); 3687 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigfaked); 3688 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, sicodefaked); 3689 3690 DPRINTF("Before resuming the child process where it left off and " 3691 "without signal to be sent\n"); 3692 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, sigfaked) != -1); 3693 3694 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3695 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3696 3697 validate_status_exited(status, exitval); 3698 3699 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3700 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3701} 3702 3703ATF_TC(siginfo4); 3704ATF_TC_HEAD(siginfo4, tc) 3705{ 3706 atf_tc_set_md_var(tc, "descr", 3707 "Detect SIGTRAP TRAP_EXEC from tracee"); 3708} 3709 3710ATF_TC_BODY(siginfo4, tc) 3711{ 3712 const int sigval = SIGTRAP; 3713 pid_t child, wpid; 3714#if defined(TWAIT_HAVE_STATUS) 3715 int status; 3716#endif 3717 3718 struct ptrace_siginfo info; 3719 memset(&info, 0, sizeof(info)); 3720 3721 DPRINTF("Before forking process PID=%d\n", getpid()); 3722 SYSCALL_REQUIRE((child = fork()) != -1); 3723 if (child == 0) { 3724 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3725 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3726 3727 DPRINTF("Before calling execve(2) from child\n"); 3728 execlp("/bin/echo", "/bin/echo", NULL); 3729 3730 FORKEE_ASSERT(0 && "Not reached"); 3731 } 3732 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3733 3734 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3735 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3736 3737 validate_status_stopped(status, sigval); 3738 3739 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3740 SYSCALL_REQUIRE( 3741 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3742 3743 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 3744 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 3745 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 3746 info.psi_siginfo.si_errno); 3747 3748 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 3749 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); 3750 3751 DPRINTF("Before resuming the child process where it left off and " 3752 "without signal to be sent\n"); 3753 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3754 3755 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3756 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3757 3758 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3759 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3760} 3761 3762#if defined(TWAIT_HAVE_PID) 3763ATF_TC(siginfo5); 3764ATF_TC_HEAD(siginfo5, tc) 3765{ 3766 atf_tc_set_md_var(tc, "descr", 3767 "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK " 3768 "set to PTRACE_FORK and reports correct signal information"); 3769} 3770 3771ATF_TC_BODY(siginfo5, tc) 3772{ 3773 const int exitval = 5; 3774 const int exitval2 = 15; 3775 const int sigval = SIGSTOP; 3776 pid_t child, child2, wpid; 3777#if defined(TWAIT_HAVE_STATUS) 3778 int status; 3779#endif 3780 ptrace_state_t state; 3781 const int slen = sizeof(state); 3782 ptrace_event_t event; 3783 const int elen = sizeof(event); 3784 struct ptrace_siginfo info; 3785 3786 memset(&info, 0, sizeof(info)); 3787 3788 DPRINTF("Before forking process PID=%d\n", getpid()); 3789 SYSCALL_REQUIRE((child = fork()) != -1); 3790 if (child == 0) { 3791 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3792 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3793 3794 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3795 FORKEE_ASSERT(raise(sigval) == 0); 3796 3797 FORKEE_ASSERT((child2 = fork()) != -1); 3798 3799 if (child2 == 0) 3800 _exit(exitval2); 3801 3802 FORKEE_REQUIRE_SUCCESS 3803 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 3804 3805 forkee_status_exited(status, exitval2); 3806 3807 DPRINTF("Before exiting of the child process\n"); 3808 _exit(exitval); 3809 } 3810 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3811 3812 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3813 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3814 3815 validate_status_stopped(status, sigval); 3816 3817 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3818 SYSCALL_REQUIRE( 3819 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3820 3821 DPRINTF("Before checking siginfo_t\n"); 3822 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 3823 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 3824 3825 DPRINTF("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child); 3826 event.pe_set_event = PTRACE_FORK; 3827 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 3828 3829 DPRINTF("Before resuming the child process where it left off and " 3830 "without signal to be sent\n"); 3831 DPRINTF("We expect two SIGTRAP events, for child %d (TRAP_CHLD, " 3832 "pe_report_event=PTRACE_FORK, state.pe_other_pid=child2) and " 3833 "for child2 (TRAP_CHLD, pe_report_event=PTRACE_FORK, " 3834 "state.pe_other_pid=child)\n", child); 3835 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3836 3837 DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, child); 3838 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3839 3840 validate_status_stopped(status, SIGTRAP); 3841 3842 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3843 SYSCALL_REQUIRE( 3844 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3845 3846 DPRINTF("Before checking siginfo_t\n"); 3847 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 3848 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_CHLD); 3849 3850 SYSCALL_REQUIRE( 3851 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 3852 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 3853 3854 child2 = state.pe_other_pid; 3855 DPRINTF("Reported PTRACE_FORK event with forkee %d\n", child2); 3856 3857 DPRINTF("Before calling %s() for the forkee %d of the child %d\n", 3858 TWAIT_FNAME, child2, child); 3859 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 3860 child2); 3861 3862 validate_status_stopped(status, SIGTRAP); 3863 3864 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3865 SYSCALL_REQUIRE( 3866 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3867 3868 DPRINTF("Before checking siginfo_t\n"); 3869 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 3870 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_CHLD); 3871 3872 SYSCALL_REQUIRE( 3873 ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 3874 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 3875 ATF_REQUIRE_EQ(state.pe_other_pid, child); 3876 3877 DPRINTF("Before resuming the forkee process where it left off and " 3878 "without signal to be sent\n"); 3879 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 3880 3881 DPRINTF("Before resuming the child process where it left off and " 3882 "without signal to be sent\n"); 3883 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3884 3885 DPRINTF("Before calling %s() for the forkee - expected exited\n", 3886 TWAIT_FNAME); 3887 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 3888 child2); 3889 3890 validate_status_exited(status, exitval2); 3891 3892 DPRINTF("Before calling %s() for the forkee - expected no process\n", 3893 TWAIT_FNAME); 3894 TWAIT_REQUIRE_FAILURE(ECHILD, 3895 wpid = TWAIT_GENERIC(child2, &status, 0)); 3896 3897 DPRINTF("Before calling %s() for the child - expected stopped " 3898 "SIGCHLD\n", TWAIT_FNAME); 3899 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3900 3901 validate_status_stopped(status, SIGCHLD); 3902 3903 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3904 SYSCALL_REQUIRE( 3905 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3906 3907 DPRINTF("Before checking siginfo_t\n"); 3908 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGCHLD); 3909 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, CLD_EXITED); 3910 3911 DPRINTF("Before resuming the child process where it left off and " 3912 "without signal to be sent\n"); 3913 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 3914 3915 DPRINTF("Before calling %s() for the child - expected exited\n", 3916 TWAIT_FNAME); 3917 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3918 3919 validate_status_exited(status, exitval); 3920 3921 DPRINTF("Before calling %s() for the child - expected no process\n", 3922 TWAIT_FNAME); 3923 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 3924} 3925#endif 3926 3927#if defined(PT_STEP) 3928ATF_TC(siginfo6); 3929ATF_TC_HEAD(siginfo6, tc) 3930{ 3931 atf_tc_set_md_var(tc, "descr", 3932 "Verify single PT_STEP call with signal information check"); 3933} 3934 3935ATF_TC_BODY(siginfo6, tc) 3936{ 3937 const int exitval = 5; 3938 const int sigval = SIGSTOP; 3939 pid_t child, wpid; 3940#if defined(TWAIT_HAVE_STATUS) 3941 int status; 3942#endif 3943 int happy; 3944 struct ptrace_siginfo info; 3945 3946#if defined(__arm__) 3947 /* PT_STEP not supported on arm 32-bit */ 3948 atf_tc_expect_fail("PR kern/52119"); 3949#endif 3950 3951 memset(&info, 0, sizeof(info)); 3952 3953 DPRINTF("Before forking process PID=%d\n", getpid()); 3954 SYSCALL_REQUIRE((child = fork()) != -1); 3955 if (child == 0) { 3956 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 3957 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 3958 3959 happy = check_happy(100); 3960 3961 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 3962 FORKEE_ASSERT(raise(sigval) == 0); 3963 3964 FORKEE_ASSERT_EQ(happy, check_happy(100)); 3965 3966 DPRINTF("Before exiting of the child process\n"); 3967 _exit(exitval); 3968 } 3969 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 3970 3971 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3972 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3973 3974 validate_status_stopped(status, sigval); 3975 3976 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3977 SYSCALL_REQUIRE( 3978 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3979 3980 DPRINTF("Before checking siginfo_t\n"); 3981 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigval); 3982 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, SI_LWP); 3983 3984 DPRINTF("Before resuming the child process where it left off and " 3985 "without signal to be sent (use PT_STEP)\n"); 3986 SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1); 3987 3988 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 3989 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 3990 3991 validate_status_stopped(status, SIGTRAP); 3992 3993 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 3994 SYSCALL_REQUIRE( 3995 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 3996 3997 DPRINTF("Before checking siginfo_t\n"); 3998 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 3999 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_TRACE); 4000 4001 DPRINTF("Before resuming the child process where it left off and " 4002 "without signal to be sent\n"); 4003 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4004 4005 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4006 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4007 4008 validate_status_exited(status, exitval); 4009 4010 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4011 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4012} 4013#endif 4014 4015volatile lwpid_t the_lwp_id = 0; 4016 4017static void 4018lwp_main_func(void *arg) 4019{ 4020 the_lwp_id = _lwp_self(); 4021 _lwp_exit(); 4022} 4023 4024ATF_TC(lwp_create1); 4025ATF_TC_HEAD(lwp_create1, tc) 4026{ 4027 atf_tc_set_md_var(tc, "descr", 4028 "Verify that 1 LWP creation is intercepted by ptrace(2) with " 4029 "EVENT_MASK set to PTRACE_LWP_CREATE"); 4030} 4031 4032ATF_TC_BODY(lwp_create1, tc) 4033{ 4034 const int exitval = 5; 4035 const int sigval = SIGSTOP; 4036 pid_t child, wpid; 4037#if defined(TWAIT_HAVE_STATUS) 4038 int status; 4039#endif 4040 ptrace_state_t state; 4041 const int slen = sizeof(state); 4042 ptrace_event_t event; 4043 const int elen = sizeof(event); 4044 ucontext_t uc; 4045 lwpid_t lid; 4046 static const size_t ssize = 16*1024; 4047 void *stack; 4048 4049 DPRINTF("Before forking process PID=%d\n", getpid()); 4050 SYSCALL_REQUIRE((child = fork()) != -1); 4051 if (child == 0) { 4052 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4053 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4054 4055 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4056 FORKEE_ASSERT(raise(sigval) == 0); 4057 4058 DPRINTF("Before allocating memory for stack in child\n"); 4059 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 4060 4061 DPRINTF("Before making context for new lwp in child\n"); 4062 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 4063 4064 DPRINTF("Before creating new in child\n"); 4065 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 4066 4067 DPRINTF("Before waiting for lwp %d to exit\n", lid); 4068 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 4069 4070 DPRINTF("Before verifying that reported %d and running lid %d " 4071 "are the same\n", lid, the_lwp_id); 4072 FORKEE_ASSERT_EQ(lid, the_lwp_id); 4073 4074 DPRINTF("Before exiting of the child process\n"); 4075 _exit(exitval); 4076 } 4077 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4078 4079 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4080 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4081 4082 validate_status_stopped(status, sigval); 4083 4084 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 4085 event.pe_set_event = PTRACE_LWP_CREATE; 4086 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 4087 4088 DPRINTF("Before resuming the child process where it left off and " 4089 "without signal to be sent\n"); 4090 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4091 4092 DPRINTF("Before calling %s() for the child - expected stopped " 4093 "SIGTRAP\n", TWAIT_FNAME); 4094 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4095 4096 validate_status_stopped(status, SIGTRAP); 4097 4098 SYSCALL_REQUIRE( 4099 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 4100 4101 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE); 4102 4103 lid = state.pe_lwp; 4104 DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); 4105 4106 DPRINTF("Before resuming the child process where it left off and " 4107 "without signal to be sent\n"); 4108 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4109 4110 DPRINTF("Before calling %s() for the child - expected exited\n", 4111 TWAIT_FNAME); 4112 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4113 4114 validate_status_exited(status, exitval); 4115 4116 DPRINTF("Before calling %s() for the child - expected no process\n", 4117 TWAIT_FNAME); 4118 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4119} 4120 4121ATF_TC(lwp_exit1); 4122ATF_TC_HEAD(lwp_exit1, tc) 4123{ 4124 atf_tc_set_md_var(tc, "descr", 4125 "Verify that 1 LWP creation is intercepted by ptrace(2) with " 4126 "EVENT_MASK set to PTRACE_LWP_EXIT"); 4127} 4128 4129ATF_TC_BODY(lwp_exit1, tc) 4130{ 4131 const int exitval = 5; 4132 const int sigval = SIGSTOP; 4133 pid_t child, wpid; 4134#if defined(TWAIT_HAVE_STATUS) 4135 int status; 4136#endif 4137 ptrace_state_t state; 4138 const int slen = sizeof(state); 4139 ptrace_event_t event; 4140 const int elen = sizeof(event); 4141 ucontext_t uc; 4142 lwpid_t lid; 4143 static const size_t ssize = 16*1024; 4144 void *stack; 4145 4146 DPRINTF("Before forking process PID=%d\n", getpid()); 4147 SYSCALL_REQUIRE((child = fork()) != -1); 4148 if (child == 0) { 4149 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4150 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4151 4152 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4153 FORKEE_ASSERT(raise(sigval) == 0); 4154 4155 DPRINTF("Before allocating memory for stack in child\n"); 4156 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 4157 4158 DPRINTF("Before making context for new lwp in child\n"); 4159 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 4160 4161 DPRINTF("Before creating new in child\n"); 4162 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 4163 4164 DPRINTF("Before waiting for lwp %d to exit\n", lid); 4165 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 4166 4167 DPRINTF("Before verifying that reported %d and running lid %d " 4168 "are the same\n", lid, the_lwp_id); 4169 FORKEE_ASSERT_EQ(lid, the_lwp_id); 4170 4171 DPRINTF("Before exiting of the child process\n"); 4172 _exit(exitval); 4173 } 4174 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4175 4176 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4177 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4178 4179 validate_status_stopped(status, sigval); 4180 4181 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 4182 event.pe_set_event = PTRACE_LWP_EXIT; 4183 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 4184 4185 DPRINTF("Before resuming the child process where it left off and " 4186 "without signal to be sent\n"); 4187 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4188 4189 DPRINTF("Before calling %s() for the child - expected stopped " 4190 "SIGTRAP\n", TWAIT_FNAME); 4191 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4192 4193 validate_status_stopped(status, SIGTRAP); 4194 4195 SYSCALL_REQUIRE( 4196 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 4197 4198 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT); 4199 4200 lid = state.pe_lwp; 4201 DPRINTF("Reported PTRACE_LWP_EXIT event with lid %d\n", lid); 4202 4203 DPRINTF("Before resuming the child process where it left off and " 4204 "without signal to be sent\n"); 4205 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4206 4207 DPRINTF("Before calling %s() for the child - expected exited\n", 4208 TWAIT_FNAME); 4209 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4210 4211 validate_status_exited(status, exitval); 4212 4213 DPRINTF("Before calling %s() for the child - expected no process\n", 4214 TWAIT_FNAME); 4215 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4216} 4217 4218ATF_TC(signal1); 4219ATF_TC_HEAD(signal1, tc) 4220{ 4221 atf_tc_set_md_var(tc, "descr", 4222 "Verify that masking single unrelated signal does not stop tracer " 4223 "from catching other signals"); 4224} 4225 4226ATF_TC_BODY(signal1, tc) 4227{ 4228 const int exitval = 5; 4229 const int sigval = SIGSTOP; 4230 const int sigmasked = SIGTRAP; 4231 const int signotmasked = SIGINT; 4232 pid_t child, wpid; 4233#if defined(TWAIT_HAVE_STATUS) 4234 int status; 4235#endif 4236 sigset_t intmask; 4237 4238 DPRINTF("Before forking process PID=%d\n", getpid()); 4239 SYSCALL_REQUIRE((child = fork()) != -1); 4240 if (child == 0) { 4241 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4242 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4243 4244 sigemptyset(&intmask); 4245 sigaddset(&intmask, sigmasked); 4246 sigprocmask(SIG_BLOCK, &intmask, NULL); 4247 4248 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4249 FORKEE_ASSERT(raise(sigval) == 0); 4250 4251 DPRINTF("Before raising %s from child\n", 4252 strsignal(signotmasked)); 4253 FORKEE_ASSERT(raise(signotmasked) == 0); 4254 4255 DPRINTF("Before exiting of the child process\n"); 4256 _exit(exitval); 4257 } 4258 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4259 4260 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4261 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4262 4263 validate_status_stopped(status, sigval); 4264 4265 DPRINTF("Before resuming the child process where it left off and " 4266 "without signal to be sent\n"); 4267 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4268 4269 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4270 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4271 4272 validate_status_stopped(status, signotmasked); 4273 4274 DPRINTF("Before resuming the child process where it left off and " 4275 "without signal to be sent\n"); 4276 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4277 4278 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4279 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4280 4281 validate_status_exited(status, exitval); 4282 4283 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4284 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4285} 4286 4287ATF_TC(signal2); 4288ATF_TC_HEAD(signal2, tc) 4289{ 4290 atf_tc_set_md_var(tc, "descr", 4291 "Verify that masking SIGTRAP in tracee stops tracer from " 4292 "catching this raised signal"); 4293} 4294 4295ATF_TC_BODY(signal2, tc) 4296{ 4297 const int exitval = 5; 4298 const int sigval = SIGSTOP; 4299 const int sigmasked = SIGTRAP; 4300 pid_t child, wpid; 4301#if defined(TWAIT_HAVE_STATUS) 4302 int status; 4303#endif 4304 sigset_t intmask; 4305 4306 DPRINTF("Before forking process PID=%d\n", getpid()); 4307 SYSCALL_REQUIRE((child = fork()) != -1); 4308 if (child == 0) { 4309 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4310 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4311 4312 sigemptyset(&intmask); 4313 sigaddset(&intmask, sigmasked); 4314 sigprocmask(SIG_BLOCK, &intmask, NULL); 4315 4316 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4317 FORKEE_ASSERT(raise(sigval) == 0); 4318 4319 DPRINTF("Before raising %s breakpoint from child\n", 4320 strsignal(sigmasked)); 4321 FORKEE_ASSERT(raise(sigmasked) == 0); 4322 4323 DPRINTF("Before exiting of the child process\n"); 4324 _exit(exitval); 4325 } 4326 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4327 4328 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4329 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4330 4331 validate_status_stopped(status, sigval); 4332 4333 DPRINTF("Before resuming the child process where it left off and " 4334 "without signal to be sent\n"); 4335 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4336 4337 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4338 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4339 4340 validate_status_exited(status, exitval); 4341 4342 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4343 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4344} 4345 4346ATF_TC(signal3); 4347ATF_TC_HEAD(signal3, tc) 4348{ 4349 atf_tc_set_md_var(tc, "timeout", "5"); 4350 atf_tc_set_md_var(tc, "descr", 4351 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4352 "catching software breakpoints"); 4353} 4354 4355ATF_TC_BODY(signal3, tc) 4356{ 4357 const int exitval = 5; 4358 const int sigval = SIGSTOP; 4359 const int sigmasked = SIGTRAP; 4360 pid_t child, wpid; 4361#if defined(TWAIT_HAVE_STATUS) 4362 int status; 4363#endif 4364 sigset_t intmask; 4365 4366 DPRINTF("Before forking process PID=%d\n", getpid()); 4367 SYSCALL_REQUIRE((child = fork()) != -1); 4368 if (child == 0) { 4369 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4370 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4371 4372 sigemptyset(&intmask); 4373 sigaddset(&intmask, sigmasked); 4374 sigprocmask(SIG_BLOCK, &intmask, NULL); 4375 4376 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4377 FORKEE_ASSERT(raise(sigval) == 0); 4378 4379 DPRINTF("Before raising software breakpoint from child\n"); 4380 trigger_trap(); 4381 4382 DPRINTF("Before exiting of the child process\n"); 4383 _exit(exitval); 4384 } 4385 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4386 4387 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4388 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4389 4390 validate_status_stopped(status, sigval); 4391 4392 DPRINTF("Before resuming the child process where it left off and " 4393 "without signal to be sent\n"); 4394 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4395 4396 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4397 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4398 4399 validate_status_stopped(status, sigmasked); 4400 4401 DPRINTF("Before resuming the child process where it left off and " 4402 "without signal to be sent\n"); 4403 SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1); 4404 4405 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4406 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4407 4408 validate_status_signaled(status, SIGKILL, 0); 4409 4410 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4411 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4412} 4413 4414#if defined(PT_STEP) 4415ATF_TC(signal4); 4416ATF_TC_HEAD(signal4, tc) 4417{ 4418 atf_tc_set_md_var(tc, "descr", 4419 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4420 "catching single step trap"); 4421} 4422 4423ATF_TC_BODY(signal4, tc) 4424{ 4425 const int exitval = 5; 4426 const int sigval = SIGSTOP; 4427 const int sigmasked = SIGTRAP; 4428 pid_t child, wpid; 4429#if defined(TWAIT_HAVE_STATUS) 4430 int status; 4431#endif 4432 sigset_t intmask; 4433 int happy; 4434 4435#if defined(__arm__) 4436 /* PT_STEP not supported on arm 32-bit */ 4437 atf_tc_expect_fail("PR kern/51918 PR kern/52119"); 4438#endif 4439 4440 DPRINTF("Before forking process PID=%d\n", getpid()); 4441 SYSCALL_REQUIRE((child = fork()) != -1); 4442 if (child == 0) { 4443 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4444 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4445 4446 happy = check_happy(100); 4447 4448 sigemptyset(&intmask); 4449 sigaddset(&intmask, sigmasked); 4450 sigprocmask(SIG_BLOCK, &intmask, NULL); 4451 4452 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4453 FORKEE_ASSERT(raise(sigval) == 0); 4454 4455 FORKEE_ASSERT_EQ(happy, check_happy(100)); 4456 4457 DPRINTF("Before exiting of the child process\n"); 4458 _exit(exitval); 4459 } 4460 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4461 4462 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4463 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4464 4465 validate_status_stopped(status, sigval); 4466 4467 DPRINTF("Before resuming the child process where it left off and " 4468 "without signal to be sent\n"); 4469 SYSCALL_REQUIRE(ptrace(PT_STEP, child, (void *)1, 0) != -1); 4470 4471 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4472 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4473 4474 validate_status_stopped(status, sigmasked); 4475 4476 DPRINTF("Before resuming the child process where it left off and " 4477 "without signal to be sent\n"); 4478 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4479 4480 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4481 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4482 4483 validate_status_exited(status, exitval); 4484 4485 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4486 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4487} 4488#endif 4489 4490ATF_TC(signal5); 4491ATF_TC_HEAD(signal5, tc) 4492{ 4493 atf_tc_set_md_var(tc, "descr", 4494 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4495 "catching exec() breakpoint"); 4496} 4497 4498ATF_TC_BODY(signal5, tc) 4499{ 4500 const int sigval = SIGSTOP; 4501 const int sigmasked = SIGTRAP; 4502 pid_t child, wpid; 4503#if defined(TWAIT_HAVE_STATUS) 4504 int status; 4505#endif 4506 struct ptrace_siginfo info; 4507 sigset_t intmask; 4508 4509 memset(&info, 0, sizeof(info)); 4510 4511 DPRINTF("Before forking process PID=%d\n", getpid()); 4512 SYSCALL_REQUIRE((child = fork()) != -1); 4513 if (child == 0) { 4514 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4515 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4516 4517 sigemptyset(&intmask); 4518 sigaddset(&intmask, sigmasked); 4519 sigprocmask(SIG_BLOCK, &intmask, NULL); 4520 4521 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4522 FORKEE_ASSERT(raise(sigval) == 0); 4523 4524 DPRINTF("Before calling execve(2) from child\n"); 4525 execlp("/bin/echo", "/bin/echo", NULL); 4526 4527 /* NOTREACHED */ 4528 FORKEE_ASSERTX(0 && "Not reached"); 4529 } 4530 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4531 4532 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4533 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4534 4535 validate_status_stopped(status, sigval); 4536 4537 DPRINTF("Before resuming the child process where it left off and " 4538 "without signal to be sent\n"); 4539 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4540 4541 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4542 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4543 4544 validate_status_stopped(status, sigmasked); 4545 4546 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 4547 SYSCALL_REQUIRE( 4548 ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 4549 4550 DPRINTF("Signal traced to lwpid=%d\n", info.psi_lwpid); 4551 DPRINTF("Signal properties: si_signo=%#x si_code=%#x si_errno=%#x\n", 4552 info.psi_siginfo.si_signo, info.psi_siginfo.si_code, 4553 info.psi_siginfo.si_errno); 4554 4555 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, sigmasked); 4556 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_EXEC); 4557 4558 DPRINTF("Before resuming the child process where it left off and " 4559 "without signal to be sent\n"); 4560 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4561 4562 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4563 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4564 4565 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4566 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4567} 4568 4569#if defined(TWAIT_HAVE_PID) 4570ATF_TC(signal6); 4571ATF_TC_HEAD(signal6, tc) 4572{ 4573 atf_tc_set_md_var(tc, "timeout", "5"); 4574 atf_tc_set_md_var(tc, "descr", 4575 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4576 "catching PTRACE_FORK breakpoint"); 4577} 4578 4579ATF_TC_BODY(signal6, tc) 4580{ 4581 const int exitval = 5; 4582 const int exitval2 = 15; 4583 const int sigval = SIGSTOP; 4584 const int sigmasked = SIGTRAP; 4585 pid_t child, child2, wpid; 4586#if defined(TWAIT_HAVE_STATUS) 4587 int status; 4588#endif 4589 sigset_t intmask; 4590 ptrace_state_t state; 4591 const int slen = sizeof(state); 4592 ptrace_event_t event; 4593 const int elen = sizeof(event); 4594 4595 atf_tc_expect_fail("PR kern/51918"); 4596 4597 DPRINTF("Before forking process PID=%d\n", getpid()); 4598 SYSCALL_REQUIRE((child = fork()) != -1); 4599 if (child == 0) { 4600 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4601 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4602 4603 sigemptyset(&intmask); 4604 sigaddset(&intmask, sigmasked); 4605 sigprocmask(SIG_BLOCK, &intmask, NULL); 4606 4607 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4608 FORKEE_ASSERT(raise(sigval) == 0); 4609 4610 FORKEE_ASSERT((child2 = fork()) != -1); 4611 4612 if (child2 == 0) 4613 _exit(exitval2); 4614 4615 FORKEE_REQUIRE_SUCCESS 4616 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 4617 4618 forkee_status_exited(status, exitval2); 4619 4620 DPRINTF("Before exiting of the child process\n"); 4621 _exit(exitval); 4622 } 4623 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4624 4625 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4626 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4627 4628 validate_status_stopped(status, sigval); 4629 4630 DPRINTF("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child); 4631 event.pe_set_event = PTRACE_FORK; 4632 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 4633 4634 DPRINTF("Before resuming the child process where it left off and " 4635 "without signal to be sent\n"); 4636 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4637 4638 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4639 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4640 4641 validate_status_stopped(status, sigmasked); 4642 4643 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 4644 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 4645 4646 child2 = state.pe_other_pid; 4647 DPRINTF("Reported PTRACE_FORK event with forkee %d\n", child2); 4648 4649 DPRINTF("Before calling %s() for the child2\n", TWAIT_FNAME); 4650 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 4651 child2); 4652 4653 validate_status_stopped(status, SIGTRAP); 4654 4655 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 4656 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK); 4657 ATF_REQUIRE_EQ(state.pe_other_pid, child); 4658 4659 DPRINTF("Before resuming the forkee process where it left off and " 4660 "without signal to be sent\n"); 4661 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 4662 4663 DPRINTF("Before resuming the child process where it left off and " 4664 "without signal to be sent\n"); 4665 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4666 4667 DPRINTF("Before calling %s() for the forkee - expected exited\n", 4668 TWAIT_FNAME); 4669 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 4670 child2); 4671 4672 validate_status_exited(status, exitval2); 4673 4674 DPRINTF("Before calling %s() for the forkee - expected no process\n", 4675 TWAIT_FNAME); 4676 TWAIT_REQUIRE_FAILURE(ECHILD, 4677 wpid = TWAIT_GENERIC(child2, &status, 0)); 4678 4679 DPRINTF("Before calling %s() for the child - expected stopped " 4680 "SIGCHLD\n", TWAIT_FNAME); 4681 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4682 4683 validate_status_stopped(status, SIGCHLD); 4684 4685 DPRINTF("Before resuming the child process where it left off and " 4686 "without signal to be sent\n"); 4687 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4688 4689 DPRINTF("Before calling %s() for the child - expected exited\n", 4690 TWAIT_FNAME); 4691 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4692 4693 validate_status_exited(status, exitval); 4694 4695 DPRINTF("Before calling %s() for the child - expected no process\n", 4696 TWAIT_FNAME); 4697 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4698} 4699#endif 4700 4701#if defined(TWAIT_HAVE_PID) 4702ATF_TC(signal7); 4703ATF_TC_HEAD(signal7, tc) 4704{ 4705 atf_tc_set_md_var(tc, "descr", 4706 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4707 "catching PTRACE_VFORK breakpoint"); 4708} 4709 4710ATF_TC_BODY(signal7, tc) 4711{ 4712 const int exitval = 5; 4713 const int exitval2 = 15; 4714 const int sigval = SIGSTOP; 4715 const int sigmasked = SIGTRAP; 4716 pid_t child, child2, wpid; 4717#if defined(TWAIT_HAVE_STATUS) 4718 int status; 4719#endif 4720 sigset_t intmask; 4721 ptrace_state_t state; 4722 const int slen = sizeof(state); 4723 ptrace_event_t event; 4724 const int elen = sizeof(event); 4725 4726 atf_tc_expect_fail("PR kern/51918"); 4727 4728 DPRINTF("Before forking process PID=%d\n", getpid()); 4729 SYSCALL_REQUIRE((child = fork()) != -1); 4730 if (child == 0) { 4731 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4732 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4733 4734 sigemptyset(&intmask); 4735 sigaddset(&intmask, sigmasked); 4736 sigprocmask(SIG_BLOCK, &intmask, NULL); 4737 4738 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4739 FORKEE_ASSERT(raise(sigval) == 0); 4740 4741 FORKEE_ASSERT((child2 = fork()) != -1); 4742 4743 if (child2 == 0) 4744 _exit(exitval2); 4745 4746 FORKEE_REQUIRE_SUCCESS 4747 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 4748 4749 forkee_status_exited(status, exitval2); 4750 4751 DPRINTF("Before exiting of the child process\n"); 4752 _exit(exitval); 4753 } 4754 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4755 4756 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4757 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4758 4759 validate_status_stopped(status, sigval); 4760 4761 DPRINTF("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child); 4762 event.pe_set_event = PTRACE_VFORK; 4763 SYSCALL_REQUIRE( 4764 ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1 || 4765 errno == ENOTSUP); 4766 4767 DPRINTF("Before resuming the child process where it left off and " 4768 "without signal to be sent\n"); 4769 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4770 4771 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4772 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4773 4774 validate_status_stopped(status, sigmasked); 4775 4776 SYSCALL_REQUIRE( 4777 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 4778 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK); 4779 4780 child2 = state.pe_other_pid; 4781 DPRINTF("Reported PTRACE_VFORK event with forkee %d\n", child2); 4782 4783 DPRINTF("Before calling %s() for the child2\n", TWAIT_FNAME); 4784 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 4785 child2); 4786 4787 validate_status_stopped(status, SIGTRAP); 4788 4789 SYSCALL_REQUIRE( 4790 ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1); 4791 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK); 4792 ATF_REQUIRE_EQ(state.pe_other_pid, child); 4793 4794 DPRINTF("Before resuming the forkee process where it left off and " 4795 "without signal to be sent\n"); 4796 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1); 4797 4798 DPRINTF("Before resuming the child process where it left off and " 4799 "without signal to be sent\n"); 4800 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4801 4802 DPRINTF("Before calling %s() for the forkee - expected exited\n", 4803 TWAIT_FNAME); 4804 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0), 4805 child2); 4806 4807 validate_status_exited(status, exitval2); 4808 4809 DPRINTF("Before calling %s() for the forkee - expected no process\n", 4810 TWAIT_FNAME); 4811 TWAIT_REQUIRE_FAILURE(ECHILD, 4812 wpid = TWAIT_GENERIC(child2, &status, 0)); 4813 4814 DPRINTF("Before calling %s() for the child - expected stopped " 4815 "SIGCHLD\n", TWAIT_FNAME); 4816 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4817 4818 validate_status_stopped(status, SIGCHLD); 4819 4820 DPRINTF("Before resuming the child process where it left off and " 4821 "without signal to be sent\n"); 4822 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4823 4824 DPRINTF("Before calling %s() for the child - expected exited\n", 4825 TWAIT_FNAME); 4826 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4827 4828 validate_status_exited(status, exitval); 4829 4830 DPRINTF("Before calling %s() for the child - expected no process\n", 4831 TWAIT_FNAME); 4832 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4833} 4834#endif 4835 4836ATF_TC(signal8); 4837ATF_TC_HEAD(signal8, tc) 4838{ 4839 atf_tc_set_md_var(tc, "descr", 4840 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4841 "catching PTRACE_VFORK_DONE breakpoint"); 4842} 4843 4844ATF_TC_BODY(signal8, tc) 4845{ 4846 const int exitval = 5; 4847 const int exitval2 = 15; 4848 const int sigval = SIGSTOP; 4849 const int sigmasked = SIGTRAP; 4850 pid_t child, child2, wpid; 4851#if defined(TWAIT_HAVE_STATUS) 4852 int status; 4853#endif 4854 sigset_t intmask; 4855 ptrace_state_t state; 4856 const int slen = sizeof(state); 4857 ptrace_event_t event; 4858 const int elen = sizeof(event); 4859 4860 atf_tc_expect_fail("PR kern/51918"); 4861 4862 DPRINTF("Before forking process PID=%d\n", getpid()); 4863 SYSCALL_REQUIRE((child = fork()) != -1); 4864 if (child == 0) { 4865 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4866 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4867 4868 sigemptyset(&intmask); 4869 sigaddset(&intmask, sigmasked); 4870 sigprocmask(SIG_BLOCK, &intmask, NULL); 4871 4872 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4873 FORKEE_ASSERT(raise(sigval) == 0); 4874 4875 FORKEE_ASSERT((child2 = vfork()) != -1); 4876 4877 if (child2 == 0) 4878 _exit(exitval2); 4879 4880 FORKEE_REQUIRE_SUCCESS 4881 (wpid = TWAIT_GENERIC(child2, &status, 0), child2); 4882 4883 forkee_status_exited(status, exitval2); 4884 4885 DPRINTF("Before exiting of the child process\n"); 4886 _exit(exitval); 4887 } 4888 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 4889 4890 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4891 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4892 4893 validate_status_stopped(status, sigval); 4894 4895 DPRINTF("Enable PTRACE_VFORK_DONE in EVENT_MASK for the child %d\n", 4896 child); 4897 event.pe_set_event = PTRACE_VFORK_DONE; 4898 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 4899 4900 DPRINTF("Before resuming the child process where it left off and " 4901 "without signal to be sent\n"); 4902 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4903 4904 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 4905 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4906 4907 validate_status_stopped(status, sigmasked); 4908 4909 SYSCALL_REQUIRE( 4910 ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 4911 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE); 4912 4913 child2 = state.pe_other_pid; 4914 DPRINTF("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2); 4915 4916 DPRINTF("Before resuming the child process where it left off and " 4917 "without signal to be sent\n"); 4918 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4919 4920 DPRINTF("Before calling %s() for the child - expected stopped " 4921 "SIGCHLD\n", TWAIT_FNAME); 4922 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4923 4924 validate_status_stopped(status, SIGCHLD); 4925 4926 DPRINTF("Before resuming the child process where it left off and " 4927 "without signal to be sent\n"); 4928 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 4929 4930 DPRINTF("Before calling %s() for the child - expected exited\n", 4931 TWAIT_FNAME); 4932 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 4933 4934 validate_status_exited(status, exitval); 4935 4936 DPRINTF("Before calling %s() for the child - expected no process\n", 4937 TWAIT_FNAME); 4938 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 4939} 4940 4941ATF_TC(signal9); 4942ATF_TC_HEAD(signal9, tc) 4943{ 4944 atf_tc_set_md_var(tc, "descr", 4945 "Verify that masking SIGTRAP in tracee does not stop tracer from " 4946 "catching PTRACE_LWP_CREATE breakpoint"); 4947} 4948 4949ATF_TC_BODY(signal9, tc) 4950{ 4951 const int exitval = 5; 4952 const int sigval = SIGSTOP; 4953 const int sigmasked = SIGTRAP; 4954 pid_t child, wpid; 4955#if defined(TWAIT_HAVE_STATUS) 4956 int status; 4957#endif 4958 sigset_t intmask; 4959 ptrace_state_t state; 4960 const int slen = sizeof(state); 4961 ptrace_event_t event; 4962 const int elen = sizeof(event); 4963 ucontext_t uc; 4964 lwpid_t lid; 4965 static const size_t ssize = 16*1024; 4966 void *stack; 4967 4968 atf_tc_expect_fail("PR kern/51918"); 4969 4970 DPRINTF("Before forking process PID=%d\n", getpid()); 4971 SYSCALL_REQUIRE((child = fork()) != -1); 4972 if (child == 0) { 4973 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 4974 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 4975 4976 sigemptyset(&intmask); 4977 sigaddset(&intmask, sigmasked); 4978 sigprocmask(SIG_BLOCK, &intmask, NULL); 4979 4980 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 4981 FORKEE_ASSERT(raise(sigval) == 0); 4982 4983 DPRINTF("Before allocating memory for stack in child\n"); 4984 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 4985 4986 DPRINTF("Before making context for new lwp in child\n"); 4987 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 4988 4989 DPRINTF("Before creating new in child\n"); 4990 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 4991 4992 DPRINTF("Before waiting for lwp %d to exit\n", lid); 4993 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 4994 4995 DPRINTF("Before verifying that reported %d and running lid %d " 4996 "are the same\n", lid, the_lwp_id); 4997 FORKEE_ASSERT_EQ(lid, the_lwp_id); 4998 4999 DPRINTF("Before exiting of the child process\n"); 5000 _exit(exitval); 5001 } 5002 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5003 5004 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5005 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5006 5007 validate_status_stopped(status, sigval); 5008 5009 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 5010 event.pe_set_event = PTRACE_LWP_CREATE; 5011 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 5012 5013 DPRINTF("Before resuming the child process where it left off and " 5014 "without signal to be sent\n"); 5015 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5016 5017 DPRINTF("Before calling %s() for the child - expected stopped " 5018 "SIGTRAP\n", TWAIT_FNAME); 5019 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5020 5021 validate_status_stopped(status, sigmasked); 5022 5023 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5024 5025 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_CREATE); 5026 5027 lid = state.pe_lwp; 5028 DPRINTF("Reported PTRACE_LWP_CREATE event with lid %d\n", lid); 5029 5030 DPRINTF("Before resuming the child process where it left off and " 5031 "without signal to be sent\n"); 5032 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5033 5034 DPRINTF("Before calling %s() for the child - expected exited\n", 5035 TWAIT_FNAME); 5036 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5037 5038 validate_status_exited(status, exitval); 5039 5040 DPRINTF("Before calling %s() for the child - expected no process\n", 5041 TWAIT_FNAME); 5042 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5043} 5044 5045ATF_TC(signal10); 5046ATF_TC_HEAD(signal10, tc) 5047{ 5048 atf_tc_set_md_var(tc, "descr", 5049 "Verify that masking SIGTRAP in tracee does not stop tracer from " 5050 "catching PTRACE_LWP_EXIT breakpoint"); 5051} 5052 5053ATF_TC_BODY(signal10, tc) 5054{ 5055 const int exitval = 5; 5056 const int sigval = SIGSTOP; 5057 const int sigmasked = SIGTRAP; 5058 pid_t child, wpid; 5059#if defined(TWAIT_HAVE_STATUS) 5060 int status; 5061#endif 5062 sigset_t intmask; 5063 ptrace_state_t state; 5064 const int slen = sizeof(state); 5065 ptrace_event_t event; 5066 const int elen = sizeof(event); 5067 ucontext_t uc; 5068 lwpid_t lid; 5069 static const size_t ssize = 16*1024; 5070 void *stack; 5071 5072 atf_tc_expect_fail("PR kern/51918"); 5073 5074 DPRINTF("Before forking process PID=%d\n", getpid()); 5075 SYSCALL_REQUIRE((child = fork()) != -1); 5076 if (child == 0) { 5077 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5078 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5079 5080 sigemptyset(&intmask); 5081 sigaddset(&intmask, sigmasked); 5082 sigprocmask(SIG_BLOCK, &intmask, NULL); 5083 5084 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5085 FORKEE_ASSERT(raise(sigval) == 0); 5086 5087 DPRINTF("Before allocating memory for stack in child\n"); 5088 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 5089 5090 DPRINTF("Before making context for new lwp in child\n"); 5091 _lwp_makecontext(&uc, lwp_main_func, NULL, NULL, stack, ssize); 5092 5093 DPRINTF("Before creating new in child\n"); 5094 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 5095 5096 DPRINTF("Before waiting for lwp %d to exit\n", lid); 5097 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 5098 5099 DPRINTF("Before verifying that reported %d and running lid %d " 5100 "are the same\n", lid, the_lwp_id); 5101 FORKEE_ASSERT_EQ(lid, the_lwp_id); 5102 5103 DPRINTF("Before exiting of the child process\n"); 5104 _exit(exitval); 5105 } 5106 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5107 5108 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5109 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5110 5111 validate_status_stopped(status, sigval); 5112 5113 DPRINTF("Set empty EVENT_MASK for the child %d\n", child); 5114 event.pe_set_event = PTRACE_LWP_EXIT; 5115 SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); 5116 5117 DPRINTF("Before resuming the child process where it left off and " 5118 "without signal to be sent\n"); 5119 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5120 5121 DPRINTF("Before calling %s() for the child - expected stopped " 5122 "SIGTRAP\n", TWAIT_FNAME); 5123 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5124 5125 validate_status_stopped(status, sigmasked); 5126 5127 SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); 5128 5129 ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_LWP_EXIT); 5130 5131 lid = state.pe_lwp; 5132 DPRINTF("Reported PTRACE_LWP_EXIT event with lid %d\n", lid); 5133 5134 DPRINTF("Before resuming the child process where it left off and " 5135 "without signal to be sent\n"); 5136 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5137 5138 DPRINTF("Before calling %s() for the child - expected exited\n", 5139 TWAIT_FNAME); 5140 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5141 5142 validate_status_exited(status, exitval); 5143 5144 DPRINTF("Before calling %s() for the child - expected no process\n", 5145 TWAIT_FNAME); 5146 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5147} 5148 5149static void 5150lwp_main_stop(void *arg) 5151{ 5152 the_lwp_id = _lwp_self(); 5153 5154 raise(SIGTRAP); 5155 5156 _lwp_exit(); 5157} 5158 5159ATF_TC(suspend1); 5160ATF_TC_HEAD(suspend1, tc) 5161{ 5162 atf_tc_set_md_var(tc, "descr", 5163 "Verify that a thread can be suspended by a debugger and later " 5164 "resumed by a tracee"); 5165} 5166 5167ATF_TC_BODY(suspend1, tc) 5168{ 5169 const int exitval = 5; 5170 const int sigval = SIGSTOP; 5171 pid_t child, wpid; 5172#if defined(TWAIT_HAVE_STATUS) 5173 int status; 5174#endif 5175 ucontext_t uc; 5176 lwpid_t lid; 5177 static const size_t ssize = 16*1024; 5178 void *stack; 5179 struct ptrace_lwpinfo pl; 5180 struct ptrace_siginfo psi; 5181 volatile int go = 0; 5182 5183 // Feature pending for refactoring 5184 atf_tc_expect_fail("PR kern/51995"); 5185 5186 // Hangs with qemu 5187 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 5188 5189 DPRINTF("Before forking process PID=%d\n", getpid()); 5190 SYSCALL_REQUIRE((child = fork()) != -1); 5191 if (child == 0) { 5192 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5193 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5194 5195 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5196 FORKEE_ASSERT(raise(sigval) == 0); 5197 5198 DPRINTF("Before allocating memory for stack in child\n"); 5199 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 5200 5201 DPRINTF("Before making context for new lwp in child\n"); 5202 _lwp_makecontext(&uc, lwp_main_stop, NULL, NULL, stack, ssize); 5203 5204 DPRINTF("Before creating new in child\n"); 5205 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 5206 5207 while (go == 0) 5208 continue; 5209 5210 raise(SIGINT); 5211 5212 FORKEE_ASSERT(_lwp_continue(lid) == 0); 5213 5214 DPRINTF("Before waiting for lwp %d to exit\n", lid); 5215 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 5216 5217 DPRINTF("Before verifying that reported %d and running lid %d " 5218 "are the same\n", lid, the_lwp_id); 5219 FORKEE_ASSERT_EQ(lid, the_lwp_id); 5220 5221 DPRINTF("Before exiting of the child process\n"); 5222 _exit(exitval); 5223 } 5224 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5225 5226 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5227 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5228 5229 validate_status_stopped(status, sigval); 5230 5231 DPRINTF("Before resuming the child process where it left off and " 5232 "without signal to be sent\n"); 5233 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5234 5235 DPRINTF("Before calling %s() for the child - expected stopped " 5236 "SIGTRAP\n", TWAIT_FNAME); 5237 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5238 5239 validate_status_stopped(status, SIGTRAP); 5240 5241 DPRINTF("Before reading siginfo and lwpid_t\n"); 5242 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &psi, sizeof(psi)) != -1); 5243 5244 DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); 5245 SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); 5246 5247 DPRINTF("Write new go to tracee (PID=%d) from tracer (PID=%d)\n", 5248 child, getpid()); 5249 SYSCALL_REQUIRE(ptrace(PT_WRITE_D, child, __UNVOLATILE(&go), 1) != -1); 5250 5251 DPRINTF("Before resuming the child process where it left off and " 5252 "without signal to be sent\n"); 5253 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5254 5255 DPRINTF("Before calling %s() for the child - expected stopped " 5256 "SIGINT\n", TWAIT_FNAME); 5257 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5258 5259 validate_status_stopped(status, SIGINT); 5260 5261 pl.pl_lwpid = 0; 5262 5263 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 5264 while (pl.pl_lwpid != 0) { 5265 5266 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 5267 switch (pl.pl_lwpid) { 5268 case 1: 5269 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SIGNAL); 5270 break; 5271 case 2: 5272 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SUSPENDED); 5273 break; 5274 } 5275 } 5276 5277 DPRINTF("Before resuming the child process where it left off and " 5278 "without signal to be sent\n"); 5279 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5280 5281 DPRINTF("Before calling %s() for the child - expected exited\n", 5282 TWAIT_FNAME); 5283 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5284 5285 validate_status_exited(status, exitval); 5286 5287 DPRINTF("Before calling %s() for the child - expected no process\n", 5288 TWAIT_FNAME); 5289 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5290} 5291 5292ATF_TC(suspend2); 5293ATF_TC_HEAD(suspend2, tc) 5294{ 5295 atf_tc_set_md_var(tc, "descr", 5296 "Verify that the while the only thread within a process is " 5297 "suspended, the whole process cannot be unstopped"); 5298} 5299 5300ATF_TC_BODY(suspend2, tc) 5301{ 5302 const int exitval = 5; 5303 const int sigval = SIGSTOP; 5304 pid_t child, wpid; 5305#if defined(TWAIT_HAVE_STATUS) 5306 int status; 5307#endif 5308 struct ptrace_siginfo psi; 5309 5310 // Feature pending for refactoring 5311 atf_tc_expect_fail("PR kern/51995"); 5312 5313 // Hangs with qemu 5314 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 5315 5316 DPRINTF("Before forking process PID=%d\n", getpid()); 5317 SYSCALL_REQUIRE((child = fork()) != -1); 5318 if (child == 0) { 5319 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5320 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5321 5322 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5323 FORKEE_ASSERT(raise(sigval) == 0); 5324 5325 DPRINTF("Before exiting of the child process\n"); 5326 _exit(exitval); 5327 } 5328 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5329 5330 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5331 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5332 5333 validate_status_stopped(status, sigval); 5334 5335 DPRINTF("Before reading siginfo and lwpid_t\n"); 5336 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &psi, sizeof(psi)) != -1); 5337 5338 DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); 5339 SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); 5340 5341 DPRINTF("Before resuming the child process where it left off and " 5342 "without signal to be sent\n"); 5343 ATF_REQUIRE_ERRNO(EDEADLK, 5344 ptrace(PT_CONTINUE, child, (void *)1, 0) == -1); 5345 5346 DPRINTF("Before resuming LWP %d\n", psi.psi_lwpid); 5347 SYSCALL_REQUIRE(ptrace(PT_RESUME, child, NULL, psi.psi_lwpid) != -1); 5348 5349 DPRINTF("Before resuming the child process where it left off and " 5350 "without signal to be sent\n"); 5351 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5352 5353 DPRINTF("Before calling %s() for the child - expected exited\n", 5354 TWAIT_FNAME); 5355 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5356 5357 validate_status_exited(status, exitval); 5358 5359 DPRINTF("Before calling %s() for the child - expected no process\n", 5360 TWAIT_FNAME); 5361 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5362} 5363 5364ATF_TC(resume1); 5365ATF_TC_HEAD(resume1, tc) 5366{ 5367 atf_tc_set_md_var(tc, "timeout", "5"); 5368 atf_tc_set_md_var(tc, "descr", 5369 "Verify that a thread can be suspended by a debugger and later " 5370 "resumed by the debugger"); 5371} 5372 5373ATF_TC_BODY(resume1, tc) 5374{ 5375 struct msg_fds fds; 5376 const int exitval = 5; 5377 const int sigval = SIGSTOP; 5378 pid_t child, wpid; 5379 uint8_t msg = 0xde; /* dummy message for IPC based on pipe(2) */ 5380#if defined(TWAIT_HAVE_STATUS) 5381 int status; 5382#endif 5383 ucontext_t uc; 5384 lwpid_t lid; 5385 static const size_t ssize = 16*1024; 5386 void *stack; 5387 struct ptrace_lwpinfo pl; 5388 struct ptrace_siginfo psi; 5389 5390 // Feature pending for refactoring 5391 atf_tc_expect_fail("PR kern/51995"); 5392 5393 // Hangs with qemu 5394 ATF_REQUIRE(0 && "In order to get reliable failure, abort"); 5395 5396 SYSCALL_REQUIRE(msg_open(&fds) == 0); 5397 5398 DPRINTF("Before forking process PID=%d\n", getpid()); 5399 SYSCALL_REQUIRE((child = fork()) != -1); 5400 if (child == 0) { 5401 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5402 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5403 5404 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5405 FORKEE_ASSERT(raise(sigval) == 0); 5406 5407 DPRINTF("Before allocating memory for stack in child\n"); 5408 FORKEE_ASSERT((stack = malloc(ssize)) != NULL); 5409 5410 DPRINTF("Before making context for new lwp in child\n"); 5411 _lwp_makecontext(&uc, lwp_main_stop, NULL, NULL, stack, ssize); 5412 5413 DPRINTF("Before creating new in child\n"); 5414 FORKEE_ASSERT(_lwp_create(&uc, 0, &lid) == 0); 5415 5416 CHILD_TO_PARENT("Message", fds, msg); 5417 5418 raise(SIGINT); 5419 5420 DPRINTF("Before waiting for lwp %d to exit\n", lid); 5421 FORKEE_ASSERT(_lwp_wait(lid, NULL) == 0); 5422 5423 DPRINTF("Before verifying that reported %d and running lid %d " 5424 "are the same\n", lid, the_lwp_id); 5425 FORKEE_ASSERT_EQ(lid, the_lwp_id); 5426 5427 DPRINTF("Before exiting of the child process\n"); 5428 _exit(exitval); 5429 } 5430 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5431 5432 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5433 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5434 5435 validate_status_stopped(status, sigval); 5436 5437 DPRINTF("Before resuming the child process where it left off and " 5438 "without signal to be sent\n"); 5439 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5440 5441 DPRINTF("Before calling %s() for the child - expected stopped " 5442 "SIGTRAP\n", TWAIT_FNAME); 5443 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5444 5445 validate_status_stopped(status, SIGTRAP); 5446 5447 DPRINTF("Before reading siginfo and lwpid_t\n"); 5448 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &psi, sizeof(psi)) != -1); 5449 5450 DPRINTF("Before suspending LWP %d\n", psi.psi_lwpid); 5451 SYSCALL_REQUIRE(ptrace(PT_SUSPEND, child, NULL, psi.psi_lwpid) != -1); 5452 5453 PARENT_FROM_CHILD("Message", fds, msg); 5454 5455 DPRINTF("Before resuming the child process where it left off and " 5456 "without signal to be sent\n"); 5457 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5458 5459 DPRINTF("Before calling %s() for the child - expected stopped " 5460 "SIGINT\n", TWAIT_FNAME); 5461 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5462 5463 validate_status_stopped(status, SIGINT); 5464 5465 pl.pl_lwpid = 0; 5466 5467 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 5468 while (pl.pl_lwpid != 0) { 5469 SYSCALL_REQUIRE(ptrace(PT_LWPINFO, child, &pl, sizeof(pl)) != -1); 5470 switch (pl.pl_lwpid) { 5471 case 1: 5472 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SIGNAL); 5473 break; 5474 case 2: 5475 ATF_REQUIRE_EQ(pl.pl_event, PL_EVENT_SUSPENDED); 5476 break; 5477 } 5478 } 5479 5480 DPRINTF("Before resuming LWP %d\n", psi.psi_lwpid); 5481 SYSCALL_REQUIRE(ptrace(PT_RESUME, child, NULL, psi.psi_lwpid) != -1); 5482 5483 DPRINTF("Before resuming the child process where it left off and " 5484 "without signal to be sent\n"); 5485 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5486 5487 DPRINTF("Before calling %s() for the child - expected exited\n", 5488 TWAIT_FNAME); 5489 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5490 5491 validate_status_exited(status, exitval); 5492 5493 DPRINTF("Before calling %s() for the child - expected no process\n", 5494 TWAIT_FNAME); 5495 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5496 5497 msg_close(&fds); 5498 5499 DPRINTF("XXX: Test worked this time but for consistency timeout it\n"); 5500 sleep(10); 5501} 5502 5503ATF_TC(syscall1); 5504ATF_TC_HEAD(syscall1, tc) 5505{ 5506 atf_tc_set_md_var(tc, "descr", 5507 "Verify that getpid(2) can be traced with PT_SYSCALL"); 5508} 5509 5510ATF_TC_BODY(syscall1, tc) 5511{ 5512 const int exitval = 5; 5513 const int sigval = SIGSTOP; 5514 pid_t child, wpid; 5515#if defined(TWAIT_HAVE_STATUS) 5516 int status; 5517#endif 5518 struct ptrace_siginfo info; 5519 memset(&info, 0, sizeof(info)); 5520 5521 DPRINTF("Before forking process PID=%d\n", getpid()); 5522 SYSCALL_REQUIRE((child = fork()) != -1); 5523 if (child == 0) { 5524 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5525 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5526 5527 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5528 FORKEE_ASSERT(raise(sigval) == 0); 5529 5530 syscall(SYS_getpid); 5531 5532 DPRINTF("Before exiting of the child process\n"); 5533 _exit(exitval); 5534 } 5535 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5536 5537 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5538 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5539 5540 validate_status_stopped(status, sigval); 5541 5542 DPRINTF("Before resuming the child process where it left off and " 5543 "without signal to be sent\n"); 5544 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 5545 5546 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5547 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5548 5549 validate_status_stopped(status, SIGTRAP); 5550 5551 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 5552 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 5553 5554 DPRINTF("Before checking siginfo_t and lwpid\n"); 5555 ATF_REQUIRE_EQ(info.psi_lwpid, 1); 5556 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 5557 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCE); 5558 5559 DPRINTF("Before resuming the child process where it left off and " 5560 "without signal to be sent\n"); 5561 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 5562 5563 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5564 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5565 5566 validate_status_stopped(status, SIGTRAP); 5567 5568 DPRINTF("Before calling ptrace(2) with PT_GET_SIGINFO for child\n"); 5569 SYSCALL_REQUIRE(ptrace(PT_GET_SIGINFO, child, &info, sizeof(info)) != -1); 5570 5571 DPRINTF("Before checking siginfo_t and lwpid\n"); 5572 ATF_REQUIRE_EQ(info.psi_lwpid, 1); 5573 ATF_REQUIRE_EQ(info.psi_siginfo.si_signo, SIGTRAP); 5574 ATF_REQUIRE_EQ(info.psi_siginfo.si_code, TRAP_SCX); 5575 5576 DPRINTF("Before resuming the child process where it left off and " 5577 "without signal to be sent\n"); 5578 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5579 5580 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5581 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5582 5583 validate_status_exited(status, exitval); 5584 5585 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5586 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5587} 5588 5589ATF_TC(syscallemu1); 5590ATF_TC_HEAD(syscallemu1, tc) 5591{ 5592 atf_tc_set_md_var(tc, "descr", 5593 "Verify that exit(2) can be intercepted with PT_SYSCALLEMU"); 5594} 5595 5596ATF_TC_BODY(syscallemu1, tc) 5597{ 5598 const int exitval = 5; 5599 const int sigval = SIGSTOP; 5600 pid_t child, wpid; 5601#if defined(TWAIT_HAVE_STATUS) 5602 int status; 5603#endif 5604 5605#if defined(__sparc__) && !defined(__sparc64__) 5606 /* syscallemu does not work on sparc (32-bit) */ 5607 atf_tc_expect_fail("PR kern/52166"); 5608#endif 5609 5610 DPRINTF("Before forking process PID=%d\n", getpid()); 5611 SYSCALL_REQUIRE((child = fork()) != -1); 5612 if (child == 0) { 5613 DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid()); 5614 FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); 5615 5616 DPRINTF("Before raising %s from child\n", strsignal(sigval)); 5617 FORKEE_ASSERT(raise(sigval) == 0); 5618 5619 syscall(SYS_exit, 100); 5620 5621 DPRINTF("Before exiting of the child process\n"); 5622 _exit(exitval); 5623 } 5624 DPRINTF("Parent process PID=%d, child's PID=%d\n", getpid(), child); 5625 5626 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5627 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5628 5629 validate_status_stopped(status, sigval); 5630 5631 DPRINTF("Before resuming the child process where it left off and " 5632 "without signal to be sent\n"); 5633 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 5634 5635 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5636 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5637 5638 validate_status_stopped(status, SIGTRAP); 5639 5640 DPRINTF("Set SYSCALLEMU for intercepted syscall\n"); 5641 SYSCALL_REQUIRE(ptrace(PT_SYSCALLEMU, child, (void *)1, 0) != -1); 5642 5643 DPRINTF("Before resuming the child process where it left off and " 5644 "without signal to be sent\n"); 5645 SYSCALL_REQUIRE(ptrace(PT_SYSCALL, child, (void *)1, 0) != -1); 5646 5647 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5648 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5649 5650 validate_status_stopped(status, SIGTRAP); 5651 5652 DPRINTF("Before resuming the child process where it left off and " 5653 "without signal to be sent\n"); 5654 SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); 5655 5656 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5657 TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); 5658 5659 validate_status_exited(status, exitval); 5660 5661 DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME); 5662 TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); 5663} 5664 5665#include "t_ptrace_amd64_wait.h" 5666#include "t_ptrace_i386_wait.h" 5667#include "t_ptrace_x86_wait.h" 5668 5669ATF_TP_ADD_TCS(tp) 5670{ 5671 setvbuf(stdout, NULL, _IONBF, 0); 5672 setvbuf(stderr, NULL, _IONBF, 0); 5673 5674 ATF_TP_ADD_TC(tp, traceme_raise1); 5675 ATF_TP_ADD_TC(tp, traceme_raise2); 5676 ATF_TP_ADD_TC(tp, traceme_raise3); 5677 ATF_TP_ADD_TC(tp, traceme_raise4); 5678 ATF_TP_ADD_TC(tp, traceme_raise5); 5679 5680 ATF_TP_ADD_TC(tp, traceme_crash_trap); 5681 ATF_TP_ADD_TC(tp, traceme_crash_segv); 5682// ATF_TP_ADD_TC(tp, traceme_crash_ill); 5683 ATF_TP_ADD_TC(tp, traceme_crash_fpe); 5684 ATF_TP_ADD_TC(tp, traceme_crash_bus); 5685 5686 ATF_TP_ADD_TC(tp, traceme_sendsignal_handle1); 5687 ATF_TP_ADD_TC(tp, traceme_sendsignal_handle2); 5688 ATF_TP_ADD_TC(tp, traceme_sendsignal_handle3); 5689 5690 ATF_TP_ADD_TC(tp, traceme_sendsignal_masked1); 5691 ATF_TP_ADD_TC(tp, traceme_sendsignal_masked2); 5692 ATF_TP_ADD_TC(tp, traceme_sendsignal_masked3); 5693 5694 ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored1); 5695 ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored2); 5696 ATF_TP_ADD_TC(tp, traceme_sendsignal_ignored3); 5697 5698 ATF_TP_ADD_TC(tp, traceme_sendsignal_simple1); 5699 ATF_TP_ADD_TC(tp, traceme_sendsignal_simple2); 5700 ATF_TP_ADD_TC(tp, traceme_sendsignal_simple3); 5701 ATF_TP_ADD_TC(tp, traceme_sendsignal_simple4); 5702 ATF_TP_ADD_TC(tp, traceme_sendsignal_simple5); 5703 5704 ATF_TP_ADD_TC(tp, traceme_pid1_parent); 5705 5706 ATF_TP_ADD_TC(tp, traceme_vfork_raise1); 5707 ATF_TP_ADD_TC(tp, traceme_vfork_raise2); 5708 ATF_TP_ADD_TC(tp, traceme_vfork_raise3); 5709 ATF_TP_ADD_TC(tp, traceme_vfork_raise4); 5710 ATF_TP_ADD_TC(tp, traceme_vfork_raise5); 5711 ATF_TP_ADD_TC(tp, traceme_vfork_raise6); 5712 ATF_TP_ADD_TC(tp, traceme_vfork_raise7); 5713 ATF_TP_ADD_TC(tp, traceme_vfork_raise8); 5714 5715 ATF_TP_ADD_TC(tp, traceme_vfork_crash_trap); 5716 ATF_TP_ADD_TC(tp, traceme_vfork_crash_segv); 5717// ATF_TP_ADD_TC(tp, traceme_vfork_crash_ill); 5718 ATF_TP_ADD_TC(tp, traceme_vfork_crash_fpe); 5719 ATF_TP_ADD_TC(tp, traceme_vfork_crash_bus); 5720 5721 ATF_TP_ADD_TC(tp, traceme_vfork_exec); 5722 5723 ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_trap); 5724 ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_segv); 5725// ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_ill); 5726 ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_fpe); 5727 ATF_TP_ADD_TC_HAVE_PID(tp, unrelated_tracer_sees_crash_bus); 5728 5729 ATF_TP_ADD_TC_HAVE_PID(tp, tracer_sees_terminaton_before_the_parent); 5730 ATF_TP_ADD_TC_HAVE_PID(tp, tracer_sysctl_lookup_without_duplicates); 5731 ATF_TP_ADD_TC_HAVE_PID(tp, 5732 unrelated_tracer_sees_terminaton_before_the_parent); 5733 ATF_TP_ADD_TC_HAVE_PID(tp, tracer_attach_to_unrelated_stopped_process); 5734 5735 ATF_TP_ADD_TC(tp, parent_attach_to_its_child); 5736 ATF_TP_ADD_TC(tp, parent_attach_to_its_stopped_child); 5737 5738 ATF_TP_ADD_TC(tp, child_attach_to_its_parent); 5739 ATF_TP_ADD_TC(tp, child_attach_to_its_stopped_parent); 5740 5741 ATF_TP_ADD_TC_HAVE_PID(tp, 5742 tracee_sees_its_original_parent_getppid); 5743 ATF_TP_ADD_TC_HAVE_PID(tp, 5744 tracee_sees_its_original_parent_sysctl_kinfo_proc2); 5745 ATF_TP_ADD_TC_HAVE_PID(tp, 5746 tracee_sees_its_original_parent_procfs_status); 5747 5748 ATF_TP_ADD_TC(tp, eventmask_preserved_empty); 5749 ATF_TP_ADD_TC(tp, eventmask_preserved_fork); 5750 ATF_TP_ADD_TC(tp, eventmask_preserved_vfork); 5751 ATF_TP_ADD_TC(tp, eventmask_preserved_vfork_done); 5752 ATF_TP_ADD_TC(tp, eventmask_preserved_lwp_create); 5753 ATF_TP_ADD_TC(tp, eventmask_preserved_lwp_exit); 5754 5755 ATF_TP_ADD_TC(tp, fork1); 5756 ATF_TP_ADD_TC_HAVE_PID(tp, fork2); 5757 ATF_TP_ADD_TC_HAVE_PID(tp, fork3); 5758 ATF_TP_ADD_TC_HAVE_PID(tp, fork4); 5759 ATF_TP_ADD_TC(tp, fork5); 5760 ATF_TP_ADD_TC_HAVE_PID(tp, fork6); 5761 ATF_TP_ADD_TC_HAVE_PID(tp, fork7); 5762 ATF_TP_ADD_TC_HAVE_PID(tp, fork8); 5763 5764 ATF_TP_ADD_TC(tp, vfork1); 5765 ATF_TP_ADD_TC_HAVE_PID(tp, vfork2); 5766 ATF_TP_ADD_TC_HAVE_PID(tp, vfork3); 5767 ATF_TP_ADD_TC_HAVE_PID(tp, vfork4); 5768 ATF_TP_ADD_TC(tp, vfork5); 5769 ATF_TP_ADD_TC_HAVE_PID(tp, vfork6); 5770// thes tests hang on SMP machines, disable them for now 5771// ATF_TP_ADD_TC_HAVE_PID(tp, vfork7); 5772// ATF_TP_ADD_TC_HAVE_PID(tp, vfork8); 5773 5774 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_8); 5775 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_16); 5776 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_32); 5777 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_64); 5778 5779 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_8); 5780 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_16); 5781 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_32); 5782 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_64); 5783 5784 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_8); 5785 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_16); 5786 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_32); 5787 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_64); 5788 5789 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_8); 5790 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_16); 5791 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_32); 5792 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_64); 5793 5794 ATF_TP_ADD_TC(tp, bytes_transfer_read_d); 5795 ATF_TP_ADD_TC(tp, bytes_transfer_read_i); 5796 ATF_TP_ADD_TC(tp, bytes_transfer_write_d); 5797 ATF_TP_ADD_TC(tp, bytes_transfer_write_i); 5798 5799 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_8_text); 5800 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_16_text); 5801 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_32_text); 5802 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_d_64_text); 5803 5804 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_8_text); 5805 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_16_text); 5806 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_32_text); 5807 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_i_64_text); 5808 5809 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_8_text); 5810 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_16_text); 5811 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_32_text); 5812 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_d_64_text); 5813 5814 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_8_text); 5815 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_16_text); 5816 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_32_text); 5817 ATF_TP_ADD_TC(tp, bytes_transfer_piod_write_i_64_text); 5818 5819 ATF_TP_ADD_TC(tp, bytes_transfer_read_d_text); 5820 ATF_TP_ADD_TC(tp, bytes_transfer_read_i_text); 5821 ATF_TP_ADD_TC(tp, bytes_transfer_write_d_text); 5822 ATF_TP_ADD_TC(tp, bytes_transfer_write_i_text); 5823 5824 ATF_TP_ADD_TC(tp, bytes_transfer_piod_read_auxv); 5825 5826 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); 5827 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs2); 5828 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs3); 5829 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs4); 5830 ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs5); 5831 5832 ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs1); 5833 ATF_TP_ADD_TC_HAVE_FPREGS(tp, fpregs2); 5834 5835 ATF_TP_ADD_TC_PT_STEP(tp, step1); 5836 ATF_TP_ADD_TC_PT_STEP(tp, step2); 5837 ATF_TP_ADD_TC_PT_STEP(tp, step3); 5838 ATF_TP_ADD_TC_PT_STEP(tp, step4); 5839 5840 ATF_TP_ADD_TC_PT_STEP(tp, setstep1); 5841 ATF_TP_ADD_TC_PT_STEP(tp, setstep2); 5842 ATF_TP_ADD_TC_PT_STEP(tp, setstep3); 5843 ATF_TP_ADD_TC_PT_STEP(tp, setstep4); 5844 5845 ATF_TP_ADD_TC(tp, kill1); 5846 ATF_TP_ADD_TC(tp, kill2); 5847 5848 ATF_TP_ADD_TC(tp, lwpinfo1); 5849 ATF_TP_ADD_TC_HAVE_PID(tp, lwpinfo2); 5850 5851 ATF_TP_ADD_TC(tp, siginfo1); 5852 ATF_TP_ADD_TC(tp, siginfo2); 5853 ATF_TP_ADD_TC(tp, siginfo3); 5854 ATF_TP_ADD_TC(tp, siginfo4); 5855 ATF_TP_ADD_TC_HAVE_PID(tp, siginfo5); 5856 ATF_TP_ADD_TC_PT_STEP(tp, siginfo6); 5857 5858 ATF_TP_ADD_TC(tp, lwp_create1); 5859 5860 ATF_TP_ADD_TC(tp, lwp_exit1); 5861 5862 ATF_TP_ADD_TC(tp, signal1); 5863 ATF_TP_ADD_TC(tp, signal2); 5864 ATF_TP_ADD_TC(tp, signal3); 5865 ATF_TP_ADD_TC_PT_STEP(tp, signal4); 5866 ATF_TP_ADD_TC(tp, signal5); 5867 ATF_TP_ADD_TC_HAVE_PID(tp, signal6); 5868 ATF_TP_ADD_TC_HAVE_PID(tp, signal7); 5869 ATF_TP_ADD_TC(tp, signal8); 5870 ATF_TP_ADD_TC(tp, signal9); 5871 ATF_TP_ADD_TC(tp, signal10); 5872 5873 ATF_TP_ADD_TC(tp, suspend1); 5874 ATF_TP_ADD_TC(tp, suspend2); 5875 5876 ATF_TP_ADD_TC(tp, resume1); 5877 5878 ATF_TP_ADD_TC(tp, syscall1); 5879 5880 ATF_TP_ADD_TC(tp, syscallemu1); 5881 5882 ATF_TP_ADD_TCS_PTRACE_WAIT_AMD64(); 5883 ATF_TP_ADD_TCS_PTRACE_WAIT_I386(); 5884 ATF_TP_ADD_TCS_PTRACE_WAIT_X86(); 5885 5886 return atf_no_error(); 5887} 5888