PTRACE_POKEDATA consolidation
authorAlexey Dobriyan <adobriyan@gmail.com>
Tue, 17 Jul 2007 11:03:44 +0000 (04:03 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 17 Jul 2007 17:23:03 +0000 (10:23 -0700)
Identical implementations of PTRACE_POKEDATA go into generic_ptrace_pokedata()
function.

AFAICS, fix bug on xtensa where successful PTRACE_POKEDATA will nevertheless
return EPERM.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
23 files changed:
arch/alpha/kernel/ptrace.c
arch/arm/kernel/ptrace.c
arch/arm26/kernel/ptrace.c
arch/avr32/kernel/ptrace.c
arch/cris/arch-v10/kernel/ptrace.c
arch/cris/arch-v32/kernel/ptrace.c
arch/frv/kernel/ptrace.c
arch/h8300/kernel/ptrace.c
arch/i386/kernel/ptrace.c
arch/m32r/kernel/ptrace.c
arch/m68k/kernel/ptrace.c
arch/m68knommu/kernel/ptrace.c
arch/mips/kernel/ptrace.c
arch/powerpc/kernel/ptrace.c
arch/s390/kernel/ptrace.c
arch/sh/kernel/ptrace.c
arch/sh64/kernel/ptrace.c
arch/um/kernel/ptrace.c
arch/v850/kernel/ptrace.c
arch/x86_64/kernel/ptrace.c
arch/xtensa/kernel/ptrace.c
include/linux/ptrace.h
kernel/ptrace.c

index 0cd060598f9aa25aee8d86a6629cc4d8514542ed..83a78184226623fa78f51e52c5643ce148de6f3f 100644 (file)
@@ -315,9 +315,7 @@ do_sys_ptrace(long request, long pid, long addr, long data,
        /* When I and D space are separate, this will have to be fixed.  */
        case PTRACE_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               tmp = data;
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 1);
-               ret = (copied == sizeof(tmp)) ? 0 : -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: /* write the specified register */
index 9a5d9754c2a274e155bd712fe98bcb62664930ca..78c9f1a3d41f725c428b352d413289c564ec3933 100644 (file)
@@ -677,12 +677,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                 */
                case PTRACE_POKETEXT:
                case PTRACE_POKEDATA:
-                       ret = access_process_vm(child, addr, &data,
-                                               sizeof(unsigned long), 1);
-                       if (ret == sizeof(unsigned long))
-                               ret = 0;
-                       else
-                               ret = -EIO;
+                       ret = generic_ptrace_pokedata(child, addr, data);
                        break;
 
                case PTRACE_POKEUSR:
index 0d0ead0e0a74db0c402aba36ca3c290dc6ef25a0..0fefb86970c6005c99bcdb6c36401d7cfde67598 100644 (file)
@@ -551,12 +551,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                 */
                case PTRACE_POKETEXT:
                case PTRACE_POKEDATA:
-                       ret = access_process_vm(child, addr, &data,
-                                               sizeof(unsigned long), 1);
-                       if (ret == sizeof(unsigned long))
-                               ret = 0;
-                       else
-                               ret = -EIO;
+                       ret = generic_ptrace_pokedata(child, addr, data);
                        break;
 
                case PTRACE_POKEUSR:
index 1043fdc2df7ff476444fd845171640611247ec7b..39060cbeb2a3e2acc45509fe8ea8303222bd17e3 100644 (file)
@@ -176,11 +176,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        /* Write the word in data at location addr */
        case PTRACE_POKETEXT:
        case PTRACE_POKEDATA:
-               ret = access_process_vm(child, addr, &data, sizeof(data), 1);
-               if (ret == sizeof(data))
-                       ret = 0;
-               else
-                       ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR:
index 74b1b4dc822527a5f901d899233bc5f187735fe9..f4f9db698b445afff62158c4b8e00e3451145b0c 100644 (file)
@@ -103,12 +103,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                /* Write the word at location address. */
                case PTRACE_POKETEXT:
                case PTRACE_POKEDATA:
-                       ret = 0;
-                       
-                       if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                               break;
-                       
-                       ret = -EIO;
+                       ret = generic_ptrace_pokedata(child, addr, data);
                        break;
  
                /* Write the word at location address in the USER area. */
index d4d57b74133436a607518e7471318c3c1def3b92..38ece0cd47cbbd4c6195b9e9bc1dbcc13f80e353 100644 (file)
@@ -146,12 +146,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                /* Write the word at location address. */
                case PTRACE_POKETEXT:
                case PTRACE_POKEDATA:
-                       ret = 0;
-
-                       if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                               break;
-
-                       ret = -EIO;
+                       ret = generic_ptrace_pokedata(child, addr, data);
                        break;
 
                /* Write the word at location address in the USER area. */
index a10f3092fad4b2f535f38c87ce57afae4cfc4b89..709e9bdc6126de06417624a0edd8297dca38dc22 100644 (file)
@@ -168,9 +168,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                ret = -EIO;
                if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0)
                        break;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1) != sizeof(data))
-                       break;
-               ret = 0;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index 8a7a991b8f765ffb1fa47883eeffef39af1d3110..d32bbf02fc480a75229efc3acc3ac4b808da3959 100644 (file)
@@ -111,10 +111,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_POKETEXT: /* write the word at location addr. */
                case PTRACE_POKEDATA:
-                       ret = 0;
-                       if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                               break;
-                       ret = -EIO;
+                       ret = generic_ptrace_pokedata(child, addr, data);
                        break;
 
                case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index f4bcf1da662a713f5cffa514ceb60f107419f86d..1c075f58d1f9e2a8d33353513d63fcb3504d6e15 100644 (file)
