Blame SOURCES/rh1566890-CVE_2018_3639-speculative_store_bypass.patch

b6221f
diff --git openjdk/src/hotspot/os/linux/os_linux.cpp openjdk/src/hotspot/os/linux/os_linux.cpp
b6221f
--- openjdk/src/hotspot/os/linux/os_linux.cpp
b6221f
+++ openjdk/src/hotspot/os/linux/os_linux.cpp
b6221f
@@ -107,6 +107,8 @@
b6221f
 # include <inttypes.h>
b6221f
 # include <sys/ioctl.h>
b6221f
 
b6221f
+#include <sys/prctl.h>
b6221f
+
b6221f
 #ifndef _GNU_SOURCE
b6221f
   #define _GNU_SOURCE
b6221f
   #include <sched.h>
b6221f
@@ -4984,6 +4986,48 @@
b6221f
 extern void report_error(char* file_name, int line_no, char* title,
b6221f
                          char* format, ...);
b6221f
 
b6221f
+/* Per task speculation control */
b6221f
+#ifndef PR_GET_SPECULATION_CTRL
b6221f
+# define PR_GET_SPECULATION_CTRL    52
b6221f
+#endif
b6221f
+#ifndef PR_SET_SPECULATION_CTRL
b6221f
+# define PR_SET_SPECULATION_CTRL    53
b6221f
+#endif
b6221f
+/* Speculation control variants */
b6221f
+#ifndef PR_SPEC_STORE_BYPASS
b6221f
+# define PR_SPEC_STORE_BYPASS          0
b6221f
+#endif
b6221f
+/* Return and control values for PR_SET/GET_SPECULATION_CTRL */
b6221f
+
b6221f
+#ifndef PR_SPEC_NOT_AFFECTED
b6221f
+# define PR_SPEC_NOT_AFFECTED          0
b6221f
+#endif
b6221f
+#ifndef PR_SPEC_PRCTL
b6221f
+# define PR_SPEC_PRCTL                 (1UL << 0)
b6221f
+#endif
b6221f
+#ifndef PR_SPEC_ENABLE
b6221f
+# define PR_SPEC_ENABLE                (1UL << 1)
b6221f
+#endif
b6221f
+#ifndef PR_SPEC_DISABLE
b6221f
+# define PR_SPEC_DISABLE               (1UL << 2)
b6221f
+#endif
b6221f
+#ifndef PR_SPEC_FORCE_DISABLE
b6221f
+# define PR_SPEC_FORCE_DISABLE         (1UL << 3)
b6221f
+#endif
b6221f
+#ifndef PR_SPEC_DISABLE_NOEXEC
b6221f
+# define PR_SPEC_DISABLE_NOEXEC        (1UL << 4)
b6221f
+#endif
b6221f
+
b6221f
+static void set_speculation() __attribute__((constructor));
b6221f
+static void set_speculation() {
b6221f
+  if ( prctl(PR_SET_SPECULATION_CTRL,
b6221f
+             PR_SPEC_STORE_BYPASS,
b6221f
+             PR_SPEC_DISABLE_NOEXEC, 0, 0) == 0 ) {
b6221f
+    return;
b6221f
+  }
b6221f
+  prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
b6221f
+}
b6221f
+
b6221f
 // this is called _before_ most of the global arguments have been parsed
b6221f
 void os::init(void) {
b6221f
   char dummy;   // used to get a guess on initial stack address