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 Introduce can_we_write_to_text() to ATF p...



details:   https://anonhg.NetBSD.org/src/rev/e64564edeac3
branches:  trunk
changeset: 322972:e64564edeac3
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sat May 26 15:15:17 2018 +0000

description:
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>

diffstat:

 tests/lib/libc/sys/t_ptrace_wait.h |  19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diffs (33 lines):

diff -r 69e776588cc3 -r e64564edeac3 tests/lib/libc/sys/t_ptrace_wait.h
--- a/tests/lib/libc/sys/t_ptrace_wait.h        Sat May 26 14:39:20 2018 +0000
+++ b/tests/lib/libc/sys/t_ptrace_wait.h        Sat May 26 15:15:17 2018 +0000
@@ -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 @@
 }
 #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)
 {



Home | Main Index | Thread Index | Old Index