Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/kernel Add new tests attach_pid0 and attach_pid1 to t_...
details: https://anonhg.NetBSD.org/src/rev/895365decfd9
branches: trunk
changeset: 818908:895365decfd9
user: kamil <kamil%NetBSD.org@localhost>
date: Sun Nov 06 16:24:16 2016 +0000
description:
Add new tests attach_pid0 and attach_pid1 to t_ptrace
attach_pid0 asserts that it is not valid to attach PID 0 as it is a special
kernel process.
assert_pid1 asserts that non-root user cannot attach to PID 1 as it is the
/dev/init process. This tests is skipped if run as root.
Sponsored by <The NetBSD Foundation>.
diffstat:
tests/kernel/t_ptrace.c | 37 +++++++++++++++++++++++++++++++++++--
1 files changed, 35 insertions(+), 2 deletions(-)
diffs (65 lines):
diff -r 5441499234b9 -r 895365decfd9 tests/kernel/t_ptrace.c
--- a/tests/kernel/t_ptrace.c Sun Nov 06 15:03:30 2016 +0000
+++ b/tests/kernel/t_ptrace.c Sun Nov 06 16:24:16 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace.c,v 1.10 2016/11/05 15:52:35 kamil Exp $ */
+/* $NetBSD: t_ptrace.c,v 1.11 2016/11/06 16:24:16 kamil Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_ptrace.c,v 1.10 2016/11/05 15:52:35 kamil Exp $");
+__RCSID("$NetBSD: t_ptrace.c,v 1.11 2016/11/06 16:24:16 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -622,6 +622,37 @@
ATF_REQUIRE(close(fds_totracer[1]) == 0);
}
+ATF_TC(attach_pid0);
+ATF_TC_HEAD(attach_pid0, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Assert that a debugger cannot attach to PID 0");
+}
+
+ATF_TC_BODY(attach_pid0, tc)
+{
+ errno = 0;
+ ATF_REQUIRE(ptrace(PT_ATTACH, 0, NULL, 0) == -1);
+ ATF_REQUIRE(errno == EPERM);
+}
+
+ATF_TC(attach_pid1);
+ATF_TC_HEAD(attach_pid1, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Assert that a debugger cannot attach to PID 1 (as non-root)");
+}
+
+ATF_TC_BODY(attach_pid1, tc)
+{
+ if (getuid() == 0)
+ atf_tc_skip("Test must be run as non-root");
+
+ errno = 0;
+ ATF_REQUIRE(ptrace(PT_ATTACH, 1, NULL, 0) == -1);
+ ATF_REQUIRE(errno == EPERM);
+}
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, traceme1);
@@ -629,6 +660,8 @@
ATF_TP_ADD_TC(tp, traceme3);
ATF_TP_ADD_TC(tp, traceme4);
ATF_TP_ADD_TC(tp, attach1);
+ ATF_TP_ADD_TC(tp, attach_pid0);
+ ATF_TP_ADD_TC(tp, attach_pid1);
return atf_no_error();
}
Home |
Main Index |
Thread Index |
Old Index