Blame rh1566890_speculative_store_bypass_so_added_more_per_task_speculation_control_CVE_2018_3639.patch

Alex Kashchenko af80df
diff --git openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp openjdk/hotspot/src/os/linux/vm/os_linux.cpp
Alex Kashchenko af80df
--- openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp
Alex Kashchenko af80df
+++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp
Alex Kashchenko af80df
@@ -103,6 +103,8 @@
Alex Kashchenko d6f9d0
 # include <inttypes.h>
Alex Kashchenko d6f9d0
 # include <sys ioctl.h="">
Alex Kashchenko d6f9d0
 
Alex Kashchenko d6f9d0
+#include <sys prctl.h="">
Alex Kashchenko d6f9d0
+
Alex Kashchenko d6f9d0
 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
Alex Kashchenko d6f9d0
 
Alex Kashchenko d6f9d0
 #ifndef _GNU_SOURCE
Alex Kashchenko af80df
@@ -4997,6 +4999,31 @@
Alex Kashchenko d6f9d0
   }
Alex Kashchenko d6f9d0
 }
Alex Kashchenko d6f9d0
 
Alex Kashchenko d6f9d0
+/* Per task speculation control */
Alex Kashchenko d6f9d0
+#ifndef PR_GET_SPECULATION_CTRL
Alex Kashchenko d6f9d0
+#define PR_GET_SPECULATION_CTRL    52
Alex Kashchenko d6f9d0
+#endif
Alex Kashchenko d6f9d0
+#ifndef PR_SET_SPECULATION_CTRL
Alex Kashchenko d6f9d0
+#define PR_SET_SPECULATION_CTRL    53
Alex Kashchenko d6f9d0
+#endif
Alex Kashchenko d6f9d0
+/* Speculation control variants */
Alex Kashchenko d6f9d0
+# undef PR_SPEC_STORE_BYPASS
Alex Kashchenko d6f9d0
+# define PR_SPEC_STORE_BYPASS          0
Alex Kashchenko d6f9d0
+/* Return and control values for PR_SET/GET_SPECULATION_CTRL */
Alex Kashchenko d6f9d0
+# undef PR_SPEC_NOT_AFFECTED
Alex Kashchenko d6f9d0
+# undef PR_SPEC_PRCTL
Alex Kashchenko d6f9d0
+# undef PR_SPEC_ENABLE
Alex Kashchenko d6f9d0
+# undef PR_SPEC_DISABLE
Alex Kashchenko d6f9d0
+# define PR_SPEC_NOT_AFFECTED          0
Alex Kashchenko d6f9d0
+# define PR_SPEC_PRCTL                 (1UL << 0)
Alex Kashchenko d6f9d0
+# define PR_SPEC_ENABLE                (1UL << 1)
Alex Kashchenko d6f9d0
+# define PR_SPEC_DISABLE               (1UL << 2)
Alex Kashchenko d6f9d0
+
Alex Kashchenko d6f9d0
+static void set_speculation() __attribute__((constructor));
Alex Kashchenko d6f9d0
+static void set_speculation() {
Alex Kashchenko d6f9d0
+  prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);
Alex Kashchenko d6f9d0
+}
Alex Kashchenko d6f9d0
+
Alex Kashchenko af80df
 // this is called _before_ most of the global arguments have been parsed
Alex Kashchenko d6f9d0
 void os::init(void) {
Alex Kashchenko d6f9d0
   char dummy;   /* used to get a guess on initial stack address */