Commit 9591c267 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

[PATCH] PA-RISC: ptrace fix

Fix ptrace(SINGLESTEP) through system call
Signed-off-by: default avatarRandolph Chung <tausq@parisc-linux.org>
Signed-off-by: default avatarMatthew Wilcox <willy@parisc-linux.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dedd3f09
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#undef DEBUG_PTRACE #undef DEBUG_PTRACE
#ifdef DEBUG_PTRACE #ifdef DEBUG_PTRACE
#define DBG(x) printk x #define DBG(x...) printk(x)
#else #else
#define DBG(x) #define DBG(x...)
#endif #endif
#ifdef __LP64__ #ifdef __LP64__
...@@ -138,9 +138,9 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -138,9 +138,9 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
if (copied != sizeof(tmp)) if (copied != sizeof(tmp))
goto out_tsk; goto out_tsk;
ret = put_user(tmp,(unsigned int *) data); ret = put_user(tmp,(unsigned int *) data);
DBG(("sys_ptrace(PEEK%s, %d, %lx, %lx) returning %ld, data %x\n", DBG("sys_ptrace(PEEK%s, %d, %lx, %lx) returning %ld, data %x\n",
request == PTRACE_PEEKTEXT ? "TEXT" : "DATA", request == PTRACE_PEEKTEXT ? "TEXT" : "DATA",
pid, oaddr, odata, ret, tmp)); pid, oaddr, odata, ret, tmp);
} }
else else
#endif #endif
...@@ -163,9 +163,9 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -163,9 +163,9 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
#ifdef __LP64__ #ifdef __LP64__
if (is_compat_task(child)) { if (is_compat_task(child)) {
unsigned int tmp = (unsigned int)data; unsigned int tmp = (unsigned int)data;
DBG(("sys_ptrace(POKE%s, %d, %lx, %lx)\n", DBG("sys_ptrace(POKE%s, %d, %lx, %lx)\n",
request == PTRACE_POKETEXT ? "TEXT" : "DATA", request == PTRACE_POKETEXT ? "TEXT" : "DATA",
pid, oaddr, odata)); pid, oaddr, odata);
addr &= 0xffffffffL; addr &= 0xffffffffL;
if (access_process_vm(child, addr, &tmp, sizeof(tmp), 1) == sizeof(tmp)) if (access_process_vm(child, addr, &tmp, sizeof(tmp), 1) == sizeof(tmp))
goto out_tsk; goto out_tsk;
...@@ -194,8 +194,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -194,8 +194,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
tmp = *(unsigned int *) ((char *) task_regs(child) + addr); tmp = *(unsigned int *) ((char *) task_regs(child) + addr);
ret = put_user(tmp, (unsigned int *) data); ret = put_user(tmp, (unsigned int *) data);
DBG(("sys_ptrace(PEEKUSR, %d, %lx, %lx) returning %ld, addr %lx, data %x\n", DBG("sys_ptrace(PEEKUSR, %d, %lx, %lx) returning %ld, addr %lx, data %x\n",
pid, oaddr, odata, ret, addr, tmp)); pid, oaddr, odata, ret, addr, tmp);
} }
else else
#endif #endif
...@@ -234,8 +234,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -234,8 +234,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
* BEWARE, if you set N, and then single step, it won't * BEWARE, if you set N, and then single step, it won't
* stop on the nullified instruction. * stop on the nullified instruction.
*/ */
DBG(("sys_ptrace(POKEUSR, %d, %lx, %lx)\n", DBG("sys_ptrace(POKEUSR, %d, %lx, %lx)\n",
pid, oaddr, odata)); pid, oaddr, odata);
data &= USER_PSW_BITS; data &= USER_PSW_BITS;
task_regs(child)->gr[0] &= ~USER_PSW_BITS; task_regs(child)->gr[0] &= ~USER_PSW_BITS;
task_regs(child)->gr[0] |= data; task_regs(child)->gr[0] |= data;
...@@ -248,9 +248,9 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -248,9 +248,9 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
goto out_tsk; goto out_tsk;
if ((addr = translate_usr_offset(addr)) < 0) if ((addr = translate_usr_offset(addr)) < 0)
goto out_tsk; goto out_tsk;
DBG(("sys_ptrace(POKEUSR, %d, %lx, %lx) addr %lx\n", DBG("sys_ptrace(POKEUSR, %d, %lx, %lx) addr %lx\n",
pid, oaddr, odata, addr)); pid, oaddr, odata, addr);
if (addr >= PT_FR0 && addr <= PT_FR31) { if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
/* Special case, fp regs are 64 bits anyway */ /* Special case, fp regs are 64 bits anyway */
*(unsigned int *) ((char *) task_regs(child) + addr) = data; *(unsigned int *) ((char *) task_regs(child) + addr) = data;
ret = 0; ret = 0;
...@@ -272,7 +272,7 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -272,7 +272,7 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
goto out_tsk; goto out_tsk;
if ((addr >= PT_GR1 && addr <= PT_GR31) || if ((addr >= PT_GR1 && addr <= PT_GR31) ||
addr == PT_IAOQ0 || addr == PT_IAOQ1 || addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
(addr >= PT_FR0 && addr <= PT_FR31) || (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
addr == PT_SAR) { addr == PT_SAR) {
*(unsigned long *) ((char *) task_regs(child) + addr) = data; *(unsigned long *) ((char *) task_regs(child) + addr) = data;
ret = 0; ret = 0;
...@@ -283,8 +283,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -283,8 +283,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
case PTRACE_CONT: case PTRACE_CONT:
ret = -EIO; ret = -EIO;
DBG(("sys_ptrace(%s)\n", DBG("sys_ptrace(%s)\n",
request == PTRACE_SYSCALL ? "SYSCALL" : "CONT")); request == PTRACE_SYSCALL ? "SYSCALL" : "CONT");
if ((unsigned long) data > _NSIG) if ((unsigned long) data > _NSIG)
goto out_tsk; goto out_tsk;
child->ptrace &= ~(PT_SINGLESTEP|PT_BLOCKSTEP); child->ptrace &= ~(PT_SINGLESTEP|PT_BLOCKSTEP);
...@@ -302,14 +302,14 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -302,14 +302,14 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
* sigkill. perhaps it should be put in the status * sigkill. perhaps it should be put in the status
* that it wants to exit. * that it wants to exit.
*/ */
DBG(("sys_ptrace(KILL)\n")); DBG("sys_ptrace(KILL)\n");
if (child->exit_state == EXIT_ZOMBIE) /* already dead */ if (child->exit_state == EXIT_ZOMBIE) /* already dead */
goto out_tsk; goto out_tsk;
child->exit_code = SIGKILL; child->exit_code = SIGKILL;
goto out_wake_notrap; goto out_wake_notrap;
case PTRACE_SINGLEBLOCK: case PTRACE_SINGLEBLOCK:
DBG(("sys_ptrace(SINGLEBLOCK)\n")); DBG("sys_ptrace(SINGLEBLOCK)\n");
ret = -EIO; ret = -EIO;
if ((unsigned long) data > _NSIG) if ((unsigned long) data > _NSIG)
goto out_tsk; goto out_tsk;
...@@ -326,10 +326,11 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -326,10 +326,11 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
goto out_wake; goto out_wake;
case PTRACE_SINGLESTEP: case PTRACE_SINGLESTEP:
DBG(("sys_ptrace(SINGLESTEP)\n")); DBG("sys_ptrace(SINGLESTEP)\n");
ret = -EIO; ret = -EIO;
if ((unsigned long) data > _NSIG) if ((unsigned long) data > _NSIG)
goto out_tsk; goto out_tsk;
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
child->ptrace &= ~PT_BLOCKSTEP; child->ptrace &= ~PT_BLOCKSTEP;
child->ptrace |= PT_SINGLESTEP; child->ptrace |= PT_SINGLESTEP;
...@@ -351,7 +352,7 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -351,7 +352,7 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
/* Don't wake up the child, but let the /* Don't wake up the child, but let the
parent know something happened. */ parent know something happened. */
si.si_code = TRAP_TRACE; si.si_code = TRAP_TRACE;
si.si_addr = (void *) (task_regs(child)->iaoq[0] & ~3); si.si_addr = (void __user *) (task_regs(child)->iaoq[0] & ~3);
si.si_signo = SIGTRAP; si.si_signo = SIGTRAP;
si.si_errno = 0; si.si_errno = 0;
force_sig_info(SIGTRAP, &si, child); force_sig_info(SIGTRAP, &si, child);
...@@ -397,8 +398,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data) ...@@ -397,8 +398,8 @@ long sys_ptrace(long request, pid_t pid, long addr, long data)
put_task_struct(child); put_task_struct(child);
out: out:
unlock_kernel(); unlock_kernel();
DBG(("sys_ptrace(%ld, %d, %lx, %lx) returning %ld\n", DBG("sys_ptrace(%ld, %d, %lx, %lx) returning %ld\n",
request, pid, oaddr, odata, ret)); request, pid, oaddr, odata, ret);
return ret; return ret;
} }
......
...@@ -47,7 +47,7 @@ struct pt_regs { ...@@ -47,7 +47,7 @@ struct pt_regs {
/* XXX should we use iaoq[1] or iaoq[0] ? */ /* XXX should we use iaoq[1] or iaoq[0] ? */
#define user_mode(regs) (((regs)->iaoq[0] & 3) ? 1 : 0) #define user_mode(regs) (((regs)->iaoq[0] & 3) ? 1 : 0)
#define user_space(regs) (((regs)->iasq[0] != 0) ? 1 : 0) #define user_space(regs) (((regs)->iasq[1] != 0) ? 1 : 0)
#define instruction_pointer(regs) ((regs)->iaoq[0] & ~3) #define instruction_pointer(regs) ((regs)->iaoq[0] & ~3)
#define profile_pc(regs) instruction_pointer(regs) #define profile_pc(regs) instruction_pointer(regs)
extern void show_regs(struct pt_regs *); extern void show_regs(struct pt_regs *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment