Skip to contentSkip to conversation

ptrace cleanups

RFC PATCH Superseded Namhyung Kim 6 participants 62 messages Aug 27, 2010 – Aug 30, 2010

Subsystems (15)
Arm (32-bit) x86 PowerPC MIPS +11 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ptrace cleanups

Hello,

This patchset tries to cleanup architecture independent/dependent part of ptrace syscall. Specifically it changes prototype of sys_ptrace() to have its arguments @addr and @data to be unsigned long. Since user space API of ptrace() declares them as void pointers, and most of archs consider them unsigned already in their arch_ptrace(), it would be no harmful to change them from (signed) long into unsigned long, IMHO.

ptrace() code accesses user area using above arguments frequently, changing them enables to drop unnecessary __force markup when casting them to __user pointers because sparse allows it only in case of unsigned long. And some duplicated/misused castings can be grouped into one place in favor of new variables to cleanup code further. This was suggested by Arnd Bergmann and comment from Christoph Hellwig was also helpful.

Although I couldn't test all archs, I hope it will not break anything. Exceptional case will be "03/43 ptrace: change signature of arch_ptrace()" commit since it changes prototype of arch_ptrace() in system header file. It *will* break your build if it is applied alone, please use it with your arch counterpart. The same goes vice versa, of course.

Any comments would be appreciated.
Thanks.

Namhyung Kim (43):
ptrace: change signature of sys_ptrace() and friends
ptrace: cleanup ptrace_request()
ptrace: change signature of arch_ptrace() ptrace, x86: change signature of arch_ptrace() ptrace, x86: cleanup arch_ptrace()
ptrace, alpha: change signature of arch_ptrace() ptrace, arm: change signature of arch_ptrace() ptrace, arm: cleanup arch_ptrace()
ptrace, avr32: change signature of arch_ptrace() ptrace, avr32: cleanup arch_ptrace()
ptrace, blackfin: change signature of arch_ptrace() ptrace, cris-v10: change signature of arch_ptrace() ptrace, cris-v32: change signature of arch_ptrace() ptrace, frv: change signature of arch_ptrace() ptrace, frv: cleanup arch_ptrace()
ptrace, h8300: change signature of arch_ptrace() ptrace, h8300: cleanup arch_ptrace()
ptrace, ia64: change signature of arch_ptrace() ptrace, m32r: change signature of arch_ptrace() ptrace, m32r: cleanup arch_ptrace()
ptrace, m68k: change signature of arch_ptrace() ptrace, m68k: cleanup arch_ptrace()
ptrace, m68knommu: change signature of arch_ptrace() ptrace, m68knommu: cleanup arch_ptrace() ptrace, microblaze: change signature of arch_ptrace() ptrace, mips: change signature of arch_ptrace() ptrace, mips: cleanup arch_ptrace()
ptrace, mn10300: change signature of arch_ptrace() ptrace, mn10300: cleanup arch_ptrace() ptrace, parisc: change signature of arch_ptrace() ptrace, powerpc: change signature of arch_ptrace() ptrace, powerpc: cleanup arch_ptrace() ptrace, s390: change signature of arch_ptrace() ptrace, score: change signature of arch_ptrace() ptrace, sh: change signature of arch_ptrace() ptrace, sh: cleanup arch_ptrace()
ptrace, sparc: change signature of arch_ptrace() ptrace, sparc: cleanup arch_ptrace()
ptrace, tile: change signature of arch_ptrace() ptrace, um: change signature of arch_ptrace() ptrace, um: cleanup arch_ptrace()
ptrace, xtensa: change signature of arch_ptrace() ptrace, xtensa: cleanup arch_ptrace()

 arch/alpha/kernel/ptrace.c         |    7 ++--
 arch/arm/kernel/ptrace.c           |   36 +++++++++++--------
 arch/avr32/kernel/ptrace.c         |   11 +++---
 arch/blackfin/kernel/ptrace.c      |   16 +++++----
 arch/cris/arch-v10/kernel/ptrace.c |   11 +++---
 arch/cris/arch-v32/kernel/ptrace.c |    7 ++--
 arch/frv/kernel/ptrace.c           |   32 ++++++++---------
 arch/h8300/kernel/ptrace.c         |   33 +++++++++--------
 arch/ia64/kernel/ptrace.c          |    3 +-
 arch/m32r/kernel/ptrace.c          |   11 +++---
 arch/m68k/kernel/ptrace.c          |   51 +++++++++++++-------------
 arch/m68knommu/kernel/ptrace.c     |   70 ++++++++++++++++++-----------------
 arch/microblaze/kernel/ptrace.c    |    7 ++--
 arch/mips/kernel/ptrace.c          |   26 +++++++------
 arch/mn10300/kernel/ptrace.c       |   20 +++++-----
 arch/parisc/kernel/ptrace.c        |   13 ++++---
 arch/powerpc/kernel/ptrace.c       |   70 +++++++++++++++++++----------------
 arch/s390/kernel/ptrace.c          |    3 +-
 arch/score/kernel/ptrace.c         |    7 ++--
 arch/sh/kernel/ptrace_32.c         |   51 ++++++++++++++------------
 arch/sh/kernel/ptrace_64.c         |   27 ++++++++------
 arch/sparc/kernel/ptrace_32.c      |   57 +++++++++++------------------
 arch/sparc/kernel/ptrace_64.c      |   15 ++++----
 arch/tile/kernel/ptrace.c          |   11 +++---
 arch/um/kernel/ptrace.c            |   26 +++++++-------
 arch/um/sys-i386/ptrace.c          |    4 +-
 arch/um/sys-x86_64/ptrace.c        |   11 +++---
 arch/x86/kernel/ptrace.c           |   23 +++++-------
 arch/xtensa/kernel/ptrace.c        |   14 ++++---
 include/linux/ptrace.h             |   12 ++++--
 include/linux/syscalls.h           |    3 +-
 kernel/ptrace.c                    |   29 +++++++++------
 32 files changed, 375 insertions(+), 342 deletions(-)

--
1.7.2.2

#1 lore raw

RFC PATCH 1/43 ptrace: change signature of sys_ptrace() and friends

Since user space API of ptrace syscall defines @addr and @data as void pointers, it would be more appropriate to define them as unsigned long in kernel. Therefore related functions are changed also.

---
 include/linux/ptrace.h   |    9 ++++++---
 include/linux/syscalls.h |    3 ++-
 kernel/ptrace.c          |   16 ++++++++++------
 3 files changed, 18 insertions(+), 10 deletions(-)
include/linux/ptrace.h +6 -3
index 4272521..67a4cd7 100644
@@ -108,7 +108,8 @@ extern int ptrace_attach(struct task_struct *tsk);
 extern int ptrace_detach(struct task_struct *, unsigned int);
 extern void ptrace_disable(struct task_struct *);
 extern int ptrace_check_attach(struct task_struct *task, int kill);
-extern int ptrace_request(struct task_struct *child, long request, long addr, long data);
+extern int ptrace_request(struct task_struct *child, long request,
+			  unsigned long addr, unsigned long data);
 extern void ptrace_notify(int exit_code);
 extern void __ptrace_link(struct task_struct *child,
 			  struct task_struct *new_parent);
@@ -132,8 +133,10 @@ static inline void ptrace_unlink(struct task_struct *child)
 		__ptrace_unlink(child);
 }
 
-int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data);
-int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data);
+int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
+			    unsigned long data);
+int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
+			    unsigned long data);
 
 /**
  * task_ptrace - return %PT_* flags that apply to a task
include/linux/syscalls.h +2 -1
index e6319d1..cacc27a 100644
@@ -701,7 +701,8 @@ asmlinkage long sys_nfsservctl(int cmd,
 asmlinkage long sys_syslog(int type, char __user *buf, int len);
 asmlinkage long sys_uselib(const char __user *library);
 asmlinkage long sys_ni_syscall(void);
-asmlinkage long sys_ptrace(long request, long pid, long addr, long data);
+asmlinkage long sys_ptrace(long request, long pid, unsigned long addr,
+			   unsigned long data);
 
 asmlinkage long sys_add_key(const char __user *_type,
 			    const char __user *_description,
kernel/ptrace.c +10 -6
index f34d798..f838afe 100644
@@ -402,7 +402,7 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
 	return copied;
 }
 
-static int ptrace_setoptions(struct task_struct *child, long data)
+static int ptrace_setoptions(struct task_struct *child, unsigned long data)
 {
 	child->ptrace &= ~PT_TRACE_MASK;
 
@@ -481,7 +481,8 @@ static int ptrace_setsiginfo(struct task_struct *child, const siginfo_t *info)
 #define is_sysemu_singlestep(request)	0
 #endif
 
-static int ptrace_resume(struct task_struct *child, long request, long data)
+static int ptrace_resume(struct task_struct *child, long request,
+			 unsigned long data)
 {
 	if (!valid_signal(data))
 		return -EIO;
@@ -558,7 +559,7 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,
 #endif
 
 int ptrace_request(struct task_struct *child, long request,
-		   long addr, long data)
+		   unsigned long addr, unsigned long data)
 {
 	int ret = -EIO;
 	siginfo_t siginfo;
@@ -691,7 +692,8 @@ static struct task_struct *ptrace_get_task_struct(pid_t pid)
 #define arch_ptrace_attach(child)	do { } while (0)
 #endif
 
-SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
+SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
+		unsigned long, data)
 {
 	struct task_struct *child;
 	long ret;
@@ -732,7 +734,8 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
 	return ret;
 }
 
-int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
+int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
+			    unsigned long data)
 {
 	unsigned long tmp;
 	int copied;
@@ -743,7 +746,8 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
 	return put_user(tmp, (unsigned long __user *)data);
 }
 
-int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
+int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
+			    unsigned long data)
 {
 	int copied;
 
Signature · 1 line
1.7.2.2
Acked-by on v1 1/43
#2 lore raw

Re: [RFC PATCH 01/43] ptrace: change signature of sys_ptrace() and friends

Quoted 6 lines · Namhyung Kim

Since user space API of ptrace syscall defines @addr and @data as void pointers, it would be more appropriate to define them as unsigned long in kernel. Therefore related functions are changed also.

Looks good to me. It may be worth mentioning in the changelog that 'unsigned long' is typically used in other places in the kernel as an opaque data type and that using this helps cleaning up a lot of warnings from sparse.

#3 lore raw

Re: [RFC PATCH 01/43] ptrace: change signature of sys_ptrace() and friends

Quoted 6 lines · Arnd Bergmann

Looks good to me. It may be worth mentioning in the changelog that 'unsigned long' is typically used in other places in the kernel as an opaque data type and that using this helps cleaning up a lot of warnings from sparse.

Thank you. Will add it.

Signature · 2 lines
Regards,
Namhyung Kim
#4 lore raw

RFC PATCH 2/43 ptrace: cleanup ptrace_request()

In reply to Namhyung Kim

use new local variable to remove unnecesary casting, but it requires put_user() to be changed to copy_to_user().

---
 kernel/ptrace.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
kernel/ptrace.c +7 -6
index f838afe..1084bef 100644
@@ -563,6 +563,7 @@ int ptrace_request(struct task_struct *child, long request,
 {
 	int ret = -EIO;
 	siginfo_t siginfo;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 	case PTRACE_PEEKTEXT:
@@ -579,19 +580,19 @@ int ptrace_request(struct task_struct *child, long request,
 		ret = ptrace_setoptions(child, data);
 		break;
 	case PTRACE_GETEVENTMSG:
-		ret = put_user(child->ptrace_message, (unsigned long __user *) data);
+		ret = copy_to_user(datap, &child->ptrace_message,
+				   sizeof (child->ptrace_message)) ?
+			-EFAULT : 0;
 		break;
 
 	case PTRACE_GETSIGINFO:
 		ret = ptrace_getsiginfo(child, &siginfo);
 		if (!ret)
-			ret = copy_siginfo_to_user((siginfo_t __user *) data,
-						   &siginfo);
+			ret = copy_siginfo_to_user(datap, &siginfo);
 		break;
 
 	case PTRACE_SETSIGINFO:
-		if (copy_from_user(&siginfo, (siginfo_t __user *) data,
-				   sizeof siginfo))
+		if (copy_from_user(&siginfo, datap, sizeof siginfo))
 			ret = -EFAULT;
 		else
 			ret = ptrace_setsiginfo(child, &siginfo);
@@ -622,7 +623,7 @@ int ptrace_request(struct task_struct *child, long request,
 		}
 		mmput(mm);
 
-		ret = put_user(tmp, (unsigned long __user *) data);
+		ret = copy_to_user(datap, &tmp, sizeof tmp) ? -EFAULT : 0;
 		break;
 	}
 #endif
Signature · 1 line
1.7.2.2
#5 lore raw

Re: [RFC PATCH 02/43] ptrace: cleanup ptrace_request()

Quoted 7 lines · Namhyung Kim
kernel/ptrace.c +2 -1
@@ -579,19 +580,19 @@ int ptrace_request(struct task_struct *child, long request,
                ret = ptrace_setoptions(child, data);
                break;
        case PTRACE_GETEVENTMSG:
-               ret = put_user(child->ptrace_message, (unsigned long __user *) data);
+               ret = copy_to_user(datap, &child->ptrace_message,
+                                  sizeof (child->ptrace_message)) ?

kernel/ptrace.c int ptrace_request(struct task_struct *child, long request, · line 592

Quoted 10 lines
kernel/ptrace.c +2 -2
+                       -EFAULT : 0;
                break;
 
        case PTRACE_GETSIGINFO:
                ret = ptrace_getsiginfo(child, &siginfo);
                if (!ret)
-                       ret = copy_siginfo_to_user((siginfo_t __user *) data,
-                                                  &siginfo);
+                       ret = copy_siginfo_to_user(datap, &siginfo);
                break;

If you introduce two pointers, 'siginfo_t __user *usiginfo' and 'unsigned long __user *datap' instead of just 'datap', you can use get_user/put_user everywhere, which would make the code better readable and faster.

Otherwise this change looks good.

Arnd

#6 lore raw

Re: [RFC PATCH 02/43] ptrace: cleanup ptrace_request()

Quoted 7 lines · Arnd Bergmann

If you introduce two pointers, 'siginfo_t __user *usiginfo' and 'unsigned long __user *datap' instead of just 'datap', you can use get_user/put_user everywhere, which would make the code better readable and faster.

Otherwise this change looks good.

Despite I don't know how much it can run faster, I just want to keep it as is unless it would be a serious mistake. :-)

Signature · 2 lines
Regards,
Namhyung Kim
#7 lore raw

Re: [RFC PATCH 02/43] ptrace: cleanup ptrace_request()

Quoted 11 lines · On Friday 27 August 2010 18:13:35 Namhyung Kim wrote:
Quoted 7 lines · Arnd Bergmann

If you introduce two pointers, 'siginfo_t __user *usiginfo' and 'unsigned long __user *datap' instead of just 'datap', you can use get_user/put_user everywhere, which would make the code better readable and faster.

Otherwise this change looks good.

Despite I don't know how much it can run faster, I just want to keep it as is unless it would be a serious mistake. :-)

No, not a mistake, your code is fine as it is and not performance critical at all.

However, in general using get_user/put_user is preferred over copy_from_user/copy_to_user for scalar values.

Arnd

#8 lore raw

RFC PATCH 3/43 ptrace: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long.

NOTE: This patch might break build if applied alone so should be used with your arch counterpart.

---
 include/linux/ptrace.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
include/linux/ptrace.h +2 -1
index 67a4cd7..092a04f 100644
@@ -100,7 +100,8 @@
 #include <linux/sched.h>		/* For struct task_struct.  */
 
 
