Blame SOURCES/rh1566890-CVE_2018_3639-speculative_store_bypass.patch

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