From: supriya kannery <supriyak@in.ibm.com>
To: linux-kernel@vger.kernel.org
Subject: Incorrect order of last two arguments of ptrace for requests PPC_PTRACE_GETREGS, SETREGS, GETFPREGS, SETFPREGS
Date: Wed, 25 Oct 2006 16:23:14 +0530 [thread overview]
Message-ID: <453F421A.6070507@in.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 875 bytes --]
In ptrace, when request is PPC_PTRACE_GETREGS, SETREGS, GETFPREGS and
SETFPREGS, order of the last two arguments is not correct.
General format of ptrace is ptrace (request, pid, addr, data). For the
above mentioned request ids in ppc64, if we use ptrace like
long reg[32];
ptrace (PPC_PTRACE_GETREGS, pid, 0, ®[0]);
the return value is always -1.
If we exchange the last two arguments like,
ptrace (PPC_PTRACE_GETREGS, pid, ®[0], 0);
it works!
This is because PPC_PTRACE_GETREGS option for powerpc is implemented
such that general purpose
registers of the child process get copied to the address variable
instead of data variable. Same is
the case with other PPC request options PPC_PTRACE_SETREGS, GETFPREGS
and SETFPREGS.
Prepared a patch for this problem and tested with 2.6.18-rc6 kernel.
This patch can be applied directly to
2.6.19-rc3 kernel.
[-- Attachment #2: ppc_ptrace_params.patch --]
[-- Type: text/plain, Size: 3448 bytes --]
diff -Naurp linux-2.6.18-rc6/arch/powerpc/kernel/ptrace.c linux-2.6.18-rc6-mod/arch/powerpc/kernel/ptrace.c
--- linux-2.6.18-rc6/arch/powerpc/kernel/ptrace.c 2006-10-19 18:09:01.000000000 +0530
+++ linux-2.6.18-rc6-mod/arch/powerpc/kernel/ptrace.c 2006-10-19 18:11:37.000000000 +0530
@@ -406,7 +406,7 @@ long arch_ptrace(struct task_struct *chi
case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
- unsigned long __user *tmp = (unsigned long __user *)addr;
+ unsigned long __user *tmp = (unsigned long __user *)data;
for (i = 0; i < 32; i++) {
ret = put_user(*reg, tmp);
@@ -421,7 +421,7 @@ long arch_ptrace(struct task_struct *chi
case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
- unsigned long __user *tmp = (unsigned long __user *)addr;
+ unsigned long __user *tmp = (unsigned long __user *)data;
for (i = 0; i < 32; i++) {
ret = get_user(*reg, tmp);
@@ -436,7 +436,7 @@ long arch_ptrace(struct task_struct *chi
case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
- unsigned long __user *tmp = (unsigned long __user *)addr;
+ unsigned long __user *tmp = (unsigned long __user *)data;
flush_fp_to_thread(child);
@@ -453,7 +453,7 @@ long arch_ptrace(struct task_struct *chi
case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
- unsigned long __user *tmp = (unsigned long __user *)addr;
+ unsigned long __user *tmp = (unsigned long __user *)data;
flush_fp_to_thread(child);
diff -Naurp linux-2.6.18-rc6/arch/powerpc/kernel/ptrace32.c linux-2.6.18-rc6-mod/arch/powerpc/kernel/ptrace32.c
--- linux-2.6.18-rc6/arch/powerpc/kernel/ptrace32.c 2006-10-19 18:09:01.000000000 +0530
+++ linux-2.6.18-rc6-mod/arch/powerpc/kernel/ptrace32.c 2006-10-19 18:11:41.000000000 +0530
@@ -345,7 +345,7 @@ long compat_sys_ptrace(int request, int
case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
- unsigned int __user *tmp = (unsigned int __user *)addr;
+ unsigned int __user *tmp = (unsigned int __user *)data;
for (i = 0; i < 32; i++) {
ret = put_user(*reg, tmp);
@@ -360,7 +360,7 @@ long compat_sys_ptrace(int request, int
case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
- unsigned int __user *tmp = (unsigned int __user *)addr;
+ unsigned int __user *tmp = (unsigned int __user *)data;
for (i = 0; i < 32; i++) {
ret = get_user(*reg, tmp);
@@ -375,7 +375,7 @@ long compat_sys_ptrace(int request, int
case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
- unsigned int __user *tmp = (unsigned int __user *)addr;
+ unsigned int __user *tmp = (unsigned int __user *)data;
flush_fp_to_thread(child);
@@ -392,7 +392,7 @@ long compat_sys_ptrace(int request, int
case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
int i;
unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
- unsigned int __user *tmp = (unsigned int __user *)addr;
+ unsigned int __user *tmp = (unsigned int __user *)data;
flush_fp_to_thread(child);
next reply other threads:[~2006-10-25 10:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-25 10:53 supriya kannery [this message]
2006-10-25 20:43 ` Incorrect order of last two arguments of ptrace for requests PPC_PTRACE_GETREGS, SETREGS, GETFPREGS, SETFPREGS David Miller
2006-10-27 7:20 ` supriya kannery
2006-10-27 7:10 ` David Miller
2006-10-31 12:18 ` supriya kannery
2006-11-22 18:36 ` David Woodhouse
2006-11-22 21:35 ` Benjamin Herrenschmidt
2006-12-04 21:58 ` Anton Blanchard
2007-04-30 5:42 ` Paul Mackerras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=453F421A.6070507@in.ibm.com \
--to=supriyak@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox