changeset 6665:efa98ed4bd43

PR3608: CVE-2018-3639 hw: cpu: speculative store bypass mitigation
author andrew
date Tue, 03 Jul 2018 04:06:06 +0100
parents 6941480b5b05
children e012acbfcd40
files src/os/linux/vm/os_linux.cpp
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/os/linux/vm/os_linux.cpp	Mon Jul 02 15:58:25 2018 +0100
+++ b/src/os/linux/vm/os_linux.cpp	Tue Jul 03 04:06:06 2018 +0100
@@ -124,6 +124,8 @@
 # include <inttypes.h>
 # include <sys/ioctl.h>
 
+#include <sys/prctl.h>
+
 #ifndef _GNU_SOURCE
   #define _GNU_SOURCE
   #include <sched.h>
@@ -4838,6 +4840,31 @@
   }
 }
 
+/* Per task speculation control */
+#ifndef PR_GET_SPECULATION_CTRL
+#define PR_GET_SPECULATION_CTRL    52
+#endif
+#ifndef PR_SET_SPECULATION_CTRL
+#define PR_SET_SPECULATION_CTRL    53
+#endif
+/* Speculation control variants */
+# undef PR_SPEC_STORE_BYPASS
+# define PR_SPEC_STORE_BYPASS          0
+/* Return and control values for PR_SET/GET_SPECULATION_CTRL */
+# undef PR_SPEC_NOT_AFFECTED
+# undef PR_SPEC_PRCTL
+# undef PR_SPEC_ENABLE
+# undef PR_SPEC_DISABLE
+# define PR_SPEC_NOT_AFFECTED          0
+# define PR_SPEC_PRCTL                 (1UL << 0)
+# define PR_SPEC_ENABLE                (1UL << 1)
+# define PR_SPEC_DISABLE               (1UL << 2)
+
+static void set_speculation() __attribute__((constructor));
+static void set_speculation() {
+  prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
+}
+
 // this is called _before_ the most of global arguments have been parsed
 void os::init(void) {
   char dummy;   /* used to get a guess on initial stack address */