Linus,

please pull the latest x86-pti-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-pti-for-linus

up to:  993773d11d45: x86/tls: Fix possible spectre-v1 in do_get_thread_area()

The speculative paranoia departement delivers a few more plugs for possible
(probably theoretical) spectre/mds leaks.

Thanks,

        tglx

------------------>
Dianzhang Chen (2):
      x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg()
      x86/tls: Fix possible spectre-v1 in do_get_thread_area()

Zhenzhong Duan (1):
      x86/speculation/mds: Eliminate leaks by trace_hardirqs_on()


 arch/x86/include/asm/mwait.h | 4 ++--
 arch/x86/kernel/ptrace.c     | 5 ++++-
 arch/x86/kernel/tls.c        | 9 +++++++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index eb0f80ce8524..e28f8b723b5c 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -86,9 +86,9 @@ static inline void __mwaitx(unsigned long eax, unsigned long 
ebx,
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
-       mds_idle_clear_cpu_buffers();
-
        trace_hardirqs_on();
+
+       mds_idle_clear_cpu_buffers();
        /* "mwait %eax, %ecx;" */
        asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
                     :: "a" (eax), "c" (ecx));
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index a166c960bc9e..cbac64659dc4 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -25,6 +25,7 @@
 #include <linux/rcupdate.h>
 #include <linux/export.h>
 #include <linux/context_tracking.h>
+#include <linux/nospec.h>
 
 #include <linux/uaccess.h>
 #include <asm/pgtable.h>
@@ -643,9 +644,11 @@ static unsigned long ptrace_get_debugreg(struct 
task_struct *tsk, int n)
 {
        struct thread_struct *thread = &tsk->thread;
        unsigned long val = 0;
+       int index = n;
 
        if (n < HBP_NUM) {
-               struct perf_event *bp = thread->ptrace_bps[n];
+               index = array_index_nospec(index, HBP_NUM);
+               struct perf_event *bp = thread->ptrace_bps[index];
 
                if (bp)
                        val = bp->hw.info.address;
diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
index a5b802a12212..71d3fef1edc9 100644
--- a/arch/x86/kernel/tls.c
+++ b/arch/x86/kernel/tls.c
@@ -5,6 +5,7 @@
 #include <linux/user.h>
 #include <linux/regset.h>
 #include <linux/syscalls.h>
+#include <linux/nospec.h>
 
 #include <linux/uaccess.h>
 #include <asm/desc.h>
@@ -220,6 +221,7 @@ int do_get_thread_area(struct task_struct *p, int idx,
                       struct user_desc __user *u_info)
 {
        struct user_desc info;
+       int index;
 
        if (idx == -1 && get_user(idx, &u_info->entry_number))
                return -EFAULT;
@@ -227,8 +229,11 @@ int do_get_thread_area(struct task_struct *p, int idx,
        if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
                return -EINVAL;
 
-       fill_user_desc(&info, idx,
-                      &p->thread.tls_array[idx - GDT_ENTRY_TLS_MIN]);
+       index = idx - GDT_ENTRY_TLS_MIN;
+       index = array_index_nospec(index,
+                       GDT_ENTRY_TLS_MAX - GDT_ENTRY_TLS_MIN + 1);
+
+       fill_user_desc(&info, idx, &p->thread.tls_array[index]);
 
        if (copy_to_user(u_info, &info, sizeof(info)))
                return -EFAULT;

Reply via email to