Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-drm-fsl-dcu.git] / arch / x86_64 / kernel / ptrace.c
index 2d50024c9f308b8fb5f390fb46e88d33bc843d3d..9409117b9f1901c357a1e47c75909e8fa146d34e 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
-#include <linux/smp_lock.h>
 #include <linux/errno.h>
 #include <linux/ptrace.h>
 #include <linux/user.h>
@@ -116,17 +115,17 @@ unsigned long convert_rip_to_linear(struct task_struct *child, struct pt_regs *r
        return addr;
 }
 
-static int is_at_popf(struct task_struct *child, struct pt_regs *regs)
+static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
 {
        int i, copied;
-       unsigned char opcode[16];
+       unsigned char opcode[15];
        unsigned long addr = convert_rip_to_linear(child, regs);
 
        copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
        for (i = 0; i < copied; i++) {
                switch (opcode[i]) {
-               /* popf */
-               case 0x9d:
+               /* popf and iret */
+               case 0x9d: case 0xcf:
                        return 1;
 
                        /* CHECKME: 64 65 */
@@ -138,14 +137,17 @@ static int is_at_popf(struct task_struct *child, struct pt_regs *regs)
                case 0x26: case 0x2e:
                case 0x36: case 0x3e:
                case 0x64: case 0x65:
-               case 0xf0: case 0xf2: case 0xf3:
+               case 0xf2: case 0xf3:
                        continue;
 
-               /* REX prefixes */
                case 0x40 ... 0x4f:
+                       if (regs->cs != __USER_CS)
+                               /* 32-bit mode: register increment */
+                               return 0;
+                       /* 64-bit mode: REX prefix */
                        continue;
 
-                       /* CHECKME: f0, f2, f3 */
+                       /* CHECKME: f2, f3 */
 
                /*
                 * pushf: NOTE! We should probably not let
@@ -186,10 +188,8 @@ static void set_singlestep(struct task_struct *child)
         * ..but if TF is changed by the instruction we will trace,
         * don't mark it as being "us" that set it, so that we
         * won't clear it by hand later.
-        *
-        * AK: this is not enough, LAHF and IRET can change TF in user space too.
         */
-       if (is_at_popf(child, regs))
+       if (is_setting_trap_flag(child, regs))
                return;
 
        child->ptrace |= PT_DTRACE;
@@ -420,9 +420,13 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                                if ((0x5554 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
                                        break;
                        if (i == 4) {
-                               child->thread.debugreg7 = data;
+                         child->thread.debugreg7 = data;
+                         if (data)
+                               set_tsk_thread_flag(child, TIF_DEBUG);
+                         else
+                               clear_tsk_thread_flag(child, TIF_DEBUG);
                          ret = 0;
-                 }
+                       }
                  break;
                }
                break;
@@ -531,8 +535,12 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                }
                ret = 0;
                for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
-                       ret |= __get_user(tmp, (unsigned long __user *) data);
-                       putreg(child, ui, tmp);
+                       ret = __get_user(tmp, (unsigned long __user *) data);
+                       if (ret)
+                               break;
+                       ret = putreg(child, ui, tmp);
+                       if (ret)
+                               break;
                        data += sizeof(long);
                }
                break;