Merge branch 'classmate' into release
[safe/jmp/linux-2.6] / arch / s390 / kernel / ptrace.c
index 2815bfe..13815d3 100644 (file)
@@ -26,7 +26,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>
 #include <linux/signal.h>
 #include <linux/elf.h>
 #include <linux/regset.h>
-
+#include <linux/tracehook.h>
+#include <linux/seccomp.h>
+#include <trace/syscall.h>
+#include <asm/compat.h>
 #include <asm/segment.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include "compat_ptrace.h"
 #endif
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum s390_regset {
        REGSET_GENERAL,
        REGSET_FP,
+       REGSET_GENERAL_EXTENDED,
 };
 
 static void
@@ -68,7 +74,7 @@ FixPerRegisters(struct task_struct *task)
        if (per_info->single_step) {
                per_info->control_regs.bits.starting_addr = 0;
 #ifdef CONFIG_COMPAT
-               if (test_thread_flag(TIF_31BIT))
+               if (is_compat_task())
                        per_info->control_regs.bits.ending_addr = 0x7fffffffUL;
                else
 #endif
@@ -170,6 +176,13 @@ static unsigned long __peek_user(struct task_struct *child, addr_t addr)
                 */
                tmp = (addr_t) task_pt_regs(child)->orig_gpr2;
 
+       } else if (addr < (addr_t) &dummy->regs.fp_regs) {
+               /*
+                * prevent reads of padding hole between
+                * orig_gpr2 and fp_regs on s390.
+                */
+               tmp = 0;
+
        } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
                /* 
                 * floating point regs. are stored in the thread structure
@@ -196,7 +209,6 @@ static unsigned long __peek_user(struct task_struct *child, addr_t addr)
 static int
 peek_user(struct task_struct *child, addr_t addr, addr_t data)
 {
-       struct user *dummy = NULL;
        addr_t tmp, mask;
 
        /*
@@ -205,8 +217,8 @@ peek_user(struct task_struct *child, addr_t addr, addr_t data)
         */
        mask = __ADDR_MASK;
 #ifdef CONFIG_64BIT
-       if (addr >= (addr_t) &dummy->regs.acrs &&
-           addr < (addr_t) &dummy->regs.orig_gpr2)
+       if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
+           addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
                mask = 3;
 #endif
        if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
@@ -270,6 +282,13 @@ static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
                 */
                task_pt_regs(child)->orig_gpr2 = data;
 
+       } else if (addr < (addr_t) &dummy->regs.fp_regs) {
+               /*
+                * prevent writes of padding hole between
+                * orig_gpr2 and fp_regs on s390.
+                */
+               return 0;
+
        } else if (addr < (addr_t) (&dummy->regs.fp_regs + 1)) {
                /*
                 * floating point regs. are stored in the thread structure
@@ -297,7 +316,6 @@ static int __poke_user(struct task_struct *child, addr_t addr, addr_t data)
 static int
 poke_user(struct task_struct *child, addr_t addr, addr_t data)
 {
-       struct user *dummy = NULL;
        addr_t mask;
 
        /*
@@ -306,8 +324,8 @@ poke_user(struct task_struct *child, addr_t addr, addr_t data)
         */
        mask = __ADDR_MASK;
 #ifdef CONFIG_64BIT
-       if (addr >= (addr_t) &dummy->regs.acrs &&
-           addr < (addr_t) &dummy->regs.orig_gpr2)
+       if (addr >= (addr_t) &((struct user *) NULL)->regs.acrs &&
+           addr < (addr_t) &((struct user *) NULL)->regs.orig_gpr2)
                mask = 3;
 #endif
        if ((addr & mask) || addr > sizeof(struct user) - __ADDR_MASK)
@@ -322,24 +340,10 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        int copied, ret;
 
        switch (request) {
-       case PTRACE_PEEKTEXT:
-       case PTRACE_PEEKDATA:
-               /* Remove high order bit from address (only for 31 bit). */
-               addr &= PSW_ADDR_INSN;
-               /* read word at location addr. */
-               return generic_ptrace_peekdata(child, addr, data);
-
        case PTRACE_PEEKUSR:
                /* read the word at location addr in the USER area. */
                return peek_user(child, addr, data);
 
-       case PTRACE_POKETEXT:
-       case PTRACE_POKEDATA:
-               /* Remove high order bit from address (only for 31 bit). */
-               addr &= PSW_ADDR_INSN;
-               /* write the word at location addr. */
-               return generic_ptrace_pokedata(child, addr, data);
-
        case PTRACE_POKEUSR:
                /* write the word at location addr in the USER area */
                return poke_user(child, addr, data);
@@ -369,8 +373,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                        copied += sizeof(unsigned long);
                }
                return 0;
+       default:
+               /* Removing high order bit from addr (only for 31 bit). */
+               addr &= PSW_ADDR_INSN;
+               return ptrace_request(child, request, addr, data);
        }
