Blame SOURCES/rh1566890-CVE_2018_3639-speculative_store_bypass.patch

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