@@ -387,10 +387,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_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index 01a1c9ac8458610226ea3213570ca32071e80ea3..57a92ef31a903ea7f4fd156a3097aa3d3a903a00 100644 (file)
@@ -619,15 +619,9 @@ do_ptrace(long request, struct task_struct *child, long addr, long data)
         */
        case PTRACE_POKETEXT:
        case PTRACE_POKEDATA:
-               ret = access_process_vm(child, addr, &data, sizeof(data), 1);
-               if (ret == sizeof(data)) {
-                       ret = 0;
-                       if (request == PTRACE_POKETEXT) {
-                               invalidate_cache();
-                       }
-               } else {
-                       ret = -EIO;
-               }
+               ret = generic_ptrace_pokedata(child, addr, data);
+               if (ret == 0 && request == PTRACE_POKETEXT)
+                       invalidate_cache();
                break;
 
        /*
index 01a3a09c53d9c381e5dc7dac8fe303dfe87f4ca3..2cf0690b78824f2e4e668d8d982b6d483ee77621 100644 (file)
@@ -157,8 +157,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_POKETEXT:   /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               if (access_process_vm(child, addr, &data, sizeof(data), 1) != sizeof(data))
-                       goto out_eio;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR:    /* write the word at location addr in the USER area */
index f550e614aa787d352ae7ec80db5dc3bb8503fdba..ef70ca070ce298a123efa24536106378ab52357f 100644 (file)
@@ -151,10 +151,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_POKETEXT: /* write the word at location addr. */
                case PTRACE_POKEDATA:
-                       ret = 0;
-                       if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                               break;
-                       ret = -EIO;
+                       ret = generic_ptrace_pokedata(child, addr, data);
                        break;
 
                case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index af9d0bec8731b825829ddfcf48c187614694b71a..893e7bccf2265c58ceea847db33824c393d502c5 100644 (file)
@@ -305,11 +305,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_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1)
-                   == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: {
index 581d427148e70f33caebfd685349fb705a49872b..8a177bd9eab4ff5746963e484e22b021d9d2578d 100644 (file)
@@ -413,11 +413,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        /* If I and D space are separate, this will have to be fixed. */
        case PTRACE_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1)
-                               == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        /* write the word at location addr in the USER area */
index 28afff4e5d1b3594f33b2f0141a5d4d7fe53e4f7..f4503ca27630165b4166d93f275a90a525dac0e6 100644 (file)
@@ -314,10 +314,7 @@ do_ptrace_normal(struct task_struct *child, long request, long addr, long data)
                /* Remove high order bit from address (only for 31 bit). */
                addr &= PSW_ADDR_INSN;
                /* write the word at location addr. */
-               copied = access_process_vm(child, addr, &data, sizeof(data),1);
-               if (copied != sizeof(data))
-                       return -EIO;
-               return 0;
+               return generic_ptrace_pokedata(child, addr, data);
 
        case PTRACE_POKEUSR:
                /* write the word at location addr in the USER area */
index f23f949576a52b106c1a4dfc82be5de89d4c6c39..891d1d46c902dba4850f950539951b7bc2ec4b2a 100644 (file)
@@ -126,10 +126,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_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index 12340e499bfba166f38bb8c37cdcd4aaae1789fe..df06c647746815cb0fb5ef19230ad80af9649372 100644 (file)
@@ -158,10 +158,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_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR:
index 1966da6eb36395157aa0858d24d0f3dde16ef966..6916c8888dba7156850c16c9eb22009da851674a 100644 (file)
@@ -64,11 +64,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_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = -EIO;
-               if (access_process_vm(child, addr, &data, sizeof(data), 
-                                     1) != sizeof(data))
-                       break;
-               ret = 0;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index 3bedd144e52d2e4cf1048827636fedf105de01f9..a458ac941b25b8fb432e83dc99f4c40c18aba1f7 100644 (file)
@@ -126,11 +126,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
        case PTRACE_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               rval = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1)
-                   == sizeof(data))
-                       break;
-               rval = -EIO;
+               rval = generic_ptrace_pokedata(child, addr, data);
                goto out;
 
        /* Read/write the word at location ADDR in the registers.  */
index 327ff93a38b68077a656fac9f47fe98066c93482..fa6775ef729f4a076f7a19341d48f50dd2248fe7 100644 (file)
@@ -359,10 +359,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_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                break;
 
        case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
index af182d3a700086def4a8e2180c19c92d1a05f969..06a13d9b69db54945e4d8a979e4468c88b9861ca 100644 (file)
@@ -128,10 +128,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
        case PTRACE_POKETEXT: /* write the word at location addr. */
        case PTRACE_POKEDATA:
-               if (access_process_vm(child, addr, &data, sizeof(data), 1)
-                   == sizeof(data))
-                       break;
-               ret = -EIO;
+               ret = generic_ptrace_pokedata(child, addr, data);
                goto out;
 
        case PTRACE_POKEUSR:
index 477cc8ed6bcb2d2fdd5b57d41d85fe9e4a3cc5d9..ae8146abd7463b694f0690353a13545c840890fd 100644 (file)
@@ -111,6 +111,7 @@ static inline void ptrace_unlink(struct task_struct *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);
 
 #ifndef force_successful_syscall_return
 /*
index 1653d35419a1cdd60aae7af2b592254fcc125273..4a1745f1dadf28c93cad33eadc135d8190912462 100644 (file)
@@ -501,3 +501,11 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
                return -EIO;
        return put_user(tmp, (unsigned long __user *)data);
 }
+
+int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
+{
+       int copied;
+
+       copied = access_process_vm(tsk, addr, &data, sizeof(data), 1);
+       return (copied == sizeof(data)) ? 0 : -EIO;
+}