]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Set executable protection on schedctl pages only when necessary.
authorIvo Raisr <ivosh@ivosh.net>
Mon, 11 Jul 2016 21:05:03 +0000 (21:05 +0000)
committerIvo Raisr <ivosh@ivosh.net>
Mon, 11 Jul 2016 21:05:03 +0000 (21:05 +0000)
n-i-bz

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15903

configure.ac
coregrind/m_syswrap/syswrap-solaris.c

index dd4fcb93fa68992ce7879a879379ab7d511268a1..da433137b9fd3385dfc82d76da561e76b726aa5a 100644 (file)
@@ -3604,6 +3604,51 @@ if test "$solaris_fpchip_state_takes_underscore" = "yes"; then
             [Define to 1 if fpregset_t defines struct _fpchip_state])
 fi
 
+
+# Solaris-specific check determining if schedctl page shared between kernel
+# and userspace program is executable (illumos, older Solaris) or not (newer
+# Solaris).
+#
+# C-level symbol: SOLARIS_SCHEDCTL_PAGE_EXEC
+# Automake-level symbol: none
+#
+AC_MSG_CHECKING([if schedctl page is executable (Solaris-specific)])
+AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#include <assert.h>
+#include <fcntl.h>
+#include <procfs.h>
+#include <schedctl.h>
+#include <stdio.h>
+#include <unistd.h>
+]], [[
+    schedctl_t *scp = schedctl_init();
+    if (scp == NULL)
+        return 1;
+
+    int fd = open("/proc/self/map", O_RDONLY);
+    assert(fd >= 0);
+
+    prmap_t map;
+    ssize_t rd;
+    while ((rd = read(fd, &map, sizeof(map))) == sizeof(map)) {
+        if (map.pr_vaddr == ((uintptr_t) scp & PAGEMASK)) {
+            fprintf(stderr, "%#lx [%zu] %s\n", map.pr_vaddr, map.pr_size,
+                    (map.pr_mflags & MA_EXEC) ? "x" : "no-x");
+            return (map.pr_mflags & MA_EXEC);
+        }
+    }
+
+    return 1;
+]])], [
+solaris_schedctl_page_exec=no
+AC_MSG_RESULT([no])
+], [
+solaris_schedctl_page_exec=yes
+AC_MSG_RESULT([yes])
+AC_DEFINE([SOLARIS_SCHEDCTL_PAGE_EXEC], 1,
+          [Define to 1 if you have the schedctl page executable.])
+])
+
 else
 AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, false)
 AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, false)
index 84c9ff2f5eec66ff22cba78154725005e82332cc..c0bea44be33032511f5a9749b484ef8fc48fc63f 100644 (file)
@@ -9427,7 +9427,10 @@ POST(sys_schedctl)
    /* Returned address points to a block in a mapped page. */
    if (!VG_(am_find_anon_segment)(a)) {
       Addr page = VG_PGROUNDDN(a);
-      UInt prot = VKI_PROT_READ | VKI_PROT_WRITE | VKI_PROT_EXEC;
+      UInt prot = VKI_PROT_READ | VKI_PROT_WRITE;
+#     if defined(SOLARIS_SCHEDCTL_PAGE_EXEC)
+      prot |= VKI_PROT_EXEC;
+#     endif /* SOLARIS_SCHEDCTL_PAGE_EXEC */
       UInt flags = VKI_MAP_ANONYMOUS;
       /* The kernel always allocates one page for the sc_shared struct. */
       SizeT size = VKI_PAGE_SIZE;