-       return ptrace_request(child, request, addr, data);
 }
 
 #ifdef CONFIG_COMPAT
@@ -428,6 +435,13 @@ static u32 __peek_user_compat(struct task_struct *child, addr_t addr)
                 */
                tmp = *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4);
 
+       } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
+               /*
+                * prevent reads of padding hole between
+                * orig_gpr2 and fp_regs on s390.
+                */
+               tmp = 0;
+
        } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
                /*
                 * floating point regs. are stored in the thread structure 
@@ -462,8 +476,7 @@ static int peek_user_compat(struct task_struct *child,
 {
        __u32 tmp;
 
-       if (!test_thread_flag(TIF_31BIT) ||
-           (addr & 3) || addr > sizeof(struct user) - 3)
+       if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user) - 3)
                return -EIO;
 
        tmp = __peek_user_compat(child, addr);
@@ -514,6 +527,13 @@ static int __poke_user_compat(struct task_struct *child,
                 */
                *(__u32*)((addr_t) &task_pt_regs(child)->orig_gpr2 + 4) = tmp;
 
+       } else if (addr < (addr_t) &dummy32->regs.fp_regs) {
+               /*
+                * prevent writess of padding hole between
+                * orig_gpr2 and fp_regs on s390.
+                */
+               return 0;
+
        } else if (addr < (addr_t) (&dummy32->regs.fp_regs + 1)) {
                /*
                 * floating point regs. are stored in the thread structure 
@@ -557,8 +577,7 @@ static int __poke_user_compat(struct task_struct *child,
 static int poke_user_compat(struct task_struct *child,
                            addr_t addr, addr_t data)
 {
-       if (!test_thread_flag(TIF_31BIT) ||
-           (addr & 3) || addr > sizeof(struct user32) - 3)
+       if (!is_compat_task() || (addr & 3) || addr > sizeof(struct user32) - 3)
                return -EIO;
 
        return __poke_user_compat(child, addr, data);
@@ -611,40 +630,53 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 }
 #endif
 
-asmlinkage void
-syscall_trace(struct pt_regs *regs, int entryexit)
+asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 {
-       if (unlikely(current->audit_context) && entryexit)
-               audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]), regs->gprs[2]);
+       long ret;
 
-       if (!test_thread_flag(TIF_SYSCALL_TRACE))
-               goto out;
-       if (!(current->ptrace & PT_PTRACED))
-               goto out;
-       ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
-                                ? 0x80 : 0));
+       /* Do the secure computing check first. */
+       secure_computing(regs->gprs[2]);
 
        /*
-        * If the debuffer has set an invalid system call number,
-        * we prepare to skip the system call restart handling.
+        * The sysc_tracesys code in entry.S stored the system
+        * call number to gprs[2].
         */
-       if (!entryexit && regs->gprs[2] >= NR_syscalls)
-               regs->trap = -1;
-
-       /*
-        * this isn't the same as continuing with a signal, but it will do
-        * for normal use.  strace only continues with a signal if the
-        * stopping signal is not SIGTRAP.  -brl
-        */
-       if (current->exit_code) {
-               send_sig(current->exit_code, current, 1);
-               current->exit_code = 0;
+       ret = regs->gprs[2];
+       if (test_thread_flag(TIF_SYSCALL_TRACE) &&
+           (tracehook_report_syscall_entry(regs) ||
+            regs->gprs[2] >= NR_syscalls)) {
+               /*
+                * Tracing decided this syscall should not happen or the
+                * debugger stored an invalid system call number. Skip
+                * the system call and the system call restart handling.
+                */
+               regs->svcnr = 0;
+               ret = -1;
        }
- out:
-       if (unlikely(current->audit_context) && !entryexit)
-               audit_syscall_entry(test_thread_flag(TIF_31BIT)?AUDIT_ARCH_S390:AUDIT_ARCH_S390X,
-                                   regs->gprs[2], regs->orig_gpr2, regs->gprs[3],
-                                   regs->gprs[4], regs->gprs[5]);
+
+       if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+               trace_sys_enter(regs, regs->gprs[2]);
+
+       if (unlikely(current->audit_context))
+               audit_syscall_entry(is_compat_task() ?
+                                       AUDIT_ARCH_S390 : AUDIT_ARCH_S390X,
+                                   regs->gprs[2], regs->orig_gpr2,
+                                   regs->gprs[3], regs->gprs[4],
+                                   regs->gprs[5]);
+       return ret;
+}
+
+asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
+{
+       if (unlikely(current->audit_context))
+               audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
+                                  regs->gprs[2]);
+
+       if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+               trace_sys_exit(regs, regs->gprs[2]);
+
+       if (test_thread_flag(TIF_SYSCALL_TRACE))
+               tracehook_report_syscall_exit(regs, 0);
 }
 
 /*
@@ -848,6 +880,67 @@ static int s390_compat_regs_set(struct task_struct *target,
        return rc;
 }
 
+static int s390_compat_regs_high_get(struct task_struct *target,
+                                    const struct user_regset *regset,
+                                    unsigned int pos, unsigned int count,
+                                    void *kbuf, void __user *ubuf)
+{
+       compat_ulong_t *gprs_high;
+
+       gprs_high = (compat_ulong_t *)
+               &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
+       if (kbuf) {
+               compat_ulong_t *k = kbuf;
+               while (count > 0) {
+                       *k++ = *gprs_high;
+                       gprs_high += 2;
+                       count -= sizeof(*k);
+               }
+       } else {
+               compat_ulong_t __user *u = ubuf;
+               while (count > 0) {
+                       if (__put_user(*gprs_high, u++))
+                               return -EFAULT;
+                       gprs_high += 2;
+                       count -= sizeof(*u);
+               }
+       }
+       return 0;
+}
+
+static int s390_compat_regs_high_set(struct task_struct *target,
+                                    const struct user_regset *regset,
+                                    unsigned int pos, unsigned int count,
+                                    const void *kbuf, const void __user *ubuf)
+{
+       compat_ulong_t *gprs_high;
+       int rc = 0;
+
+       gprs_high = (compat_ulong_t *)
+               &task_pt_regs(target)->gprs[pos / sizeof(compat_ulong_t)];
+       if (kbuf) {
+               const compat_ulong_t *k = kbuf;
+               while (count > 0) {
+                       *gprs_high = *k++;
+                       *gprs_high += 2;
+                       count -= sizeof(*k);
+               }
+       } else {
+               const compat_ulong_t  __user *u = ubuf;
+               while (count > 0 && !rc) {
+                       unsigned long word;
+                       rc = __get_user(word, u++);
+                       if (rc)
+                               break;
+                       *gprs_high = word;
+                       *gprs_high += 2;
+                       count -= sizeof(*u);
+               }
+       }
+
+       return rc;
+}
+
 static const struct user_regset s390_compat_regsets[] = {
        [REGSET_GENERAL] = {
                .core_note_type = NT_PRSTATUS,
@@ -865,6 +958,14 @@ static const struct user_regset s390_compat_regsets[] = {
                .get = s390_fpregs_get,
                .set = s390_fpregs_set,
        },
+       [REGSET_GENERAL_EXTENDED] = {
+               .core_note_type = NT_S390_HIGH_GPRS,
+               .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
+               .size = sizeof(compat_long_t),
+               .align = sizeof(compat_long_t),
+               .get = s390_compat_regs_high_get,
+               .set = s390_compat_regs_high_set,
+       },
 };
 
 static const struct user_regset_view user_s390_compat_view = {