-extern long arch_ptrace(struct task_struct *child, long request, long addr, long data);
+extern long arch_ptrace(struct task_struct *child, long request,
+			unsigned long addr, unsigned long data);
 extern int ptrace_traceme(void);
 extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
 extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len);
Signature · 1 line
1.7.2.2
#9 lore raw

Re: [RFC PATCH 03/43] ptrace: change signature of arch_ptrace()

Quoted 6 lines · Namhyung Kim

change type of @addr and @data into unsigned long.

NOTE: This patch might break build if applied alone so should be used with your arch counterpart.

Would it be possible to rearrange your patches so that you don't break anything in the middle? I think merging all the trivial 'change signature' patches into one would also make reviewing easier. Nobody in their right mind is looking through a full series of 43 patches, especially if they do not make sense on their own, but one patch that changes a function signature tree-wide would be looked at by many people and can be applied standalone.

It does make sense to keep the 'foo: clean up arch_ptrace' patches separate though, since they are also useful on their own and need real review by the arch maintainers.

Arnd

#10 lore raw

Re: [RFC PATCH 03/43] ptrace: change signature of arch_ptrace()

Quoted 8 lines · Arnd Bergmann

Would it be possible to rearrange your patches so that you don't break anything in the middle? I think merging all the trivial 'change signature' patches into one would also make reviewing easier. Nobody in their right mind is looking through a full series of 43 patches, especially if they do not make sense on their own, but one patch that changes a function signature tree-wide would be looked at by many people and can be applied standalone.

OK. Will combine those.
BTW, one thing I wonder is it will have huge CC list of arch maintainers in commit message, so is it usual? or is there other way?

Signature · 2 lines
Regards,
Namhyung Kim
#11 lore raw

Re: [RFC PATCH 03/43] ptrace: change signature of arch_ptrace()

Quoted 10 lines · On Friday 27 August 2010 18:20:55 Namhyung Kim wrote:
Quoted 8 lines · Arnd Bergmann

Would it be possible to rearrange your patches so that you don't break anything in the middle? I think merging all the trivial 'change signature' patches into one would also make reviewing easier. Nobody in their right mind is looking through a full series of 43 patches, especially if they do not make sense on their own, but one patch that changes a function signature tree-wide would be looked at by many people and can be applied standalone.

Quoted 3 lines

OK. Will combine those.
BTW, one thing I wonder is it will have huge CC list of arch maintainers in commit message, so is it usual? or is there other way?

I'd say you don't have to for a trivial patch such at this, as long as you keep [email protected] on Cc, since that has all the arch maintainers. It also doesn't hurt to keep them all on Cc, since it would only be a single mail then.

Arnd

#12 lore raw

RFC PATCH 4/43 ptrace, x86: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/ptrace.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
arch/x86/kernel/ptrace.c +6 -7
index 70c4872..ea7766a 100644
@@ -801,7 +801,8 @@ void ptrace_disable(struct task_struct *child)
 static const struct user_regset_view user_x86_32_view; /* Initialized below. */
 #endif
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
@@ -812,8 +813,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		unsigned long tmp;
 
 		ret = -EIO;
-		if ((addr & (sizeof(data) - 1)) || addr < 0 ||
-		    addr >= sizeof(struct user))
+		if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user))
 			break;
 
 		tmp = 0;  /* Default return condition */
@@ -830,8 +830,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
 	case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
 		ret = -EIO;
-		if ((addr & (sizeof(data) - 1)) || addr < 0 ||
-		    addr >= sizeof(struct user))
+		if ((addr & (sizeof(data) - 1)) || addr >= sizeof(struct user))
 			break;
 
 		if (addr < sizeof(struct user_regs_struct))
@@ -888,14 +887,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
 	case PTRACE_GET_THREAD_AREA:
-		if (addr < 0)
+		if ((int) addr < 0)
 			return -EIO;
 		ret = do_get_thread_area(child, addr,
 					 (struct user_desc __user *) data);
 		break;
 
 	case PTRACE_SET_THREAD_AREA:
-		if (addr < 0)
+		if ((int) addr < 0)
 			return -EIO;
 		ret = do_set_thread_area(child, addr,
 					 (struct user_desc __user *) data, 0);
Signature · 1 line
1.7.2.2
#13 lore raw

RFC PATCH 5/43 ptrace, x86: cleanup arch_ptrace()

In reply to Namhyung Kim

change type of 'datap' variable into void pointer in order to remove unnecessary castings.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/ptrace.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
arch/x86/kernel/ptrace.c +4 -6
index ea7766a..29c17610 100644
@@ -805,7 +805,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
-	unsigned long __user *datap = (unsigned long __user *)data;
+	void __user *datap = (void __user *)data;
 
 	switch (request) {
 	/* read the word at location addr in the USER area. */
@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
 			addr -= offsetof(struct user, u_debugreg[0]);
 			tmp = ptrace_get_debugreg(child, addr / sizeof(data));
 		}
-		ret = put_user(tmp, datap);
+		ret = copy_to_user(datap, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 		break;
 	}
 
@@ -889,15 +889,13 @@ long arch_ptrace(struct task_struct *child, long request,
 	case PTRACE_GET_THREAD_AREA:
 		if ((int) addr < 0)
 			return -EIO;
-		ret = do_get_thread_area(child, addr,
-					 (struct user_desc __user *) data);
+		ret = do_get_thread_area(child, addr, datap);
 		break;
 
 	case PTRACE_SET_THREAD_AREA:
 		if ((int) addr < 0)
 			return -EIO;
-		ret = do_set_thread_area(child, addr,
-					 (struct user_desc __user *) data, 0);
+		ret = do_set_thread_area(child, addr, datap, 0);
 		break;
 #endif
 
Signature · 1 line
1.7.2.2
#14 lore raw

RFC PATCH 6/43 ptrace, alpha: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
---
 arch/alpha/kernel/ptrace.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/alpha/kernel/ptrace.c +4 -3
index baa9036..e2af5eb 100644
@@ -269,7 +269,8 @@ void ptrace_disable(struct task_struct *child)
 	user_disable_single_step(child);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long tmp;
 	size_t copied;
@@ -292,7 +293,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	case PTRACE_PEEKUSR:
 		force_successful_syscall_return();
 		ret = get_reg(child, addr);
-		DBG(DBG_MEM, ("peek $%ld->%#lx\n", addr, ret));
+		DBG(DBG_MEM, ("peek $%lu->%#lx\n", addr, ret));
 		break;
 
 	/* When I and D space are separate, this will have to be fixed.  */
@@ -302,7 +303,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		break;
 
 	case PTRACE_POKEUSR: /* write the specified register */
-		DBG(DBG_MEM, ("poke $%ld<-%#lx\n", addr, data));
+		DBG(DBG_MEM, ("poke $%lu<-%#lx\n", addr, data));
 		ret = put_reg(child, addr, data);
 		break;
 	default:
Signature · 1 line
1.7.2.2
#15 lore raw

RFC PATCH 7/43 ptrace, arm: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/arm/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/arm/kernel/ptrace.c +2 -1
index f99d489..87ca2c7 100644
@@ -847,7 +847,8 @@ static int ptrace_setvfpregs(struct task_struct *tsk, void __user *data)
 }
 #endif
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 
Signature · 1 line
1.7.2.2
#16 lore raw

RFC PATCH 8/43 ptrace, arm: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'datap' variable type of void pointer in order to remove unnecessary castings.

---
 arch/arm/kernel/ptrace.c |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)
arch/arm/kernel/ptrace.c +19 -14
index 87ca2c7..4be8a58 100644
@@ -851,10 +851,11 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 		case PTRACE_PEEKUSR:
-			ret = ptrace_read_user(child, addr, (unsigned long __user *)data);
+			ret = ptrace_read_user(child, addr, datap);
 			break;
 
 		case PTRACE_POKEUSR:
@@ -862,35 +863,39 @@ long arch_ptrace(struct task_struct *child, long request,
 			break;
 
 		case PTRACE_GETREGS:
-			ret = ptrace_getregs(child, (void __user *)data);
+			ret = ptrace_getregs(child, datap);
 			break;
 
 		case PTRACE_SETREGS:
-			ret = ptrace_setregs(child, (void __user *)data);
+			ret = ptrace_setregs(child, datap);
 			break;
 
 		case PTRACE_GETFPREGS:
-			ret = ptrace_getfpregs(child, (void __user *)data);
+			ret = ptrace_getfpregs(child, datap);
 			break;
 		
 		case PTRACE_SETFPREGS:
-			ret = ptrace_setfpregs(child, (void __user *)data);
+			ret = ptrace_setfpregs(child, datap);
 			break;
 
 #ifdef CONFIG_IWMMXT
 		case PTRACE_GETWMMXREGS:
-			ret = ptrace_getwmmxregs(child, (void __user *)data);
+			ret = ptrace_getwmmxregs(child, datap);
 			break;
 
 		case PTRACE_SETWMMXREGS:
-			ret = ptrace_setwmmxregs(child, (void __user *)data);
+			ret = ptrace_setwmmxregs(child, datap);
 			break;
 #endif
 
-		case PTRACE_GET_THREAD_AREA:
-			ret = put_user(task_thread_info(child)->tp_value,
-				       (unsigned long __user *) data);
+		case PTRACE_GET_THREAD_AREA: {
+			unsigned long tpval;
+			tpval = task_thread_info(child)->tp_value;
+			
+			ret = copy_to_user(datap, &tpval, sizeof(tpval)) ?
+				-EFAULT : 0;
 			break;
+		}
 
 		case PTRACE_SET_SYSCALL:
 			task_thread_info(child)->syscall = data;
@@ -899,21 +904,21 @@ long arch_ptrace(struct task_struct *child, long request,
 
 #ifdef CONFIG_CRUNCH
 		case PTRACE_GETCRUNCHREGS:
-			ret = ptrace_getcrunchregs(child, (void __user *)data);
+			ret = ptrace_getcrunchregs(child, datap);
 			break;
 
 		case PTRACE_SETCRUNCHREGS:
-			ret = ptrace_setcrunchregs(child, (void __user *)data);
+			ret = ptrace_setcrunchregs(child, datap);
 			break;
 #endif
 
 #ifdef CONFIG_VFP
 		case PTRACE_GETVFPREGS:
-			ret = ptrace_getvfpregs(child, (void __user *)data);
+			ret = ptrace_getvfpregs(child, datap);
 			break;
 
 		case PTRACE_SETVFPREGS:
-			ret = ptrace_setvfpregs(child, (void __user *)data);
+			ret = ptrace_setvfpregs(child, datap);
 			break;
 #endif
 
Signature · 1 line
1.7.2.2
#17 lore raw

RFC PATCH 9/43 ptrace, avr32: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Haavard Skinnemoen <[email protected]>

---
 arch/avr32/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/avr32/kernel/ptrace.c +2 -1
index 5e73c25..ecea9b6 100644
@@ -146,7 +146,8 @@ static int ptrace_setregs(struct task_struct *tsk, const void __user *uregs)
 	return ret;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 
Signature · 1 line
1.7.2.2
#18 lore raw

RFC PATCH 10/43 ptrace, avr32: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'datap' variable type of void pointer in order to remove unnecessary castings.

Cc Haavard Skinnemoen <[email protected]>
---
 arch/avr32/kernel/ptrace.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
arch/avr32/kernel/ptrace.c +4 -4
index ecea9b6..4aedcab 100644
@@ -150,6 +150,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 	/* Read the word at location addr in the child process */
@@ -159,8 +160,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		break;
 
 	case PTRACE_PEEKUSR:
-		ret = ptrace_read_user(child, addr,
-				       (unsigned long __user *)data);
+		ret = ptrace_read_user(child, addr, datap);
 		break;
 
 	/* Write the word in data at location addr */
@@ -174,11 +174,11 @@ long arch_ptrace(struct task_struct *child, long request,
 		break;
 
 	case PTRACE_GETREGS:
-		ret = ptrace_getregs(child, (void __user *)data);
+		ret = ptrace_getregs(child, datap);
 		break;
 
 	case PTRACE_SETREGS:
-		ret = ptrace_setregs(child, (const void __user *)data);
+		ret = ptrace_setregs(child, datap);
 		break;
 
 	default:
Signature · 1 line
1.7.2.2
#20 lore raw

RFC PATCH 11/43 ptrace, blackfin: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

{get,put}_reg() also be changed because they are used only in arch_ptrace() and this can make one of argument checking unnecessary. And castings to void pointer can be removed by make use of datap.

Cc Mike Frysinger <[email protected]>
---
 arch/blackfin/kernel/ptrace.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
arch/blackfin/kernel/ptrace.c +9 -7
index 6ec7768..545fc14 100644
@@ -37,12 +37,13 @@
  * Get contents of register REGNO in task TASK.
  */
 static inline long
-get_reg(struct task_struct *task, long regno, unsigned long __user *datap)
+get_reg(struct task_struct *task, unsigned long regno,
+	unsigned long __user *datap)
 {
 	long tmp;
 	struct pt_regs *regs = task_pt_regs(task);
 
-	if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0)
+	if (regno & 3 || regno > PT_LAST_PSEUDO)
 		return -EIO;
 
 	switch (regno) {
@@ -73,11 +74,11 @@ get_reg(struct task_struct *task, long regno, unsigned long __user *datap)
  * Write contents of register REGNO in task TASK.
  */
 static inline int
-put_reg(struct task_struct *task, long regno, unsigned long data)
+put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
 {
 	struct pt_regs *regs = task_pt_regs(task);
 
-	if (regno & 3 || regno > PT_LAST_PSEUDO || regno < 0)
+	if (regno & 3 || regno > PT_LAST_PSEUDO)
 		return -EIO;
 
 	switch (regno) {
@@ -232,7 +233,8 @@ void user_disable_single_step(struct task_struct *child)
 	clear_tsk_thread_flag(child, TIF_SINGLESTEP);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
@@ -360,14 +362,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		return copy_regset_to_user(child, &user_bfin_native_view,
 					   REGSET_GENERAL,
 					   0, sizeof(struct pt_regs),
-					   (void __user *)data);
+					   datap);
 
 	case PTRACE_SETREGS:
 		pr_debug("ptrace: PTRACE_SETREGS\n");
 		return copy_regset_from_user(child, &user_bfin_native_view,
 					     REGSET_GENERAL,
 					     0, sizeof(struct pt_regs),
-					     (const void __user *)data);
+					     datap);
 
 	case_default:
 	default:
Signature · 1 line
1.7.2.2
#21 lore raw

RFC PATCH 12/43 ptrace, cris-v10: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Also fix misc bug on datap.

Cc Mikael Starvik <[email protected]>
Cc Jesper Nilsson <[email protected]>
---
 arch/cris/arch-v10/kernel/ptrace.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
arch/cris/arch-v10/kernel/ptrace.c +6 -5
index e70c804..9f02416 100644
@@ -76,7 +76,8 @@ ptrace_disable(struct task_struct *child)
  * (in user space) where the result of the ptrace call is written (instead of
  * being returned).
  */
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
@@ -93,7 +94,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			unsigned long tmp;
 
 			ret = -EIO;
-			if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
+			if ((addr & 3) || addr > PT_MAX << 2)
 				break;
 
 			tmp = get_reg(child, addr >> 2);
@@ -110,7 +111,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
  		/* Write the word at location address in the USER area. */
 		case PTRACE_POKEUSR:
 			ret = -EIO;
-			if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
+			if ((addr & 3) || addr > PT_MAX << 2)
 				break;
 
 			addr >>= 2;
@@ -141,7 +142,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 					break;
 				}
 				
-				data += sizeof(long);
+				datap++;
 			}
 
 			break;
@@ -165,7 +166,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				}
 				
 				put_reg(child, i, tmp);
-				data += sizeof(long);
+				datap++;
 			}
 			
 			break;
Signature · 1 line
1.7.2.2
#22 lore raw

RFC PATCH 13/43 ptrace, cris-v32: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Mikael Starvik <[email protected]>
Cc Jesper Nilsson <[email protected]>
---
 arch/cris/arch-v32/kernel/ptrace.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/cris/arch-v32/kernel/ptrace.c +4 -3
index f4ebd1e..b50da61 100644
@@ -126,7 +126,8 @@ ptrace_disable(struct task_struct *child)
 }
 
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 	unsigned long __user *datap = (unsigned long __user *)data;
@@ -163,7 +164,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			unsigned long tmp;
 
 			ret = -EIO;
-			if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
+			if ((addr & 3) || addr > PT_MAX << 2)
 				break;
 
 			tmp = get_reg(child, addr >> 2);
@@ -180,7 +181,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		/* Write the word at location address in the USER area. */
 		case PTRACE_POKEUSR:
 			ret = -EIO;
-			if ((addr & 3) || addr < 0 || addr > PT_MAX << 2)
+			if ((addr & 3) || addr > PT_MAX << 2)
 				break;
 
 			addr >>= 2;
Signature · 1 line
1.7.2.2
#23 lore raw

RFC PATCH 14/43 ptrace, frv: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/frv/kernel/ptrace.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/frv/kernel/ptrace.c +4 -3
index fac0289..3d87d1c 100644
@@ -254,7 +254,8 @@ void ptrace_disable(struct task_struct *child)
 	user_disable_single_step(child);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long tmp;
 	int ret;
@@ -264,7 +265,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	case PTRACE_PEEKUSR: {
 		tmp = 0;
 		ret = -EIO;
-		if ((addr & 3) || addr < 0)
+		if (addr & 3)
 			break;
 
 		ret = 0;
@@ -305,7 +306,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
 	case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
 		ret = -EIO;
-		if ((addr & 3) || addr < 0)
+		if (addr & 3)
 			break;
 
 		ret = 0;
Signature · 1 line
1.7.2.2
#24 lore raw

Re: [RFC PATCH 14/43] ptrace, frv: change signature of arch_ptrace()

Quoted 2 lines · Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

That description means nothing. Commit f76671df26ef06321480e702770f88f61272be29 is not upstream.

David

#25 lore raw

Re: [RFC PATCH 14/43] ptrace, frv: change signature of arch_ptrace()

Quoted 3 lines · David Howells

That description means nothing. Commit f76671df26ef06321480e702770f88f61272be29 is not upstream.

Hi,
Thank you for noticing. My bad.
I just wanted to let you know it depends on that.
What is the proper way to handle this?

Signature · 2 lines
Regards,
Namhyung Kim
#26 lore raw

Re: [RFC PATCH 14/43] ptrace, frv: change signature of arch_ptrace()

Quoted 5 lines · Namhyung Kim
Quoted 2 lines

That description means nothing. Commit f76671df26ef06321480e702770f88f61272be29 is not upstream.

Hi,
Thank you for noticing. My bad.

The problem with using a non-upstream commit ID like this is that it likely won't be the same once that commit is committed by Linus.

Quoted 1 line

I just wanted to let you know it depends on that.

The patch being part of the series is probably sufficient, though a note of the subject line of the previous patch would be useful.

Quoted 1 line

What is the proper way to handle this?

A summary of the changes being made is good:

ptrace: Fix up the arguments arch_ptrace() in arch FRV

Fix up the arguments to arch_ptrace() to take account of the fact that addr and data are now unsigned long rather than long as of a preceding patch in this series.

Signed-off-by ...

Note, however, that if the earlier patch breaks the compilation and then this patch fixes it up, you should roll this patch into the earlier patch, and the earlier patch is not complete without it.

Think what happens if patch 3/43 breaks an arch, and then patch 43/43, say, mends that arch, and then bisection lands on patch 3 during its progress. You may end up having to 'git bisect skip' all the patches between 3 and 43 one at a time.

David

#27 lore raw

Re: [RFC PATCH 14/43] ptrace, frv: change signature of arch_ptrace()

Quoted 6 lines · David Howells
Quoted 1 line · Namhyung Kim

I just wanted to let you know it depends on that.

The patch being part of the series is probably sufficient, though a note of the subject line of the previous patch would be useful.

I see. Will do that hereafter.

Quoted 4 lines
Quoted 1 line

What is the proper way to handle this?

A summary of the changes being made is good:

Quoted 8 lines

ptrace: Fix up the arguments arch_ptrace() in arch FRV

Fix up the arguments to arch_ptrace() to take account of the fact that addr and data are now unsigned long rather than long as of a preceding patch in this series.

Signed-off-by ...

Thanks. I will use this on the next round. :-)

Quoted 9 lines

Note, however, that if the earlier patch breaks the compilation and then this patch fixes it up, you should roll this patch into the earlier patch, and the earlier patch is not complete without it.

Think what happens if patch 3/43 breaks an arch, and then patch 43/43, say, mends that arch, and then bisection lands on patch 3 during its progress. You may end up having to 'git bisect skip' all the patches between 3 and 43 one at a time.

In this series, 3/43 changes the prototype of arch_ptrace() in include/linux/ptrace.h and the following patches change it for each arch in arch/xxx/kernel/ptrace.c. Do you mean all of arch change patches should be combinded into a patch?

Signature · 2 lines
Regards,
Namhyung Kim
#28 lore raw

Re: [RFC PATCH 14/43] ptrace, frv: change signature of arch_ptrace()

Quoted 4 lines · Namhyung Kim

In this series, 3/43 changes the prototype of arch_ptrace() in include/linux/ptrace.h and the following patches change it for each arch in arch/xxx/kernel/ptrace.c. Do you mean all of arch change patches should be combinded into a patch?

If patch 3 breaks all architectures, such that none of them then compile, this is bad. The fixes should be combined into that patch.

If it breaks them such that there are warnings, but they still compile, we can probably live with that, but it's still icky.

David

#29 lore raw

Re: [RFC PATCH 14/43] ptrace, frv: change signature of arch_ptrace()

Quoted 6 lines · David Howells

If patch 3 breaks all architectures, such that none of them then compile, this is bad. The fixes should be combined into that patch.

If it breaks them such that there are warnings, but they still compile, we can probably live with that, but it's still icky.

OK. I'll combine those patches into one on next round. Thanks.

Signature · 2 lines
Regards,
Namhyung Kim
#30 lore raw

RFC PATCH 15/43 ptrace, frv: cleanup arch_ptrace()

In reply to Namhyung Kim

use new regno, datap variables in order to remove duplicated expressions and unnecessary castings.

---
 arch/frv/kernel/ptrace.c |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)
arch/frv/kernel/ptrace.c +11 -14
index 3d87d1c..9d68f7f 100644
@@ -259,6 +259,8 @@ long arch_ptrace(struct task_struct *child, long request,
 {
 	unsigned long tmp;
 	int ret;
+	int regno = addr >> 2;
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 		/* read the word at location addr in the USER area. */
@@ -269,9 +271,9 @@ long arch_ptrace(struct task_struct *child, long request,
 			break;
 
 		ret = 0;
-		switch (addr >> 2) {
+		switch (regno) {
 		case 0 ... PT__END - 1:
-			tmp = get_reg(child, addr >> 2);
+			tmp = get_reg(child, regno);
 			break;
 
 		case PT__END + 0:
@@ -300,7 +302,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		}
 
 		if (ret == 0)
-			ret = put_user(tmp, (unsigned long *) data);
+			ret = put_user(tmp, datap);
 		break;
 	}
 
@@ -309,14 +311,9 @@ long arch_ptrace(struct task_struct *child, long request,
 		if (addr & 3)
 			break;
 
-		ret = 0;
-		switch (addr >> 2) {
+		switch (regno) {
 		case 0 ... PT__END - 1:
-			ret = put_reg(child, addr >> 2, data);
-			break;
-
-		default:
-			ret = -EIO;
+			ret = put_reg(child, regno, data);
 			break;
 		}
 		break;
@@ -325,25 +322,25 @@ long arch_ptrace(struct task_struct *child, long request,
 		return copy_regset_to_user(child, &user_frv_native_view,
 					   REGSET_GENERAL,
 					   0, sizeof(child->thread.user->i),
-					   (void __user *)data);
+					   datap);
 
 	case PTRACE_SETREGS:	/* Set all integer regs in the child. */
 		return copy_regset_from_user(child, &user_frv_native_view,
 					     REGSET_GENERAL,
 					     0, sizeof(child->thread.user->i),
-					     (const void __user *)data);
+					     datap);
 
 	case PTRACE_GETFPREGS:	/* Get the child FP/Media state. */
 		return copy_regset_to_user(child, &user_frv_native_view,
 					   REGSET_FPMEDIA,
 					   0, sizeof(child->thread.user->f),
-					   (void __user *)data);
+					   datap);
 
 	case PTRACE_SETFPREGS:	/* Set the child FP/Media state. */
 		return copy_regset_from_user(child, &user_frv_native_view,
 					     REGSET_FPMEDIA,
 					     0, sizeof(child->thread.user->f),
-					     (const void __user *)data);
+					     datap);
 
 	default:
 		ret = ptrace_request(child, request, addr, data);
Signature · 1 line
1.7.2.2
#31 lore raw

RFC PATCH 16/43 ptrace, h8300: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Yoshinori Sato <[email protected]>
---
 arch/h8300/kernel/ptrace.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
arch/h8300/kernel/ptrace.c +6 -5
index df11412..23a95f84 100644
@@ -50,7 +50,8 @@ void ptrace_disable(struct task_struct *child)
 	user_disable_single_step(child);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 
@@ -59,7 +60,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		case PTRACE_PEEKUSR: {
 			unsigned long tmp = 0;
 			
-			if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
+			if ((addr & 3) || addr >= sizeof(struct user)) {
 				ret = -EIO;
 				break ;
 			}
@@ -94,7 +95,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
       /* when I and D space are separate, this will have to be fixed. */
 		case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
-			if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
+			if ((addr & 3) || addr >= sizeof(struct user)) {
 				ret = -EIO;
 				break ;
 			}
@@ -120,7 +121,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				ret = -EFAULT;
 				break;
 			    }
-			    data += sizeof(long);
+			    data += sizeof(unsigned long);
 			}
 			ret = 0;
 			break;
@@ -135,7 +136,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				break;
 			    }
 			    h8300_put_reg(child, i, tmp);
-			    data += sizeof(long);
+			    data += sizeof(unsigned long);
 			}
 			ret = 0;
 			break;
Signature · 1 line
1.7.2.2
#32 lore raw

RFC PATCH 17/43 ptrace, h8300: cleanup arch_ptrace()

In reply to Namhyung Kim

use new regno, datap variables in order to remove duplicated expressions and unnecessary castings.

Cc Yoshinori Sato <[email protected]>
---
 arch/h8300/kernel/ptrace.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)
arch/h8300/kernel/ptrace.c +13 -13
index 23a95f84..00ddc9c 100644
@@ -54,6 +54,8 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
+	int regno = addr >> 2; /* temporary hack. */
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 	/* read the word at location addr in the USER area. */
@@ -66,12 +68,11 @@ long arch_ptrace(struct task_struct *child, long request,
 			}
 			
 		        ret = 0;  /* Default return condition */
-			addr = addr >> 2; /* temporary hack. */
 
-			if (addr < H8300_REGS_NO)
-				tmp = h8300_get_reg(child, addr);
+			if (regno < H8300_REGS_NO)
+				tmp = h8300_get_reg(child, regno);
 			else {
-				switch(addr) {
+				switch(regno) {
 				case 49:
 					tmp = child->mm->start_code;
 					break ;
@@ -89,7 +90,7 @@ long arch_ptrace(struct task_struct *child, long request,
 				}
 			}
 			if (!ret)
-				ret = put_user(tmp,(unsigned long *) data);
+				ret = put_user(tmp, datap);
 			break ;
 		}
 
@@ -99,14 +100,13 @@ long arch_ptrace(struct task_struct *child, long request,
 				ret = -EIO;
 				break ;
 			}
-			addr = addr >> 2; /* temporary hack. */
 			    
-			if (addr == PT_ORIG_ER0) {
+			if (regno == PT_ORIG_ER0) {
 				ret = -EIO;
 				break ;
 			}
-			if (addr < H8300_REGS_NO) {
-				ret = h8300_put_reg(child, addr, data);
+			if (regno < H8300_REGS_NO) {
+				ret = h8300_put_reg(child, regno, data);
 				break ;
 			}
 			ret = -EIO;
@@ -117,11 +117,11 @@ long arch_ptrace(struct task_struct *child, long request,
 			unsigned long tmp;
 			for (i = 0; i < H8300_REGS_NO; i++) {
 			    tmp = h8300_get_reg(child, i);
-			    if (put_user(tmp, (unsigned long *) data)) {
+			    if (put_user(tmp, datap)) {
 				ret = -EFAULT;
 				break;
 			    }
-			    data += sizeof(unsigned long);
+			    datap++;
 			}
 			ret = 0;
 			break;
@@ -131,12 +131,12 @@ long arch_ptrace(struct task_struct *child, long request,
 			int i;
 			unsigned long tmp;
 			for (i = 0; i < H8300_REGS_NO; i++) {
-			    if (get_user(tmp, (unsigned long *) data)) {
+			    if (get_user(tmp, datap)) {
 				ret = -EFAULT;
 				break;
 			    }
 			    h8300_put_reg(child, i, tmp);
-			    data += sizeof(unsigned long);
+			    datap++;
 			}
 			ret = 0;
 			break;
Signature · 1 line
1.7.2.2
#33 lore raw

RFC PATCH 18/43 ptrace, ia64: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/ia64/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/ia64/kernel/ptrace.c +2 -1
index 7c7909f..8848f43 100644
@@ -1177,7 +1177,8 @@ ptrace_disable (struct task_struct *child)
 }
 
 long
-arch_ptrace (struct task_struct *child, long request, long addr, long data)
+arch_ptrace (struct task_struct *child, long request,
+	     unsigned long addr, unsigned long data)
 {
 	switch (request) {
 	case PTRACE_PEEKTEXT:
Signature · 1 line
1.7.2.2
#34 lore raw

RFC PATCH 19/43 ptrace, m32r: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/m32r/kernel/ptrace.c +2 -1
index e555091..69bbf7a 100644
@@ -621,7 +621,8 @@ void ptrace_disable(struct task_struct *child)
 }
 
 long
-arch_ptrace(struct task_struct *child, long request, long addr, long data)
+arch_ptrace(struct task_struct *child, long request,
+	    unsigned long addr, unsigned long data)
 {
 	int ret;
 
Signature · 1 line
1.7.2.2
#35 lore raw

RFC PATCH 20/43 ptrace, m32r: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'datap' variable in order to remove duplicated castings.

Cc Hirokazu Takata <[email protected]>
---
 arch/m32r/kernel/ptrace.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
arch/m32r/kernel/ptrace.c +4 -4
index 69bbf7a..fc93e8d 100644
@@ -625,6 +625,7 @@ arch_ptrace(struct task_struct *child, long request,
 	    unsigned long addr, unsigned long data)
 {
 	int ret;
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 	/*
@@ -639,8 +640,7 @@ arch_ptrace(struct task_struct *child, long request,
 	 * read the word at location addr in the USER area.
 	 */
 	case PTRACE_PEEKUSR:
-		ret = ptrace_read_user(child, addr,
-				       (unsigned long __user *)data);
+		ret = ptrace_read_user(child, addr, datap);
 		break;
 
 	/*
@@ -661,11 +661,11 @@ arch_ptrace(struct task_struct *child, long request,
 		break;
 
 	case PTRACE_GETREGS:
-		ret = ptrace_getregs(child, (void __user *)data);
+		ret = ptrace_getregs(child, datap);
 		break;
 
 	case PTRACE_SETREGS:
-		ret = ptrace_setregs(child, (void __user *)data);
+		ret = ptrace_setregs(child, datap);
 		break;
 
 	default:
Signature · 1 line
1.7.2.2
#36 lore raw

RFC PATCH 21/43 ptrace, m68k: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Geert Uytterhoeven <[email protected]>
Cc Roman Zippel <[email protected]>
---
 arch/m68k/kernel/ptrace.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
arch/m68k/kernel/ptrace.c +5 -4
index 616e597..583f59f 100644
@@ -156,7 +156,8 @@ void user_disable_single_step(struct task_struct *child)
 	singlestep_disable(child);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long tmp;
 	int i, ret = 0;
@@ -200,7 +201,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			 * into internal fpu reg representation
 			 */
 			if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
-				data = (unsigned long)data << 15;
+				data <<= 15;
 				data = (data & 0xffff0000) |
 				       ((data & 0x0000ffff) >> 1);
 			}
@@ -215,7 +216,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			ret = put_user(tmp, (unsigned long *)data);
 			if (ret)
 				break;
-			data += sizeof(long);
+			data += sizeof(unsigned long);
 		}
 		break;
 
@@ -229,7 +230,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				tmp |= get_reg(child, PT_SR) & ~SR_MASK;
 			}
 			put_reg(child, i, tmp);
-			data += sizeof(long);
+			data += sizeof(unsigned long);
 		}
 		break;
 
Signature · 1 line
1.7.2.2
#37 lore raw

RFC PATCH 22/43 ptrace, m68k: cleanup arch_ptrace()

In reply to Namhyung Kim

use new regno, datap variables in order to remove duplicated expressions and unnecessary castings.

Cc Geert Uytterhoeven <[email protected]>
Cc Roman Zippel <[email protected]>
---
 arch/m68k/kernel/ptrace.c |   46 ++++++++++++++++++++++----------------------
 1 files changed, 23 insertions(+), 23 deletions(-)
arch/m68k/kernel/ptrace.c +23 -23
index 583f59f..0b25268 100644
@@ -161,51 +161,52 @@ long arch_ptrace(struct task_struct *child, long request,
 {
 	unsigned long tmp;
 	int i, ret = 0;
+	int regno = addr >> 2; /* temporary hack. */
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 	/* read the word at location addr in the USER area. */
 	case PTRACE_PEEKUSR:
 		if (addr & 3)
 			goto out_eio;
-		addr >>= 2;	/* temporary hack. */
 
-		if (addr >= 0 && addr < 19) {
-			tmp = get_reg(child, addr);
-		} else if (addr >= 21 && addr < 49) {
-			tmp = child->thread.fp[addr - 21];
+		if (regno >= 0 && regno < 19) {
+			tmp = get_reg(child, regno);
+		} else if (regno >= 21 && regno < 49) {
+			tmp = child->thread.fp[regno - 21];
 			/* Convert internal fpu reg representation
 			 * into long double format
 			 */
-			if (FPU_IS_EMU && (addr < 45) && !(addr % 3))
+			if (FPU_IS_EMU && (regno < 45) && !(regno % 3))
 				tmp = ((tmp & 0xffff0000) << 15) |
 				      ((tmp & 0x0000ffff) << 16);
 		} else
 			goto out_eio;
-		ret = put_user(tmp, (unsigned long *)data);
+		ret = put_user(tmp, datap);
 		break;
 
-	case PTRACE_POKEUSR:	/* write the word at location addr in the USER area */
+	case PTRACE_POKEUSR:
+	/* write the word at location addr in the USER area */
 		if (addr & 3)
 			goto out_eio;
-		addr >>= 2;	/* temporary hack. */
 
-		if (addr == PT_SR) {
+		if (regno == PT_SR) {
 			data &= SR_MASK;
 			data |= get_reg(child, PT_SR) & ~SR_MASK;
 		}
-		if (addr >= 0 && addr < 19) {
-			if (put_reg(child, addr, data))
+		if (regno >= 0 && regno < 19) {
+			if (put_reg(child, regno, data))
 				goto out_eio;
-		} else if (addr >= 21 && addr < 48) {
+		} else if (regno >= 21 && regno < 48) {
 			/* Convert long double format
 			 * into internal fpu reg representation
 			 */
-			if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
+			if (FPU_IS_EMU && (regno < 45) && !(regno % 3)) {
 				data <<= 15;
 				data = (data & 0xffff0000) |
 				       ((data & 0x0000ffff) >> 1);
 			}
-			child->thread.fp[addr - 21] = data;
+			child->thread.fp[regno - 21] = data;
 		} else
 			goto out_eio;
 		break;
@@ -213,16 +214,16 @@ long arch_ptrace(struct task_struct *child, long request,
 	case PTRACE_GETREGS:	/* Get all gp regs from the child. */
 		for (i = 0; i < 19; i++) {
 			tmp = get_reg(child, i);
-			ret = put_user(tmp, (unsigned long *)data);
+			ret = put_user(tmp, datap);
 			if (ret)
 				break;
-			data += sizeof(unsigned long);
+			datap++;
 		}
 		break;
 
 	case PTRACE_SETREGS:	/* Set all gp regs in the child. */
 		for (i = 0; i < 19; i++) {
-			ret = get_user(tmp, (unsigned long *)data);
+			ret = get_user(tmp, datap);
 			if (ret)
 				break;
 			if (i == PT_SR) {
@@ -230,25 +231,24 @@ long arch_ptrace(struct task_struct *child, long request,
 				tmp |= get_reg(child, PT_SR) & ~SR_MASK;
 			}
 			put_reg(child, i, tmp);
-			data += sizeof(unsigned long);
+			datap++;
 		}
 		break;
 
 	case PTRACE_GETFPREGS:	/* Get the child FPU state. */
-		if (copy_to_user((void *)data, &child->thread.fp,
+		if (copy_to_user(datap, &child->thread.fp,
 				 sizeof(struct user_m68kfp_struct)))
 			ret = -EFAULT;
 		break;
 
 	case PTRACE_SETFPREGS:	/* Set the child FPU state. */
-		if (copy_from_user(&child->thread.fp, (void *)data,
+		if (copy_from_user(&child->thread.fp, datap,
 				   sizeof(struct user_m68kfp_struct)))
 			ret = -EFAULT;
 		break;
 
 	case PTRACE_GET_THREAD_AREA:
-		ret = put_user(task_thread_info(child)->tp_value,
-			       (unsigned long __user *)data);
+		ret = put_user(task_thread_info(child)->tp_value, datap);
 		break;
 
 	default:
Signature · 1 line
1.7.2.2
#38 lore raw

RFC PATCH 23/43 ptrace, m68knommu: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/m68knommu/kernel/ptrace.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)
arch/m68knommu/kernel/ptrace.c +7 -8
index f6be124..835a3ed 100644
@@ -111,7 +111,8 @@ void ptrace_disable(struct task_struct *child)
 	user_disable_single_step(child);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 
@@ -121,8 +122,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			unsigned long tmp;
 			
 			ret = -EIO;
-			if ((addr & 3) || addr < 0 ||
-			    addr > sizeof(struct user) - 3)
+			if ((addr & 3) || addr > sizeof(struct user) - 3)
 				break;
 			
 			tmp = 0;  /* Default return condition */
@@ -156,8 +156,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
 		case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
 			ret = -EIO;
-			if ((addr & 3) || addr < 0 ||
-			    addr > sizeof(struct user) - 3)
+			if ((addr & 3) || addr > sizeof(struct user) - 3)
 				break;
 
 			addr = addr >> 2; /* temporary hack. */
@@ -180,7 +179,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				 * into internal fpu reg representation
 				 */
 				if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
-					data = (unsigned long)data << 15;
+					data <<= 15;
 					data = (data & 0xffff0000) |
 					       ((data & 0x0000ffff) >> 1);
 				}
@@ -201,7 +200,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				ret = -EFAULT;
 				break;
 			    }
-			    data += sizeof(long);
+			    data += sizeof(unsigned long);
 			}
 			ret = 0;
 			break;
@@ -221,7 +220,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 				tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
 			    }
 			    put_reg(child, i, tmp);
-			    data += sizeof(long);
+			    data += sizeof(unsigned long);
 			}
 			ret = 0;
 			break;
Signature · 1 line
1.7.2.2
#39 lore raw

RFC PATCH 24/43 ptrace, m68knommu: cleanup arch_ptrace()

In reply to Namhyung Kim

use new regno, datap variables in order to remove duplicated expressions and unnecessary castings. Also some coding style fixes are included.

---
 arch/m68knommu/kernel/ptrace.c |   59 +++++++++++++++++++++-------------------
 1 files changed, 31 insertions(+), 28 deletions(-)
arch/m68knommu/kernel/ptrace.c +31 -28
index 835a3ed..7f23775 100644
@@ -115,6 +115,8 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
+	int regno = addr >> 2; /* temporary hack. */
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 		/* read the word at location addr in the USER area. */
@@ -126,59 +128,60 @@ long arch_ptrace(struct task_struct *child, long request,
 				break;
 			
 			tmp = 0;  /* Default return condition */
-			addr = addr >> 2; /* temporary hack. */
 			ret = -EIO;
-			if (addr < 19) {
-				tmp = get_reg(child, addr);
+			if (regno < 19) {
+				tmp = get_reg(child, regno);
 				if (addr == PT_SR)
 					tmp >>= 16;
-			} else if (addr >= 21 && addr < 49) {
-				tmp = child->thread.fp[addr - 21];
+			} else if (regno >= 21 && regno < 49) {
+				tmp = child->thread.fp[regno - 21];
 #ifdef CONFIG_M68KFPU_EMU
 				/* Convert internal fpu reg representation
 				 * into long double format
 				 */
-				if (FPU_IS_EMU && (addr < 45) && !(addr % 3))
+				if (FPU_IS_EMU && (regno < 45) &&
+				    !(regno % 3))
 					tmp = ((tmp & 0xffff0000) << 15) |
 					      ((tmp & 0x0000ffff) << 16);
 #endif
-			} else if (addr == 49) {
+			} else if (regno == 49) {
 				tmp = child->mm->start_code;
-			} else if (addr == 50) {
+			} else if (regno == 50) {
 				tmp = child->mm->start_data;
-			} else if (addr == 51) {
+			} else if (regno == 51) {
 				tmp = child->mm->end_code;
 			} else
 				break;
-			ret = put_user(tmp,(unsigned long *) data);
+			ret = put_user(tmp, datap);
 			break;
 		}
 
-		case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
+		case PTRACE_POKEUSR:
+		/* write the word at location addr in the USER area */
 			ret = -EIO;
 			if ((addr & 3) || addr > sizeof(struct user) - 3)
 				break;
 
-			addr = addr >> 2; /* temporary hack. */
-			    
-			if (addr == PT_SR) {
+			if (regno == PT_SR) {
 				data &= SR_MASK;
 				data <<= 16;
-				data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
+				data |= get_reg(child, PT_SR) &
+					~(SR_MASK << 16);
 			}
-			if (addr < 19) {
-				if (put_reg(child, addr, data))
+			if (regno < 19) {
+				if (put_reg(child, regno, data))
 					break;
 				ret = 0;
 				break;
 			}
-			if (addr >= 21 && addr < 48)
+			if (regno >= 21 && regno < 48)
 			{
 #ifdef CONFIG_M68KFPU_EMU
 				/* Convert long double format
 				 * into internal fpu reg representation
 				 */
-				if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) {
+				if (FPU_IS_EMU && (regno < 45) &&
+				    !(regno % 3)) {
 					data <<= 15;
 					data = (data & 0xffff0000) |
 					       ((data & 0x0000ffff) >> 1);
@@ -196,11 +199,11 @@ long arch_ptrace(struct task_struct *child, long request,
 			    tmp = get_reg(child, i);
 			    if (i == PT_SR)
 				tmp >>= 16;
-			    if (put_user(tmp, (unsigned long *) data)) {
+			    if (put_user(tmp, datap)) {
 				ret = -EFAULT;
 				break;
 			    }
-			    data += sizeof(unsigned long);
+			    datap++;
 			}
 			ret = 0;
 			break;
@@ -210,17 +213,18 @@ long arch_ptrace(struct task_struct *child, long request,
 			int i;
 			unsigned long tmp;
 			for (i = 0; i < 19; i++) {
-			    if (get_user(tmp, (unsigned long *) data)) {
+			    if (get_user(tmp, datap)) {
 				ret = -EFAULT;
 				break;
 			    }
 			    if (i == PT_SR) {
 				tmp &= SR_MASK;
 				tmp <<= 16;
-				tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
+				tmp |= get_reg(child, PT_SR) &
+					~(SR_MASK << 16);
 			    }
 			    put_reg(child, i, tmp);
-			    data += sizeof(unsigned long);
+			    datap++;
 			}
 			ret = 0;
 			break;
@@ -229,7 +233,7 @@ long arch_ptrace(struct task_struct *child, long request,
 #ifdef PTRACE_GETFPREGS
 		case PTRACE_GETFPREGS: { /* Get the child FPU state. */
 			ret = 0;
-			if (copy_to_user((void *)data, &child->thread.fp,
+			if (copy_to_user(datap, &child->thread.fp,
 					 sizeof(struct user_m68kfp_struct)))
 				ret = -EFAULT;
 			break;
@@ -239,7 +243,7 @@ long arch_ptrace(struct task_struct *child, long request,
 #ifdef PTRACE_SETFPREGS
 		case PTRACE_SETFPREGS: { /* Set the child FPU state. */
 			ret = 0;
-			if (copy_from_user(&child->thread.fp, (void *)data,
+			if (copy_from_user(&child->thread.fp, datap,
 					   sizeof(struct user_m68kfp_struct)))
 				ret = -EFAULT;
 			break;
@@ -247,8 +251,7 @@ long arch_ptrace(struct task_struct *child, long request,
 #endif
 
 	case PTRACE_GET_THREAD_AREA:
-		ret = put_user(task_thread_info(child)->tp_value,
-			       (unsigned long __user *)data);
+		ret = put_user(task_thread_info(child)->tp_value, datap);
 		break;
 
 		default:
Signature · 1 line
1.7.2.2
#40 lore raw

RFC PATCH 25/43 ptrace, microblaze: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/microblaze/kernel/ptrace.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/microblaze/kernel/ptrace.c +4 -3
index dc03ffc..2d6b4cf 100644
@@ -73,7 +73,8 @@ static microblaze_reg_t *reg_save_addr(unsigned reg_offs,
 	return (microblaze_reg_t *)((char *)regs + reg_offs);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int rval;
 	unsigned long val = 0;
@@ -99,7 +100,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			} else {
 				rval = -EIO;
 			}
-		} else if (addr >= 0 && addr < PT_SIZE && (addr & 0x3) == 0) {
+		} else if (addr < PT_SIZE && (addr & 0x3) == 0) {
 			microblaze_reg_t *reg_addr = reg_save_addr(addr, child);
 			if (request == PTRACE_PEEKUSR)
 				val = *reg_addr;
@@ -122,7 +123,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			rval = -EIO;
 
 		if (rval == 0 && request == PTRACE_PEEKUSR)
-			rval = put_user(val, (unsigned long *)data);
+			rval = put_user(val, (unsigned long __user *)data);
 		break;
 	default:
 		rval = ptrace_request(child, request, addr, data);
Signature · 1 line
1.7.2.2
#41 lore raw

RFC PATCH 26/43 ptrace, mips: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/mips/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/mips/kernel/ptrace.c +2 -1
index c51b95f..26c29dd 100644
@@ -255,7 +255,8 @@ int ptrace_set_watch_regs(struct task_struct *child,
 	return 0;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 
Signature · 1 line
1.7.2.2
#42 lore raw

RFC PATCH 27/43 ptrace, mips: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'addrp' and 'datap' variables type of void pointer in order to remove unnecessary castings.

---
 arch/mips/kernel/ptrace.c |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)
arch/mips/kernel/ptrace.c +12 -11
index 26c29dd..c0ab9d2 100644
@@ -259,6 +259,8 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
+	void __user *addrp = (void __user *) addr;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 	/* when I and D space are separate, these will need to be fixed. */
@@ -387,7 +389,9 @@ long arch_ptrace(struct task_struct *child, long request,
 			ret = -EIO;
 			goto out;
 		}
-		ret = put_user(tmp, (unsigned long __user *) data);
+		ret = copy_to_user(datap, &tmp, sizeof(tmp));
+		if (ret)
+			ret = -EFAULT;
 		break;
 	}
 
@@ -479,34 +483,31 @@ long arch_ptrace(struct task_struct *child, long request,
 		}
 
 	case PTRACE_GETREGS:
-		ret = ptrace_getregs(child, (__s64 __user *) data);
+		ret = ptrace_getregs(child, datap);
 		break;
 
 	case PTRACE_SETREGS:
-		ret = ptrace_setregs(child, (__s64 __user *) data);
+		ret = ptrace_setregs(child, datap);
 		break;
 
 	case PTRACE_GETFPREGS:
-		ret = ptrace_getfpregs(child, (__u32 __user *) data);
+		ret = ptrace_getfpregs(child, datap);
 		break;
 
 	case PTRACE_SETFPREGS:
-		ret = ptrace_setfpregs(child, (__u32 __user *) data);
+		ret = ptrace_setfpregs(child, datap);
 		break;
 
 	case PTRACE_GET_THREAD_AREA:
-		ret = put_user(task_thread_info(child)->tp_value,
-				(unsigned long __user *) data);
+		ret = put_user(task_thread_info(child)->tp_value, datap);
 		break;
 
 	case PTRACE_GET_WATCH_REGS:
-		ret = ptrace_get_watch_regs(child,
-					(struct pt_watch_regs __user *) addr);
+		ret = ptrace_get_watch_regs(child, addrp);
 		break;
 
 	case PTRACE_SET_WATCH_REGS:
-		ret = ptrace_set_watch_regs(child,
-					(struct pt_watch_regs __user *) addr);
+		ret = ptrace_set_watch_regs(child, addrp);
 		break;
 
 	default:
Signature · 1 line
1.7.2.2
#43 lore raw

RFC PATCH 28/43 ptrace, mn10300: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc David Howells <[email protected]>
Cc Koichi Yasutake <[email protected]>
---
 arch/mn10300/kernel/ptrace.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
arch/mn10300/kernel/ptrace.c +4 -5
index cf847da..4261810 100644
@@ -295,7 +295,8 @@ void ptrace_disable(struct task_struct *child)
 /*
  * handle the arch-specific side of process tracing
  */
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long tmp;
 	int ret;
@@ -304,8 +305,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	/* read the word at location addr in the USER area. */
 	case PTRACE_PEEKUSR:
 		ret = -EIO;
-		if ((addr & 3) || addr < 0 ||
-		    addr > sizeof(struct user) - 3)
+		if ((addr & 3) || addr > sizeof(struct user) - 3)
 			break;
 
 		tmp = 0;  /* Default return condition */
@@ -318,8 +318,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		/* write the word at location addr in the USER area */
 	case PTRACE_POKEUSR:
 		ret = -EIO;
-		if ((addr & 3) || addr < 0 ||
-		    addr > sizeof(struct user) - 3)
+		if ((addr & 3) || addr > sizeof(struct user) - 3)
 			break;
 
 		ret = 0;
Signature · 1 line
1.7.2.2
#44 lore raw

RFC PATCH 29/43 ptrace, mn10300: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'datap' variable in order to remove unnecessary castings.

Cc David Howells <[email protected]>
Cc Koichi Yasutake <[email protected]>
---
 arch/mn10300/kernel/ptrace.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
arch/mn10300/kernel/ptrace.c +6 -5
index 4261810..5c0b07e 100644
@@ -300,6 +300,7 @@ long arch_ptrace(struct task_struct *child, long request,
 {
 	unsigned long tmp;
 	int ret;
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 	/* read the word at location addr in the USER area. */
@@ -312,7 +313,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		if (addr < NR_PTREGS << 2)
 			tmp = get_stack_long(child,
 					     ptrace_regid_to_frame[addr]);
-		ret = put_user(tmp, (unsigned long *) data);
+		ret = put_user(tmp, datap);
 		break;
 
 		/* write the word at location addr in the USER area */
@@ -331,25 +332,25 @@ long arch_ptrace(struct task_struct *child, long request,
 		return copy_regset_to_user(child, &user_mn10300_native_view,
 					   REGSET_GENERAL,
 					   0, NR_PTREGS * sizeof(long),
-					   (void __user *)data);
+					   datap);
 
 	case PTRACE_SETREGS:	/* Set all integer regs in the child. */
 		return copy_regset_from_user(child, &user_mn10300_native_view,
 					     REGSET_GENERAL,
 					     0, NR_PTREGS * sizeof(long),
-					     (const void __user *)data);
+					     datap);
 
 	case PTRACE_GETFPREGS:	/* Get the child FPU state. */
 		return copy_regset_to_user(child, &user_mn10300_native_view,
 					   REGSET_FPU,
 					   0, sizeof(struct fpu_state_struct),
-					   (void __user *)data);
+					   datap);
 
 	case PTRACE_SETFPREGS:	/* Set the child FPU state. */
 		return copy_regset_from_user(child, &user_mn10300_native_view,
 					     REGSET_FPU,
 					     0, sizeof(struct fpu_state_struct),
-					     (const void __user *)data);
+					     datap);
 
 	default:
 		ret = ptrace_request(child, request, addr, data);
Signature · 1 line
1.7.2.2
#45 lore raw

RFC PATCH 30/43 ptrace, parisc: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Kyle McMartin <[email protected]>
Cc Helge Deller <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 arch/parisc/kernel/ptrace.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
arch/parisc/kernel/ptrace.c +7 -6
index c4f49e4..2905b1f 100644
@@ -110,7 +110,8 @@ void user_enable_block_step(struct task_struct *task)
 	pa_psw(task)->l = 0;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long tmp;
 	long ret = -EIO;
@@ -120,11 +121,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	/* Read the word at location addr in the USER area.  For ptraced
 	   processes, the kernel saves all regs on a syscall. */
 	case PTRACE_PEEKUSR:
-		if ((addr & (sizeof(long)-1)) ||
-		    (unsigned long) addr >= sizeof(struct pt_regs))
+		if ((addr & (sizeof(unsigned long)-1)) ||
+		     addr >= sizeof(struct pt_regs))
 			break;
 		tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
-		ret = put_user(tmp, (unsigned long *) data);
+		ret = put_user(tmp, (unsigned long __user *) data);
 		break;
 
 	/* Write the word at location addr in the USER area.  This will need
@@ -151,8 +152,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 			break;
 		}
 
-		if ((addr & (sizeof(long)-1)) ||
-		    (unsigned long) addr >= sizeof(struct pt_regs))
+		if ((addr & (sizeof(unsigned long)-1)) ||
+		     addr >= sizeof(struct pt_regs))
 			break;
 		if ((addr >= PT_GR1 && addr <= PT_GR31) ||
 				addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
Signature · 1 line
1.7.2.2
#46 lore raw

RFC PATCH 31/43 ptrace, powerpc: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/ptrace.c |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
arch/powerpc/kernel/ptrace.c +8 -7
index 11f3cd9..e4b6d75 100644
@@ -1406,8 +1406,8 @@ static long ppc_del_hwdebug(struct task_struct *child, long addr, long data)
  * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
  * we mark them as obsolete now, they will be removed in a future version
  */
-static long arch_ptrace_old(struct task_struct *child, long request, long addr,
-			    long data)
+static long arch_ptrace_old(struct task_struct *child, long request,
+			    unsigned long addr, unsigned long data)
 {
 	switch (request) {
 	case PPC_PTRACE_GETREGS:	/* Get GPRs 0 - 31. */
@@ -1434,7 +1434,8 @@ static long arch_ptrace_old(struct task_struct *child, long request, long addr,
 	return -EPERM;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret = -EPERM;
 
@@ -1446,11 +1447,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		ret = -EIO;
 		/* convert to index and check */
 #ifdef CONFIG_PPC32
-		index = (unsigned long) addr >> 2;
+		index = addr >> 2;
 		if ((addr & 3) || (index > PT_FPSCR)
 		    || (child->thread.regs == NULL))
 #else
-		index = (unsigned long) addr >> 3;
+		index = addr >> 3;
 		if ((addr & 7) || (index > PT_FPSCR))
 #endif
 			break;
@@ -1474,11 +1475,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		ret = -EIO;
 		/* convert to index and check */
 #ifdef CONFIG_PPC32
-		index = (unsigned long) addr >> 2;
+		index = addr >> 2;
 		if ((addr & 3) || (index > PT_FPSCR)
 		    || (child->thread.regs == NULL))
 #else
-		index = (unsigned long) addr >> 3;
+		index = addr >> 3;
 		if ((addr & 7) || (index > PT_FPSCR))
 #endif
 			break;
Signature · 1 line
1.7.2.2
#47 lore raw

RFC PATCH 32/43 ptrace, powerpc: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'datap' variable in order to remove unnecessary castings.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
---
 arch/powerpc/kernel/ptrace.c |   55 +++++++++++++++++++++++-------------------
 1 files changed, 30 insertions(+), 25 deletions(-)
arch/powerpc/kernel/ptrace.c +30 -25
index e4b6d75..0047bf9 100644
@@ -1409,26 +1409,28 @@ static long ppc_del_hwdebug(struct task_struct *child, long addr, long data)
 static long arch_ptrace_old(struct task_struct *child, long request,
 			    unsigned long addr, unsigned long data)
 {
+	void __user *datap = (void __user *) data;
+
 	switch (request) {
 	case PPC_PTRACE_GETREGS:	/* Get GPRs 0 - 31. */
 		return copy_regset_to_user(child, &user_ppc_native_view,
 					   REGSET_GPR, 0, 32 * sizeof(long),
-					   (void __user *) data);
+					   datap);
 
 	case PPC_PTRACE_SETREGS:	/* Set GPRs 0 - 31. */
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_GPR, 0, 32 * sizeof(long),
-					     (const void __user *) data);
+					     datap);
 
 	case PPC_PTRACE_GETFPREGS:	/* Get FPRs 0 - 31. */
 		return copy_regset_to_user(child, &user_ppc_native_view,
 					   REGSET_FPR, 0, 32 * sizeof(double),
-					   (void __user *) data);
+					   datap);
 
 	case PPC_PTRACE_SETFPREGS:	/* Set FPRs 0 - 31. */
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_FPR, 0, 32 * sizeof(double),
-					     (const void __user *) data);
+					     datap);
 	}
 
 	return -EPERM;
@@ -1438,6 +1440,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret = -EPERM;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 	/* read the word at location addr in the USER area. */
@@ -1464,7 +1467,8 @@ long arch_ptrace(struct task_struct *child, long request,
 			tmp = ((unsigned long *)child->thread.fpr)
 				[TS_FPRWIDTH * (index - PT_FPR0)];
 		}
-		ret = put_user(tmp,(unsigned long __user *) data);
+		ret = copy_to_user(datap, &tmp, sizeof(tmp)) ?
+		      -EFAULT : 0;
 		break;
 	}
 
@@ -1526,11 +1530,11 @@ long arch_ptrace(struct task_struct *child, long request,
 		dbginfo.features = 0;
 #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
 
-		if (!access_ok(VERIFY_WRITE, data,
+		if (!access_ok(VERIFY_WRITE, datap,
 			       sizeof(struct ppc_debug_info)))
 			return -EFAULT;
-		ret = __copy_to_user((struct ppc_debug_info __user *)data,
-				     &dbginfo, sizeof(struct ppc_debug_info)) ?
+		ret = __copy_to_user(datap, &dbginfo,
+				     sizeof(struct ppc_debug_info)) ?
 		      -EFAULT : 0;
 		break;
 	}
@@ -1538,11 +1542,10 @@ long arch_ptrace(struct task_struct *child, long request,
 	case PPC_PTRACE_SETHWDEBUG: {
 		struct ppc_hw_breakpoint bp_info;
 
-		if (!access_ok(VERIFY_READ, data,
+		if (!access_ok(VERIFY_READ, datap,
 			       sizeof(struct ppc_hw_breakpoint)))
 			return -EFAULT;
-		ret = __copy_from_user(&bp_info,
-				       (struct ppc_hw_breakpoint __user *)data,
+		ret = __copy_from_user(&bp_info, datap,
 				       sizeof(struct ppc_hw_breakpoint)) ?
 		      -EFAULT : 0;
 		if (!ret)
@@ -1561,11 +1564,13 @@ long arch_ptrace(struct task_struct *child, long request,
 		if (addr > 0)
 			break;
 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
-		ret = put_user(child->thread.dac1,
-			       (unsigned long __user *)data);
+		ret = copy_to_user(datap, child->thread.dac1,
+				   sizeof(child->thread.dac1)) ?
+		      -EFAULT : 0;
 #else
-		ret = put_user(child->thread.dabr,
-			       (unsigned long __user *)data);
+		ret = copy_to_user(datap, child->thread.dabr,
+				   sizeof(child->thread.dabr)) ?
+		      -EFAULT : 0;
 #endif
 		break;
 	}
@@ -1581,7 +1586,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		return copy_regset_to_user(child, &user_ppc_native_view,
 					   REGSET_GPR,
 					   0, sizeof(struct pt_regs),
-					   (void __user *) data);
+					   datap);
 
 #ifdef CONFIG_PPC64
 	case PTRACE_SETREGS64:
@@ -1590,19 +1595,19 @@ long arch_ptrace(struct task_struct *child, long request,
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_GPR,
 					     0, sizeof(struct pt_regs),
-					     (const void __user *) data);
+					     datap);
 
 	case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
 		return copy_regset_to_user(child, &user_ppc_native_view,
 					   REGSET_FPR,
 					   0, sizeof(elf_fpregset_t),
-					   (void __user *) data);
+					   datap);
 
 	case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_FPR,
 					     0, sizeof(elf_fpregset_t),
-					     (const void __user *) data);
+					     datap);
 
 #ifdef CONFIG_ALTIVEC
 	case PTRACE_GETVRREGS:
@@ -1610,40 +1615,40 @@ long arch_ptrace(struct task_struct *child, long request,
 					   REGSET_VMX,
 					   0, (33 * sizeof(vector128) +
 					       sizeof(u32)),
-					   (void __user *) data);
+					   datap);
 
 	case PTRACE_SETVRREGS:
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_VMX,
 					     0, (33 * sizeof(vector128) +
 						 sizeof(u32)),
-					     (const void __user *) data);
+					     datap);
 #endif
 #ifdef CONFIG_VSX
 	case PTRACE_GETVSRREGS:
 		return copy_regset_to_user(child, &user_ppc_native_view,
 					   REGSET_VSX,
 					   0, 32 * sizeof(double),
-					   (void __user *) data);
+					   datap);
 
 	case PTRACE_SETVSRREGS:
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_VSX,
 					     0, 32 * sizeof(double),
-					     (const void __user *) data);
+					     datap);
 #endif
 #ifdef CONFIG_SPE
 	case PTRACE_GETEVRREGS:
 		/* Get the child spe register state. */
 		return copy_regset_to_user(child, &user_ppc_native_view,
 					   REGSET_SPE, 0, 35 * sizeof(u32),
-					   (void __user *) data);
+					   datap);
 
 	case PTRACE_SETEVRREGS:
 		/* Set the child spe register state. */
 		return copy_regset_from_user(child, &user_ppc_native_view,
 					     REGSET_SPE, 0, 35 * sizeof(u32),
-					     (const void __user *) data);
+					     datap);
 #endif
 
 	/* Old reverse args ptrace callss */
Signature · 1 line
1.7.2.2
#48 lore raw

RFC PATCH 33/43 ptrace, s390: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>
---
 arch/s390/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/s390/kernel/ptrace.c +2 -1
index 83339d3..019bb71 100644
@@ -343,7 +343,8 @@ poke_user(struct task_struct *child, addr_t addr, addr_t data)
 	return __poke_user(child, addr, data);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	ptrace_area parea; 
 	int copied, ret;
Signature · 1 line
1.7.2.2
#49 lore raw

RFC PATCH 34/43 ptrace, score: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

And removes unnecessary castings.

---
 arch/score/kernel/ptrace.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/score/kernel/ptrace.c +4 -3
index 174c642..5583618 100644
@@ -325,7 +325,8 @@ void ptrace_disable(struct task_struct *child)
 }
 
 long
-arch_ptrace(struct task_struct *child, long request, long addr, long data)
+arch_ptrace(struct task_struct *child, long request,
+	    unsigned long addr, unsigned long data)
 {
 	int ret;
 	unsigned long __user *datap = (void __user *)data;
@@ -335,14 +336,14 @@ arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		ret = copy_regset_to_user(child, &user_score_native_view,
 						REGSET_GENERAL,
 						0, sizeof(struct pt_regs),
-						(void __user *)datap);
+						datap);
 		break;
 
 	case PTRACE_SETREGS:
 		ret = copy_regset_from_user(child, &user_score_native_view,
 						REGSET_GENERAL,
 						0, sizeof(struct pt_regs),
-						(const void __user *)datap);
+						datap);
 		break;
 
 	default:
Signature · 1 line
1.7.2.2
#50 lore raw

RFC PATCH 35/43 ptrace, sh: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/sh/kernel/ptrace_32.c |   31 +++++++++++++++----------------
 arch/sh/kernel/ptrace_64.c |   10 ++++++----
 2 files changed, 21 insertions(+), 20 deletions(-)
arch/sh/kernel/ptrace_32.c +15 -16
index 6c4bbba..c81a6b9 100644
@@ -338,7 +338,8 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 	return &user_sh_native_view;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	struct user * dummy = NULL;
 	unsigned long __user *datap = (unsigned long __user *)data;
@@ -350,23 +351,22 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		unsigned long tmp;
 
 		ret = -EIO;
-		if ((addr & 3) || addr < 0 ||
-		    addr > sizeof(struct user) - 3)
+		if ((addr & 3) || addr > sizeof(struct user) - 3)
 			break;
 
 		if (addr < sizeof(struct pt_regs))
 			tmp = get_stack_long(child, addr);
-		else if (addr >= (long) &dummy->fpu &&
-			 addr < (long) &dummy->u_fpvalid) {
+		else if (addr >= (unsigned long) &dummy->fpu &&
+			 addr < (unsigned long) &dummy->u_fpvalid) {
 			if (!tsk_used_math(child)) {
-				if (addr == (long)&dummy->fpu.fpscr)
+				if (addr == (unsigned long)&dummy->fpu.fpscr)
 					tmp = FPSCR_INIT;
 				else
 					tmp = 0;
 			} else
-				tmp = ((long *)child->thread.xstate)
-					[(addr - (long)&dummy->fpu) >> 2];
-		} else if (addr == (long) &dummy->u_fpvalid)
+				tmp = ((unsigned long *)child->thread.xstate)
+					[(addr - (unsigned long)&dummy->fpu) >> 2];
+		} else if (addr == (unsigned long) &dummy->u_fpvalid)
 			tmp = !!tsk_used_math(child);
 		else if (addr == PT_TEXT_ADDR)
 			tmp = child->mm->start_code;
@@ -384,19 +384,18 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
 	case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
 		ret = -EIO;
-		if ((addr & 3) || addr < 0 ||
-		    addr > sizeof(struct user) - 3)
+		if ((addr & 3) || addr > sizeof(struct user) - 3)
 			break;
 
 		if (addr < sizeof(struct pt_regs))
 			ret = put_stack_long(child, addr, data);
-		else if (addr >= (long) &dummy->fpu &&
-			 addr < (long) &dummy->u_fpvalid) {
+		else if (addr >= (unsigned long) &dummy->fpu &&
+			 addr < (unsigned long) &dummy->u_fpvalid) {
 			set_stopped_child_used_math(child);
-			((long *)child->thread.xstate)
-				[(addr - (long)&dummy->fpu) >> 2] = data;
+			((unsigned long *)child->thread.xstate)
+				[(addr - (unsigned long)&dummy->fpu) >> 2] = data;
 			ret = 0;
-		} else if (addr == (long) &dummy->u_fpvalid) {
+		} else if (addr == (unsigned long) &dummy->u_fpvalid) {
 			conditional_stopped_child_used_math(data, child);
 			ret = 0;
 		}
arch/sh/kernel/ptrace_64.c +6 -4
index 5fd644d..c2c2ed5 100644
@@ -304,7 +304,8 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 	return &user_sh64_native_view;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret;
 
@@ -314,7 +315,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 		unsigned long tmp;
 
 		ret = -EIO;
-		if ((addr & 3) || addr < 0)
+		if (addr & 3)
 			break;
 
 		if (addr < sizeof(struct pt_regs))
@@ -337,7 +338,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                    this could crash the kernel or result in a security
                    loophole. */
 		ret = -EIO;
-		if ((addr & 3) || addr < 0)
+		if (addr & 3)
 			break;
 
 		if (addr < sizeof(struct pt_regs)) {
@@ -392,7 +393,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	return ret;
 }
 
-asmlinkage int sh64_ptrace(long request, long pid, long addr, long data)
+asmlinkage int sh64_ptrace(long request, long pid,
+			   unsigned long addr, unsigned long data)
 {
 #define WPC_DBRMODE 0x0d104008
 	static int first_call = 1;
Signature · 1 line
1.7.2.2
#51 lore raw

RFC PATCH 36/43 ptrace, sh: cleanup arch_ptrace()

In reply to Namhyung Kim

remove unnecessary castings, get rid of dummy pointer in favour of offsetof() macro and use temporary variables in order to improve readability.

---
 arch/sh/kernel/ptrace_32.c |   38 +++++++++++++++++++++-----------------
 arch/sh/kernel/ptrace_64.c |   17 ++++++++++-------
 2 files changed, 31 insertions(+), 24 deletions(-)
arch/sh/kernel/ptrace_32.c +21 -17
index c81a6b9..926f706 100644
@@ -341,7 +341,6 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
-	struct user * dummy = NULL;
 	unsigned long __user *datap = (unsigned long __user *)data;
 	int ret;
 
@@ -356,17 +355,20 @@ long arch_ptrace(struct task_struct *child, long request,
 
 		if (addr < sizeof(struct pt_regs))
 			tmp = get_stack_long(child, addr);
-		else if (addr >= (unsigned long) &dummy->fpu &&
-			 addr < (unsigned long) &dummy->u_fpvalid) {
+		else if (addr >= offsetof(struct user, fpu) &&
+			 addr < offsetof(struct user, u_fpvalid)) {
 			if (!tsk_used_math(child)) {
-				if (addr == (unsigned long)&dummy->fpu.fpscr)
+				if (addr == offsetof(struct user, fpu.fpscr))
 					tmp = FPSCR_INIT;
 				else
 					tmp = 0;
-			} else
+			} else {
+				unsigned long index;
+				index = addr - offsetof(struct user, fpu);
 				tmp = ((unsigned long *)child->thread.xstate)
-					[(addr - (unsigned long)&dummy->fpu) >> 2];
-		} else if (addr == (unsigned long) &dummy->u_fpvalid)
+					[index >> 2];
+			}
+		} else if (addr == offsetof(struct user, u_fpvalid))
 			tmp = !!tsk_used_math(child);
 		else if (addr == PT_TEXT_ADDR)
 			tmp = child->mm->start_code;
@@ -389,13 +391,15 @@ long arch_ptrace(struct task_struct *child, long request,
 
 		if (addr < sizeof(struct pt_regs))
 			ret = put_stack_long(child, addr, data);
-		else if (addr >= (unsigned long) &dummy->fpu &&
-			 addr < (unsigned long) &dummy->u_fpvalid) {
+		else if (addr >= offsetof(struct user, fpu) &&
+			 addr < offsetof(struct user, u_fpvalid)) {
+			unsigned long index;
+			index = addr - offsetof(struct user, fpu);
 			set_stopped_child_used_math(child);
 			((unsigned long *)child->thread.xstate)
-				[(addr - (unsigned long)&dummy->fpu) >> 2] = data;
+				[index >> 2] = data;
 			ret = 0;
-		} else if (addr == (unsigned long) &dummy->u_fpvalid) {
+		} else if (addr == offsetof(struct user, u_fpvalid)) {
 			conditional_stopped_child_used_math(data, child);
 			ret = 0;
 		}
@@ -405,35 +409,35 @@ long arch_ptrace(struct task_struct *child, long request,
 		return copy_regset_to_user(child, &user_sh_native_view,
 					   REGSET_GENERAL,
 					   0, sizeof(struct pt_regs),
-					   (void __user *)data);
+					   datap);
 	case PTRACE_SETREGS:
 		return copy_regset_from_user(child, &user_sh_native_view,
 					     REGSET_GENERAL,
 					     0, sizeof(struct pt_regs),
-					     (const void __user *)data);
+					     datap);
 #ifdef CONFIG_SH_FPU
 	case PTRACE_GETFPREGS:
 		return copy_regset_to_user(child, &user_sh_native_view,
 					   REGSET_FPU,
 					   0, sizeof(struct user_fpu_struct),
-					   (void __user *)data);
+					   datap);
 	case PTRACE_SETFPREGS:
 		return copy_regset_from_user(child, &user_sh_native_view,
 					     REGSET_FPU,
 					     0, sizeof(struct user_fpu_struct),
-					     (const void __user *)data);
+					     datap);
 #endif
 #ifdef CONFIG_SH_DSP
 	case PTRACE_GETDSPREGS:
 		return copy_regset_to_user(child, &user_sh_native_view,
 					   REGSET_DSP,
 					   0, sizeof(struct pt_dspregs),
-					   (void __user *)data);
+					   datap);
 	case PTRACE_SETDSPREGS:
 		return copy_regset_from_user(child, &user_sh_native_view,
 					     REGSET_DSP,
 					     0, sizeof(struct pt_dspregs),
-					     (const void __user *)data);
+					     datap);
 #endif
 	default:
 		ret = ptrace_request(child, request, addr, data);
arch/sh/kernel/ptrace_64.c +10 -7
index c2c2ed5..5a33fac 100644
@@ -308,6 +308,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret;
+	unsigned long __user *datap = (unsigned long __user *) data;
 
 	switch (request) {
 	/* read the word at location addr in the USER area. */
@@ -322,13 +323,14 @@ long arch_ptrace(struct task_struct *child, long request,
 			tmp = get_stack_long(child, addr);
 		else if ((addr >= offsetof(struct user, fpu)) &&
 			 (addr <  offsetof(struct user, u_fpvalid))) {
-			tmp = get_fpu_long(child, addr - offsetof(struct user, fpu));
+			unsigned long index = addr - offsetof(struct user, fpu);
+			tmp = get_fpu_long(child, index);
 		} else if (addr == offsetof(struct user, u_fpvalid)) {
 			tmp = !!tsk_used_math(child);
 		} else {
 			break;
 		}
-		ret = put_user(tmp, (unsigned long *)data);
+		ret = put_user(tmp, datap);
 		break;
 	}
 
@@ -359,7 +361,8 @@ long arch_ptrace(struct task_struct *child, long request,
 		}
 		else if ((addr >= offsetof(struct user, fpu)) &&
 			 (addr <  offsetof(struct user, u_fpvalid))) {
-			ret = put_fpu_long(child, addr - offsetof(struct user, fpu), data);
+			unsigned long index = addr - offsetof(struct user, fpu);
+			ret = put_fpu_long(child, index, data);
 		}
 		break;
 
@@ -367,23 +370,23 @@ long arch_ptrace(struct task_struct *child, long request,
 		return copy_regset_to_user(child, &user_sh64_native_view,
 					   REGSET_GENERAL,
 					   0, sizeof(struct pt_regs),
-					   (void __user *)data);
+					   datap);
 	case PTRACE_SETREGS:
 		return copy_regset_from_user(child, &user_sh64_native_view,
 					     REGSET_GENERAL,
 					     0, sizeof(struct pt_regs),
-					     (const void __user *)data);
+					     datap);
 #ifdef CONFIG_SH_FPU
 	case PTRACE_GETFPREGS:
 		return copy_regset_to_user(child, &user_sh64_native_view,
 					   REGSET_FPU,
 					   0, sizeof(struct user_fpu_struct),
-					   (void __user *)data);
+					   datap);
 	case PTRACE_SETFPREGS:
 		return copy_regset_from_user(child, &user_sh64_native_view,
 					     REGSET_FPU,
 					     0, sizeof(struct user_fpu_struct),
-					     (const void __user *)data);
+					     datap);
 #endif
 	default:
 		ret = ptrace_request(child, request, addr, data);
Signature · 1 line
1.7.2.2
#52 lore raw

RFC PATCH 37/43 ptrace, sparc: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

Cc "David S. Miller" <[email protected]>
---
 arch/sparc/kernel/ptrace_32.c |    3 ++-
 arch/sparc/kernel/ptrace_64.c |    7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/sparc/kernel/ptrace_32.c +2 -1
index e608f39..e08ba4a 100644
@@ -323,7 +323,8 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 	return &user_sparc32_view;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
 	const struct user_regset_view *view;
arch/sparc/kernel/ptrace_64.c +4 -3
index aa90da0..d9db5a4 100644
@@ -969,7 +969,8 @@ struct fps {
 	unsigned long fsr;
 };
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	const struct user_regset_view *view = task_user_regset_view(current);
 	unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
@@ -977,8 +978,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	struct fps __user *fps;
 	int ret;
 
-	pregs = (struct pt_regs __user *) (unsigned long) addr;
-	fps = (struct fps __user *) (unsigned long) addr;
+	pregs = (struct pt_regs __user *) addr;
+	fps = (struct fps __user *) addr;
 
 	switch (request) {
 	case PTRACE_PEEKUSR:
Signature · 1 line
1.7.2.2
#53 lore raw

RFC PATCH 38/43 ptrace, sparc: cleanup arch_ptrace()

In reply to Namhyung Kim

factor out struct fps and remove redundant castings.

Cc "David S. Miller" <[email protected]>
---
 arch/sparc/kernel/ptrace_32.c |   54 +++++++++++++++-------------------------
 arch/sparc/kernel/ptrace_64.c |    8 +++---
 2 files changed, 24 insertions(+), 38 deletions(-)
arch/sparc/kernel/ptrace_32.c +20 -34
index e08ba4a..27b9e93 100644
@@ -323,19 +323,35 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 	return &user_sparc32_view;
 }
 
+struct fps {
+	unsigned long regs[32];
+	unsigned long fsr;
+	unsigned long flags;
+	unsigned long extra;
+	unsigned long fpqd;
+	struct fq {
+		unsigned long *insnaddr;
+		unsigned long insn;
+	} fpq[16];
+};
+
 long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
+	void __user *addr2p;
 	const struct user_regset_view *view;
+	struct pt_regs __user *pregs;
+	struct fps __user *fps;
 	int ret;
 
 	view = task_user_regset_view(current);
+	addr2p = (void __user *) addr2;
+	pregs = (struct pt_regs __user *) addr;
+	fps = (struct fps __user *) addr;
 
 	switch(request) {
 	case PTRACE_GETREGS: {
-		struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
-
 		ret = copy_regset_to_user(child, view, REGSET_GENERAL,
 					  32 * sizeof(u32),
 					  4 * sizeof(u32),
@@ -349,8 +365,6 @@ long arch_ptrace(struct task_struct *child, long request,
 	}
 
 	case PTRACE_SETREGS: {
-		struct pt_regs __user *pregs = (struct pt_regs __user *) addr;
-
 		ret = copy_regset_from_user(child, view, REGSET_GENERAL,
 					    32 * sizeof(u32),
 					    4 * sizeof(u32),
@@ -364,19 +378,6 @@ long arch_ptrace(struct task_struct *child, long request,
 	}
 
 	case PTRACE_GETFPREGS: {
-		struct fps {
-			unsigned long regs[32];
-			unsigned long fsr;
-			unsigned long flags;
-			unsigned long extra;
-			unsigned long fpqd;
-			struct fq {
-				unsigned long *insnaddr;
-				unsigned long insn;
-			} fpq[16];
-		};
-		struct fps __user *fps = (struct fps __user *) addr;
-
 		ret = copy_regset_to_user(child, view, REGSET_FP,
 					  0 * sizeof(u32),
 					  32 * sizeof(u32),
@@ -398,19 +399,6 @@ long arch_ptrace(struct task_struct *child, long request,
 	}
 
 	case PTRACE_SETFPREGS: {
-		struct fps {
-			unsigned long regs[32];
-			unsigned long fsr;
-			unsigned long flags;
-			unsigned long extra;
-			unsigned long fpqd;
-			struct fq {
-				unsigned long *insnaddr;
-				unsigned long insn;
-			} fpq[16];
-		};
-		struct fps __user *fps = (struct fps __user *) addr;
-
 		ret = copy_regset_from_user(child, view, REGSET_FP,
 					    0 * sizeof(u32),
 					    32 * sizeof(u32),
@@ -425,8 +413,7 @@ long arch_ptrace(struct task_struct *child, long request,
 
 	case PTRACE_READTEXT:
 	case PTRACE_READDATA:
-		ret = ptrace_readdata(child, addr,
-				      (void __user *) addr2, data);
+		ret = ptrace_readdata(child, addr, addr2p, data);
 
 		if (ret == data)
 			ret = 0;
@@ -436,8 +423,7 @@ long arch_ptrace(struct task_struct *child, long request,
 
 	case PTRACE_WRITETEXT:
 	case PTRACE_WRITEDATA:
-		ret = ptrace_writedata(child, (void __user *) addr2,
-				       addr, data);
+		ret = ptrace_writedata(child, addr2p, addr, data);
 
 		if (ret == data)
 			ret = 0;
arch/sparc/kernel/ptrace_64.c +4 -4
index d9db5a4..9ccc812 100644
@@ -976,10 +976,12 @@ long arch_ptrace(struct task_struct *child, long request,
 	unsigned long addr2 = task_pt_regs(current)->u_regs[UREG_I4];
 	struct pt_regs __user *pregs;
 	struct fps __user *fps;
+	void __user *addr2p;
 	int ret;
 
 	pregs = (struct pt_regs __user *) addr;
 	fps = (struct fps __user *) addr;
+	addr2p = (void __user *) addr2;
 
 	switch (request) {
 	case PTRACE_PEEKUSR:
@@ -1030,8 +1032,7 @@ long arch_ptrace(struct task_struct *child, long request,
 
 	case PTRACE_READTEXT:
 	case PTRACE_READDATA:
-		ret = ptrace_readdata(child, addr,
-				      (char __user *)addr2, data);
+		ret = ptrace_readdata(child, addr, addr2p, data);
 		if (ret == data)
 			ret = 0;
 		else if (ret >= 0)
@@ -1040,8 +1041,7 @@ long arch_ptrace(struct task_struct *child, long request,
 
 	case PTRACE_WRITETEXT:
 	case PTRACE_WRITEDATA:
-		ret = ptrace_writedata(child, (char __user *) addr2,
-				       addr, data);
+		ret = ptrace_writedata(child, addr2p, addr, data);
 		if (ret == data)
 			ret = 0;
 		else if (ret >= 0)
Signature · 1 line
1.7.2.2
#54 lore raw

RFC PATCH 39/43 ptrace, tile: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/tile/kernel/ptrace.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
arch/tile/kernel/ptrace.c +6 -5
index 7161bd0..704bf11 100644
@@ -64,7 +64,8 @@ void ptrace_disable(struct task_struct *child)
 	clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	unsigned long __user *datap;
 	unsigned long tmp;
@@ -84,7 +85,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	case PTRACE_PEEKUSR:  /* Read register from pt_regs. */
 		if (addr & (sizeof(data)-1))
 			break;
-		if (addr < 0 || addr >= PTREGS_SIZE)
+		if (addr >= PTREGS_SIZE)
 			break;
 		tmp = getreg(child, addr);   /* Read register */
 		ret = put_user(tmp, datap);
@@ -93,7 +94,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	case PTRACE_POKEUSR:  /* Write register in pt_regs. */
 		if (addr & (sizeof(data)-1))
 			break;
-		if (addr < 0 || addr >= PTREGS_SIZE)
+		if (addr >= PTREGS_SIZE)
 			break;
 		putreg(child, addr, data);   /* Write register */
 		ret = 0;
@@ -102,7 +103,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	case PTRACE_GETREGS:  /* Get all registers from the child. */
 		if (!access_ok(VERIFY_WRITE, datap, PTREGS_SIZE))
 			break;
-		for (i = 0; i < PTREGS_SIZE; i += sizeof(long)) {
+		for (i = 0; i < PTREGS_SIZE; i += sizeof(unsigned long)) {
 			ret = __put_user(getreg(child, i), datap);
 			if (ret != 0)
 				break;
@@ -113,7 +114,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 	case PTRACE_SETREGS:  /* Set all registers in the child. */
 		if (!access_ok(VERIFY_READ, datap, PTREGS_SIZE))
 			break;
-		for (i = 0; i < PTREGS_SIZE; i += sizeof(long)) {
+		for (i = 0; i < PTREGS_SIZE; i += sizeof(unsigned long)) {
 			ret = __get_user(tmp, datap);
 			if (ret != 0)
 				break;
Signature · 1 line
1.7.2.2
#55 lore raw

RFC PATCH 40/43 ptrace, um: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/um/kernel/ptrace.c     |    5 +++--
 arch/um/sys-i386/ptrace.c   |    4 ++--
 arch/um/sys-x86_64/ptrace.c |    4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)
arch/um/kernel/ptrace.c +3 -2
index e051049..963d82b 100644
@@ -42,10 +42,11 @@ void ptrace_disable(struct task_struct *child)
 extern int peek_user(struct task_struct * child, long addr, long data);
 extern int poke_user(struct task_struct * child, long addr, long data);
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int i, ret;
-	unsigned long __user *p = (void __user *)(unsigned long)data;
+	unsigned long __user *p = (void __user *)data;
 
 	switch (request) {
 	/* read word at location addr. */
arch/um/sys-i386/ptrace.c +2 -2
index c9b1765..d23b2d3 100644
@@ -203,8 +203,8 @@ int set_fpxregs(struct user_fxsr_struct __user *buf, struct task_struct *child)
 				     (unsigned long *) &fpregs);
 }
 
-long subarch_ptrace(struct task_struct *child, long request, long addr,
-		    long data)
+long subarch_ptrace(struct task_struct *child, long request,
+		    unsigned long addr, unsigned long data)
 {
 	return -EIO;
 }
arch/um/sys-x86_64/ptrace.c +2 -2
index f3458d7..67e6368 100644
@@ -175,8 +175,8 @@ int set_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
 	return restore_fp_registers(userspace_pid[cpu], fpregs);
 }
 
-long subarch_ptrace(struct task_struct *child, long request, long addr,
-		    long data)
+long subarch_ptrace(struct task_struct *child, long request,
+		    unsigned long addr, unsigned long data)
 {
 	int ret = -EIO;
 
Signature · 1 line
1.7.2.2
#56 lore raw

RFC PATCH 41/43 ptrace, um: cleanup arch_ptrace()

In reply to Namhyung Kim

remove unnecessary castings using void pointer and fix copy_to_user() return value.

---
 arch/um/kernel/ptrace.c     |   23 +++++++++++------------
 arch/um/sys-x86_64/ptrace.c |    7 +++----
 2 files changed, 14 insertions(+), 16 deletions(-)
arch/um/kernel/ptrace.c +11 -12
index 963d82b..137a1bc 100644
@@ -46,7 +46,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int i, ret;
-	unsigned long __user *p = (void __user *)data;
+	void __user *p = (void __user *)data;
 
 	switch (request) {
 	/* read word at location addr. */
@@ -78,12 +78,14 @@ long arch_ptrace(struct task_struct *child, long request,
 
 #ifdef PTRACE_GETREGS
 	case PTRACE_GETREGS: { /* Get all gp regs from the child. */
+		unsigned long tmp;
 		if (!access_ok(VERIFY_WRITE, p, MAX_REG_OFFSET)) {
 			ret = -EIO;
 			break;
 		}
 		for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
-			__put_user(getreg(child, i), p);
+			tmp = getreg(child, i);
+			__copy_to_user(p, &tmp, sizeof(tmp));
 			p++;
 		}
 		ret = 0;
@@ -98,7 +100,7 @@ long arch_ptrace(struct task_struct *child, long request,
 			break;
 		}
 		for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
-			__get_user(tmp, p);
+			__copy_from_user(&tmp, p, sizeof(tmp));
 			putreg(child, i, tmp);
 			p++;
 		}
@@ -108,24 +110,20 @@ long arch_ptrace(struct task_struct *child, long request,
 #endif
 #ifdef PTRACE_GETFPREGS
 	case PTRACE_GETFPREGS: /* Get the child FPU state. */
-		ret = get_fpregs((struct user_i387_struct __user *) data,
-				 child);
+		ret = get_fpregs(p, child);
 		break;
 #endif
 #ifdef PTRACE_SETFPREGS
 	case PTRACE_SETFPREGS: /* Set the child FPU state. */
-	        ret = set_fpregs((struct user_i387_struct __user *) data,
-				 child);
+	        ret = set_fpregs(p, child);
 		break;
 #endif
 	case PTRACE_GET_THREAD_AREA:
-		ret = ptrace_get_thread_area(child, addr,
-					     (struct user_desc __user *) data);
+		ret = ptrace_get_thread_area(child, addr, p);
 		break;
 
 	case PTRACE_SET_THREAD_AREA:
-		ret = ptrace_set_thread_area(child, addr,
-					     (struct user_desc __user *) data);
+		ret = ptrace_set_thread_area(child, addr, p);
 		break;
 
 	case PTRACE_FAULTINFO: {
@@ -135,7 +133,8 @@ long arch_ptrace(struct task_struct *child, long request,
 		 * On i386, ptrace_faultinfo is smaller!
 		 */
 		ret = copy_to_user(p, &child->thread.arch.faultinfo,
-				   sizeof(struct ptrace_faultinfo));
+				   sizeof(struct ptrace_faultinfo)) ?
+			-EIO : 0;
 		break;
 	}
 
arch/um/sys-x86_64/ptrace.c +3 -4
index 67e6368..f436136 100644
@@ -179,15 +179,14 @@ long subarch_ptrace(struct task_struct *child, long request,
 		    unsigned long addr, unsigned long data)
 {
 	int ret = -EIO;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 	case PTRACE_GETFPXREGS: /* Get the child FPU state. */
-		ret = get_fpregs((struct user_i387_struct __user *) data,
-				 child);
+		ret = get_fpregs(datap, child);
 		break;
 	case PTRACE_SETFPXREGS: /* Set the child FPU state. */
-		ret = set_fpregs((struct user_i387_struct __user *) data,
-				 child);
+		ret = set_fpregs(datap, child);
 		break;
 	}
 
Signature · 1 line
1.7.2.2
#57 lore raw

RFC PATCH 42/43 ptrace, xtensa: change signature of arch_ptrace()

In reply to Namhyung Kim

change type of @addr and @data into unsigned long according to commit f76671df26ef06321480e702770f88f61272be29 [PATCH 03/43]

---
 arch/xtensa/kernel/ptrace.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/xtensa/kernel/ptrace.c +2 -1
index 9d4e1ce..af9ba80 100644
@@ -256,7 +256,8 @@ int ptrace_pokeusr(struct task_struct *child, long regno, long val)
 	return 0;
 }
 
-long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+long arch_ptrace(struct task_struct *child, long request,
+		 unsigned long addr, unsigned long data)
 {
 	int ret = -EPERM;
 
Signature · 1 line
1.7.2.2
#58 lore raw

RFC PATCH 43/43 ptrace, xtensa: cleanup arch_ptrace()

In reply to Namhyung Kim

use new 'datap' variable in order to remove unnecessary castings.

---
 arch/xtensa/kernel/ptrace.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
arch/xtensa/kernel/ptrace.c +6 -5
index af9ba80..c72c947 100644
@@ -260,6 +260,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		 unsigned long addr, unsigned long data)
 {
 	int ret = -EPERM;
+	void __user *datap = (void __user *) data;
 
 	switch (request) {
 	case PTRACE_PEEKTEXT:	/* read word at location addr. */
@@ -268,7 +269,7 @@ long arch_ptrace(struct task_struct *child, long request,
 		break;
 
 	case PTRACE_PEEKUSR:	/* read register specified by addr. */
-		ret = ptrace_peekusr(child, addr, (void __user *) data);
+		ret = ptrace_peekusr(child, addr, datap);
 		break;
 
 	case PTRACE_POKETEXT:	/* write the word at location addr. */
@@ -281,19 +282,19 @@ long arch_ptrace(struct task_struct *child, long request,
 		break;
 
 	case PTRACE_GETREGS:
-		ret = ptrace_getregs(child, (void __user *) data);
+		ret = ptrace_getregs(child, datap);
 		break;
 
 	case PTRACE_SETREGS:
-		ret = ptrace_setregs(child, (void __user *) data);
+		ret = ptrace_setregs(child, datap);
 		break;
 
 	case PTRACE_GETXTREGS:
-		ret = ptrace_getxregs(child, (void __user *) data);
+		ret = ptrace_getxregs(child, datap);
 		break;
 
 	case PTRACE_SETXTREGS:
-		ret = ptrace_setxregs(child, (void __user *) data);
+		ret = ptrace_setxregs(child, datap);
 		break;
 
 	default:
Signature · 1 line
1.7.2.2
#59 lore raw
In reply to Namhyung Kim
Quoted 5 lines · Namhyung Kim

Although I couldn't test all archs, I hope it will not break anything. Exceptional case will be "03/43 ptrace: change signature of arch_ptrace()" commit since it changes prototype of arch_ptrace() in system header file. It *will* break your build if it is applied alone, please use it with your arch counterpart. The same goes vice versa, of course.

sounds like these changes should be squashed into one then -mike

#60 lore raw
In reply to Namhyung Kim

I am fine with the s/long/unsigned long/ signature changes. Adding temporaries to avoid the repeated casts is fine too. All that will compile away to the same code we have now. But please do it without changing put_user/get_user calls to copy_{to,from}_user. With a temporary or two you'll still have fewer casts than before. IMHO you should at least do a separate follow-on patch for anything that actually changes the compiled code vs just the cosmetic type cleanups.

Thanks,
Roland

#61 lore raw
Quoted 8 lines · Roland McGrath

I am fine with the s/long/unsigned long/ signature changes. Adding temporaries to avoid the repeated casts is fine too. All that will compile away to the same code we have now. But please do it without changing put_user/get_user calls to copy_{to,from}_user. With a temporary or two you'll still have fewer casts than before. IMHO you should at least do a separate follow-on patch for anything that actually changes the compiled code vs just the cosmetic type cleanups.

OK. I'll do that on next round.
Thanks.

Signature · 2 lines
Regards,
Namhyung Kim