Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libc/sys Add new ATF tests in t_ptrace_wait*
details: https://anonhg.NetBSD.org/src/rev/1e1c6ac8d770
branches: trunk
changeset: 968598:1e1c6ac8d770
user: kamil <kamil%NetBSD.org@localhost>
date: Tue Jan 21 16:46:07 2020 +0000
description:
Add new ATF tests in t_ptrace_wait*
New tests:
- access_regs_set_unaligned_pc_0x1
- access_regs_set_unaligned_pc_0x3
- access_regs_set_unaligned_pc_0x7
The purpose of these tests is check whether unaligned PC can panic the
kernel. If there is a panic it is fine to return EINVAL on PT_SETREGS.
New tests check respectively pc |= 0x1, pc |= 0x3 and pc |= 0x7.
Inspired by https://marc.info/?l=openbsd-bugs&m=107558043319084&w=2
While there fix access_regs6 to really test PT_SETREGS.
diffstat:
tests/lib/libc/sys/t_ptrace_wait.c | 60 +++++++++++++++++++++++++++++++------
1 files changed, 49 insertions(+), 11 deletions(-)
diffs (111 lines):
diff -r 71dcfce78f02 -r 1e1c6ac8d770 tests/lib/libc/sys/t_ptrace_wait.c
--- a/tests/lib/libc/sys/t_ptrace_wait.c Tue Jan 21 16:27:53 2020 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.c Tue Jan 21 16:46:07 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $ */
+/* $NetBSD: t_ptrace_wait.c,v 1.147 2020/01/21 16:46:07 kamil Exp $ */
/*-
* Copyright (c) 2016, 2017, 2018, 2019 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace_wait.c,v 1.146 2020/01/08 17:22:40 mgorny Exp $");
+__RCSID("$NetBSD: t_ptrace_wait.c,v 1.147 2020/01/21 16:46:07 kamil Exp $");
#define __LEGACY_PT_LWPINFO
@@ -4439,9 +4439,22 @@
} else if (strcmp(aux, "pc") == 0) {
rgstr = PTRACE_REG_PC(&gpr);
DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr);
- } else if (strcmp(aux, "set_pc") == 0) {
+ } else if (strstr(aux, "set_pc") != NULL) {
rgstr = PTRACE_REG_PC(&gpr);
+ DPRINTF("Retrieved PC %" PRIxREGISTER "\n", rgstr);
+ if (strstr(aux, "0x1") != NULL) {
+ rgstr |= 0x1;
+ } else if (strstr(aux, "0x3") != NULL) {
+ rgstr |= 0x3;
+ } else if (strstr(aux, "0x7") != NULL) {
+ rgstr |= 0x7;
+ }
+ DPRINTF("Set PC %" PRIxREGISTER "\n", rgstr);
PTRACE_REG_SET_PC(&gpr, rgstr);
+ if (strcmp(aux, "set_pc") != 0) {
+ /* This call can fail with EINVAL or similar. */
+ ptrace(PT_SETREGS, child, &gpr, 0);
+ }
} else if (strcmp(aux, "sp") == 0) {
rgstr = PTRACE_REG_SP(&gpr);
DPRINTF("Retrieved %" PRIxREGISTER "\n", rgstr);
@@ -4451,7 +4464,7 @@
} else if (strcmp(aux, "setregs") == 0) {
DPRINTF("Call SETREGS for the child process\n");
SYSCALL_REQUIRE(
- ptrace(PT_GETREGS, child, &gpr, 0) != -1);
+ ptrace(PT_SETREGS, child, &gpr, 0) != -1);
}
}
#endif
@@ -4475,13 +4488,31 @@
"without signal to be sent\n");
SYSCALL_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1);
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child);
-
- validate_status_exited(status, exitval);
-
- DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
- TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0));
+ if (strstr(aux, "unaligned") != NULL) {
+ DPRINTF("Before resuming the child process where it left off "
+ "and without signal to be sent\n");
+ SYSCALL_REQUIRE(ptrace(PT_KILL, child, NULL, 0) != -1);
+
+ DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+ TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0),
+ child);
+
+ validate_status_signaled(status, SIGKILL, 0);
+
+ DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+ TWAIT_REQUIRE_FAILURE(ECHILD,
+ wpid = TWAIT_GENERIC(child, &status, 0));
+ } else {
+ DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+ TWAIT_REQUIRE_SUCCESS(
+ wpid = TWAIT_GENERIC(child, &status, 0), child);
+
+ validate_status_exited(status, exitval);
+
+ DPRINTF("Before calling %s() for the child\n", TWAIT_FNAME);
+ TWAIT_REQUIRE_FAILURE(ECHILD,
+ wpid = TWAIT_GENERIC(child, &status, 0));
+ }
}
#define ACCESS_REGS(test, regset, aux) \
@@ -4506,6 +4537,9 @@
ACCESS_REGS(access_regs4, "regs", "sp")
ACCESS_REGS(access_regs5, "regs", "intrv")
ACCESS_REGS(access_regs6, "regs", "setregs")
+ACCESS_REGS(access_regs_set_unaligned_pc_0x1, "regs", "set_pc+unaligned+0x1")
+ACCESS_REGS(access_regs_set_unaligned_pc_0x3, "regs", "set_pc+unaligned+0x3")
+ACCESS_REGS(access_regs_set_unaligned_pc_0x7, "regs", "set_pc+unaligned+0x7")
#endif
#if defined(HAVE_FPREGS)
ACCESS_REGS(access_fpregs1, "fpregs", "getfpregs")
@@ -8415,6 +8449,10 @@
ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs5);
ATF_TP_ADD_TC_HAVE_GPREGS(tp, access_regs6);
+ ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x1);
+ ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x3);
+ ATF_TP_ADD_TC(tp, access_regs_set_unaligned_pc_0x7);
+
ATF_TP_ADD_TC_HAVE_FPREGS(tp, access_fpregs1);
ATF_TP_ADD_TC_HAVE_FPREGS(tp, access_fpregs2);
Home |
Main Index |
Thread Index |
Old Index