Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebieder...
[linux-2.6-block.git] / arch / x86 / kernel / ptrace.c
index 8f8f197389db6bfeadca5f0ec670c4d773549fec..71691a8310e77eac2f8061f1bda1e0ece14bc949 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /* By Ross Biro 1/23/92 */
 /*
  * Pentium III FXSR, SSE support
@@ -24,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>
@@ -153,35 +155,6 @@ static inline bool invalid_selector(u16 value)
 
 #define FLAG_MASK              FLAG_MASK_32
 
-/*
- * X86_32 CPUs don't save ss and esp if the CPU is already in kernel mode
- * when it traps.  The previous stack will be directly underneath the saved
- * registers, and 'sp/ss' won't even have been saved. Thus the '&regs->sp'.
- *
- * Now, if the stack is empty, '&regs->sp' is out of range. In this
- * case we try to take the previous stack. To always return a non-null
- * stack pointer we fall back to regs as stack if no previous stack
- * exists.
- *
- * This is valid only for kernel mode traps.
- */
-unsigned long kernel_stack_pointer(struct pt_regs *regs)
-{
-       unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
-       unsigned long sp = (unsigned long)&regs->sp;
-       u32 *prev_esp;
-
-       if (context == (sp & ~(THREAD_SIZE - 1)))
-               return sp;
-
-       prev_esp = (u32 *)(context);
-       if (*prev_esp)
-               return (unsigned long)*prev_esp;
-
-       return (unsigned long)regs;
-}
-EXPORT_SYMBOL_GPL(kernel_stack_pointer);
-
 static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long regno)
 {
        BUILD_BUG_ON(offsetof(struct pt_regs, bx) != 0);
@@ -396,22 +369,12 @@ static int putreg(struct task_struct *child,
        case offsetof(struct user_regs_struct,fs_base):
                if (value >= TASK_SIZE_MAX)
                        return -EIO;
-               /*
-                * When changing the FS base, use do_arch_prctl_64()
-                * to set the index to zero and to set the base
-                * as requested.
-                */
-               if (child->thread.fsbase != value)
-                       return do_arch_prctl_64(child, ARCH_SET_FS, value);
+               x86_fsbase_write_task(child, value);
                return 0;
        case offsetof(struct user_regs_struct,gs_base):
-               /*
-                * Exactly the same here as the %fs handling above.
-                */
                if (value >= TASK_SIZE_MAX)
                        return -EIO;
-               if (child->thread.gsbase != value)
-                       return do_arch_prctl_64(child, ARCH_SET_GS, value);
+               x86_gsbase_write_task(child, value);
                return 0;
 #endif
        }
@@ -644,7 +607,8 @@ static unsigned long ptrace_get_debugreg(struct task_struct *tsk, int n)
        unsigned long val = 0;
 
        if (n < HBP_NUM) {
-               struct perf_event *bp = thread->ptrace_bps[n];
+               int index = array_index_nospec(n, HBP_NUM);
+               struct perf_event *bp = thread->ptrace_bps[index];
 
                if (bp)
                        val = bp->hw.info.address;
@@ -746,9 +710,6 @@ static int ioperm_get(struct task_struct *target,
 void ptrace_disable(struct task_struct *child)
 {
        user_disable_single_step(child);
-#ifdef TIF_SYSCALL_EMU
-       clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
-#endif
 }
 
 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION