Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
src: Pull up following revision(s) (requested by kamil in ticket...
details: https://anonhg.NetBSD.org/src/rev/73888d295313
branches: netbsd-8
changeset: 318097:73888d295313
user: martin <martin%NetBSD.org@localhost>
date: Thu Apr 12 13:02:20 2018 +0000
description:
Pull up following revision(s) (requested by kamil in ticket #711):
tests/lib/libc/sys/t_ptrace_wait.c: revision 1.24-1.31
tests/lib/libc/sys/t_ptrace_wait.h: revision 1.2
tests/lib/libc/sys/t_ptrace_x86_wait.h: revision 1.4,1.5
tests/lib/libc/sys/msg.h: revision 1.2
Correct all ATF failures in t_ptrace_x86_wait.h (debug registers)
This code after refactoring stopped calling functions that were designed
to trigger expected behavior and thus, tests were breaking.
Sponsored by <The NetBSD Foundation>
ATF: Correct a race bug in attach2 (t_ptrace_wait*)
At the end of the test we resume a tracer and expect to observe it to
collect the debuggee. We cannot from a parent point of view wait for
collecting it with WNOHANG without a race.
Remove the WNOHANG option from wait*(2) call. This corrects one type of
race.
This test is still racy for some other and unknown reason and this is bei=
ng
investigated.
Sponsored by <The NetBSD Foundation>
ATF: Reenable attach2 in t_ptrace_wait*
The primary race specific to this test has been fixed in previous commit
(wrong WNOHANG).
This test is still racy and breaks like once every 30,000 execution.
This is down like from once from every 100th execution in the past.
The remaning race is not specific to attach2 and I can reproduce it with
at least attach1. It still looks like being specific to NetBSD and it's
not reproducible on Linux and FreeBSD. Perhaps a bug with pipe(2)/write(2=
)/
read(2) or close to these features.
Sponsored by <The NetBSD Foundation>
Add a new function in ATF t_ptrace_wait*: await_zombie_raw()
Add await_zombie_raw() that is the same as await_zombie(), whith an
addition of additional "useconds_t ms" parameter indicating delays betwee=
n
new polling for a zombie process.
This new function will be used for testing a race condition that has been=
observed occassionally crashing a test case -- returning duplicate entrie=
s
for KERN_PROC_PID.
Sponsored by <The NetBSD Foundation>
ATF t_ptrace_wait*: Disable debug messages in msg.h
msg.h is a dummy IPC interface.
Disable additional debugging logging here, especially wanted in race*
tests.
Sponsored by <The NetBSD Foundation>
ATF: Add new test race1 in t_ptrace_wait*
Reuse the attach1's test body for race1.
Add a new test race1:
Assert that await_zombie() in attach1 always finds a single
process and no other error is reported
race1 requires HAVE_PID in wait(2)-like function.
This test is executed in a loop for 5 seconds (16k iterations on Intel i7=
).
A buggy kernel was asserting an error within this timeframe almost always=
=2E
The bug in the kernel is now gone and this test is expected to pass
correctly.
Sponsored by <The NetBSD Foundation>
Add check in ATF tests for security.models.extensions.user_set_dbregs
Introduce a new function can_we_set_dbregs() in the ATF ptrace(2) tests.
It uses lazy-bool evaluation whether a process can call PT_SETDBREGS.
In case of not being able to do so, print a message and mark a test
as skipped:
Either run this test as root or set sysctl(3)
security.models.extensions.user_set_dbregs to 1
No functional change intended to the code flow of the existing tested
scenarios.
Sponsored by <The NetBSD Foundation>
Improve documentation of the ATF test t_ptrace_wait*: traceme2
Set the description to:
Verify that a signal emitted by a tracer to a child is caught by
a signal handler.
Sponsored by <The NetBSD Foundation>
Merge code in tests: fork1 and vfork1 (ATF t_ptrace_wait*)
Marge bodies of two tests into the same function.
Add few checks for regular fork or not (vfork).
Sponsored by <The NetBSD Foundation>
ATF: ptrace: Merge code in fork2 and vfork2 tests with (v)fork1 ones
Reduce code duplication, use the same function body with conditional
switches.
Sponsored by <The NetBSD Foundation>
ATF t_ptrace_wait* refactoring: vforkdone1 and vforkdone2
Merge vforkdone1 and vforkdone2 into other fork tests and reuse the same
function body fork_test().
There is an implicit enhancement in vforkdone2 that it was skipping
PTRACE_VFORK check. This test is now marked as expected failure.
PR kern/51630
Sponsored by <The NetBSD Foundation>
Cover more fork/vfork/vforkdone scenarios in ATF ptrace(2) tests
Use a shared common body for all the tests: fork1..fork8, vfork1..vfork8.=
Merge vforkdone1 and vforkdone2 into vfork* tests.
All the (v?)fork[1-8] tests cover:
- calling either fork(2) or vfork(2)
- tracking either enabled or disabled FORK, VFORK or VFORK_DONE
All the PTRACE_VFORK tests are marked as expected failure.
Sponsored by <The NetBSD Foundation>
diffstat:
tests/lib/libc/sys/msg.h | 10 +-
tests/lib/libc/sys/t_ptrace_wait.c | 941 ++++++++++++++------------------
tests/lib/libc/sys/t_ptrace_wait.h | 15 +-
tests/lib/libc/sys/t_ptrace_x86_wait.h | 95 ++-
4 files changed, 497 insertions(+), 564 deletions(-)
diffs (truncated from 1468 to 300 lines):
diff -r 2b2581b026dc -r 73888d295313 tests/lib/libc/sys/msg.h
--- a/tests/lib/libc/sys/msg.h Thu Apr 12 01:51:32 2018 +0000
+++ b/tests/lib/libc/sys/msg.h Thu Apr 12 13:02:20 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.h,v 1.1 2017/04/02 21:44:00 kamil Exp $ */
+/* $NetBSD: msg.h,v 1.1.8.1 2018/04/12 13:02:21 martin Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
CLOSEFD(fds->cfd[1]);
CLOSEFD(fds->pfd[0]);
- printf("Send %s\n", info);
+// printf("Send %s\n", info);
rv = write(fds->pfd[1], msg, len);
if (rv != (ssize_t)len)
return 1;
@@ -88,7 +88,7 @@
CLOSEFD(fds->pfd[1]);
CLOSEFD(fds->cfd[0]);
- printf("Send %s\n", info);
+// printf("Send %s\n", info);
rv = write(fds->cfd[1], msg, len);
if (rv != (ssize_t)len)
return 1;
@@ -106,7 +106,7 @@
CLOSEFD(fds->pfd[1]);
CLOSEFD(fds->cfd[0]);
- printf("Wait %s\n", info);
+// printf("Wait %s\n", info);
rv = read(fds->pfd[0], msg, len);
if (rv != (ssize_t)len)
return 1;
@@ -124,7 +124,7 @@
CLOSEFD(fds->cfd[1]);
CLOSEFD(fds->pfd[0]);
- printf("Wait %s\n", info);
+// printf("Wait %s\n", info);
rv = read(fds->cfd[0], msg, len);
if (rv != (ssize_t)len)
return 1;
diff -r 2b2581b026dc -r 73888d295313 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c Thu Apr 12 01:51:32 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c Thu Apr 12 13:02:20 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.9.2.2 2018/03/06 09:52:09 martin Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.9.2.3 2018/04/12 13:02:20 martin Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.9.2.2 2018/03/06 09:52:09 martin Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.9.2.3 2018/04/12 13:02:20 martin Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -48,6 +48,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
+#include <time.h>
#include <unistd.h>
#include <atf-c.h>
@@ -133,7 +134,8 @@
ATF_TC_HEAD(traceme2, tc)
{
atf_tc_set_md_var(tc, "descr",
- "Verify SIGSTOP followed by _exit(2) in a child");
+ "Verify that a signal emitted by a tracer to a child is caught by "
+ "a signal handler");
}
static int traceme2_caught = 0;
@@ -312,7 +314,8 @@
"Assert that tracer sees process termination before the parent");
}
-ATF_TC_BODY(attach1, tc)
+static void
+attach1_raw(bool raw)
{
struct msg_fds parent_tracee, parent_tracer;
const int exitval_tracee = 5;
@@ -372,8 +375,10 @@
PARENT_TO_CHILD("exit tracee", parent_tracee, msg);
DPRINTF("Detect that tracee is zombie\n");
- await_zombie(tracee);
-
+ if (raw)
+ await_zombie_raw(tracee, 0);
+ else
+ await_zombie(tracee);
DPRINTF("Assert that there is no status about tracee %d - "
"Tracer must detect zombie first - calling %s()\n", tracee,
@@ -402,6 +407,14 @@
msg_close(&parent_tracer);
msg_close(&parent_tracee);
}
+
+ATF_TC_BODY(attach1, tc)
+{
+
+ /* Reuse this test with race1 */
+ attach1_raw(false);
+}
+
#endif
#if defined(TWAIT_HAVE_PID)
@@ -424,9 +437,6 @@
int status;
#endif
- // Feature pending for refactoring
- atf_tc_expect_fail("test is racy");
-
DPRINTF("Spawn tracee\n");
SYSCALL_REQUIRE(msg_open(&parent_tracee) == 0);
tracee = atf_utils_fork();
@@ -500,16 +510,13 @@
DPRINTF("Wait for tracee to finish its job and exit - calling %s()\n",
TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, WNOHANG),
+ TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(tracee, &status, 0),
tracee);
validate_status_exited(status, exitval_tracee);
msg_close(&parent_tracer);
msg_close(&parent_tracee);
-
- // Test is racy
- ATF_REQUIRE(0 && "In order to get reliable failure, abort");
}
#endif
@@ -1314,21 +1321,14 @@
TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
}
-#if defined(TWAIT_HAVE_PID)
-ATF_TC(fork1);
-ATF_TC_HEAD(fork1, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that fork(2) is intercepted by ptrace(2) with EVENT_MASK "
- "set to PTRACE_FORK");
-}
-
-ATF_TC_BODY(fork1, tc)
+static void
+fork_test(pid_t (*fn)(void), bool trackfork, bool trackvfork,
+ bool trackvforkdone)
{
const int exitval = 5;
const int exitval2 = 15;
const int sigval = SIGSTOP;
- pid_t child, child2, wpid;
+ pid_t child, child2 = 0, wpid;
#if defined(TWAIT_HAVE_STATUS)
int status;
#endif
@@ -1337,6 +1337,10 @@
ptrace_event_t event;
const int elen = sizeof(event);
+ if (trackvfork) {
+ atf_tc_expect_fail("PR kern/51630");
+ }
+
DPRINTF("Before forking process PID=%d\n", getpid());
SYSCALL_REQUIRE((child = fork()) != -1);
if (child == 0) {
@@ -1346,7 +1350,7 @@
DPRINTF("Before raising %s from child\n", strsignal(sigval));
FORKEE_ASSERT(raise(sigval) == 0);
- FORKEE_ASSERT((child2 = fork()) != -1);
+ FORKEE_ASSERT((child2 = (fn)()) != -1);
if (child2 == 0)
_exit(exitval2);
@@ -1366,139 +1370,114 @@
validate_status_stopped(status, sigval);
- DPRINTF("Enable PTRACE_FORK in EVENT_MASK for the child %d\n", child);
- event.pe_set_event = PTRACE_FORK;
- SYSCALL_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1);
-
- DPRINTF("Before resuming the child process where it left off and "
- "without signal to be sent\n");
- DPRINTF("We expect two SIGTRAP events, for child %d (TRAP_CHLD, "
- "pe_report_event=PTRACE_FORK, state.pe_other_pid=child2) and "
- "for child2 (TRAP_CHLD, pe_report_event=PTRACE_FORK, "
- "state.pe_other_pid=child)\n", child);
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
- DPRINTF("Before calling %s() for the child %d\n", TWAIT_FNAME, child);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_stopped(status, SIGTRAP);
-
- SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1);
- ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
-
- child2 = state.pe_other_pid;
- DPRINTF("Reported PTRACE_FORK event with forkee %d\n", child2);
-
- DPRINTF("Before calling %s() for the forkee %d of the child %d\n",
- TWAIT_FNAME, child2, child);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
- child2);
-
- validate_status_stopped(status, SIGTRAP);
-
- SYSCALL_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child2, &state, slen) != -1);
- ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_FORK);
- ATF_REQUIRE_EQ(state.pe_other_pid, child);
-
- DPRINTF("Before resuming the forkee process where it left off and "
- "without signal to be sent\n");
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child2, (void *)1, 0) != -1);
-
- DPRINTF("Before resuming the child process where it left off and "
- "without signal to be sent\n");
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
- DPRINTF("Before calling %s() for the forkee - expected exited\n",
- TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child2, &status, 0),
- child2);
-
- validate_status_exited(status, exitval2);
-
- DPRINTF("Before calling %s() for the forkee - expected no process\n",
- TWAIT_FNAME);
- TWAIT_REQUIRE_FAILURE(ECHILD,
- wpid = TWAIT_GENERIC(child2, &status, 0));
-
- DPRINTF("Before calling %s() for the child - expected stopped "
- "SIGCHLD\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_stopped(status, SIGCHLD);
-
- DPRINTF("Before resuming the child process where it left off and "
- "without signal to be sent\n");
- SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
-
- DPRINTF("Before calling %s() for the child - expected exited\n",
- TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_exited(status, exitval);
-
- DPRINTF("Before calling %s() for the child - expected no process\n",
- TWAIT_FNAME);
- TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
-}
-#endif
-
-ATF_TC(fork2);
-ATF_TC_HEAD(fork2, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Verify that fork(2) is not intercepted by ptrace(2) with empty "
- "EVENT_MASK");
-}
-
-ATF_TC_BODY(fork2, tc)
-{
- const int exitval = 5;
- const int exitval2 = 15;
- const int sigval = SIGSTOP;
- pid_t child, child2, wpid;
-#if defined(TWAIT_HAVE_STATUS)
- int status;
-#endif
- ptrace_event_t event;
- const int elen = sizeof(event);
-
- DPRINTF("Before forking process PID=%d\n", getpid());
- SYSCALL_REQUIRE((child = fork()) != -1);
- if (child == 0) {
- DPRINTF("Before calling PT_TRACE_ME from child %d\n", getpid());
- FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1);
-
- DPRINTF("Before raising %s from child\n", strsignal(sigval));
Home |
Main Index |
Thread Index |
Old Index