Skip to content

Commit

Permalink
PTRACE_POKEDATA consolidation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alexey Dobriyan authored and Linus Torvalds committed Jul 17, 2007
1 parent 7664732 commit f284ce7
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 98 deletions.
4 changes: 1 addition & 3 deletions arch/alpha/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
7 changes: 1 addition & 6 deletions arch/arm/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions arch/arm26/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions arch/avr32/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 1 addition & 6 deletions arch/cris/arch-v10/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
7 changes: 1 addition & 6 deletions arch/cris/arch-v32/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
4 changes: 1 addition & 3 deletions arch/frv/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/h8300/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/i386/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 3 additions & 9 deletions arch/m32r/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down
3 changes: 1 addition & 2 deletions arch/m68k/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/m68knommu/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 1 addition & 5 deletions arch/mips/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 1 addition & 5 deletions arch/powerpc/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/s390/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/sh/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/sh64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions arch/um/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 1 addition & 5 deletions arch/v850/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
5 changes: 1 addition & 4 deletions arch/x86_64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions arch/xtensa/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions include/linux/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*
Expand Down
8 changes: 8 additions & 0 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f284ce7

Please sign in to comment.