Module Name: src
Committed By: kamil
Date: Sat May 26 15:15:17 UTC 2018
Modified Files:
src/tests/lib/libc/sys: t_ptrace_wait.h
Log Message:
Introduce can_we_write_to_text() to ATF ptrace(2) tests
The purpose of this function is to detect whether a tracer can write to the
.text section of its tracee.
Sponsored by <The NetBSD Foundation>
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libc/sys/t_ptrace_wait.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libc/sys/t_ptrace_wait.h
diff -u src/tests/lib/libc/sys/t_ptrace_wait.h:1.7 src/tests/lib/libc/sys/t_ptrace_wait.h:1.8
--- src/tests/lib/libc/sys/t_ptrace_wait.h:1.7 Thu May 24 08:28:40 2018
+++ src/tests/lib/libc/sys/t_ptrace_wait.h Sat May 26 15:15:17 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ptrace_wait.h,v 1.7 2018/05/24 08:28:40 kamil Exp $ */
+/* $NetBSD: t_ptrace_wait.h,v 1.8 2018/05/26 15:15:17 kamil Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -504,6 +504,23 @@ can_we_set_dbregs(void)
}
#endif
+static bool __used
+can_we_write_to_text(pid_t pid)
+{
+ int mib[3];
+ int paxflags;
+ size_t len = sizeof(int);
+
+ mib[0] = CTL_PROC;
+ mib[1] = pid;
+ mib[2] = PROC_PID_PAXFLAGS;
+
+ if (sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)
+ return false;
+
+ return !(paxflags & CTL_PROC_PAXFLAGS_MPROTECT);
+}
+
static void __used
trigger_trap(void)
{