[Linux-ia64] Fix error checking in sys32_ptrace

From: Andreas Schwab <schwab_at_suse.de>
Date: 2003-03-28 02:02:48
This fixes sys32_ptrace to use ptrace_check_attach, so that it
automatically inherits all future enhancements there.

Andreas.

--- linux-2.4.19/arch/ia64/ia32/sys_ia32.c.~1~	2003-03-20 16:33:21.000000000 +0100
+++ linux-2.4.19/arch/ia64/ia32/sys_ia32.c	2003-03-21 22:27:32.000000000 +0100
@@ -3076,26 +3076,23 @@ sys32_ptrace (int request, pid_t pid, un
 	ret = -ESRCH;
 	read_lock(&tasklist_lock);
 	child = find_task_by_pid(pid);
+	if (child)
+		get_task_struct(child);
 	read_unlock(&tasklist_lock);
 	if (!child)
 		goto out;
 	ret = -EPERM;
 	if (pid == 1)		/* no messing around with init! */
-		goto out;
+		goto out_tsk;
 
 	if (request == PTRACE_ATTACH) {
 		ret = sys_ptrace(request, pid, addr, data, arg4, arg5, arg6, arg7, stack);
-		goto out;
-	}
-	ret = -ESRCH;
-	if (!(child->ptrace & PT_PTRACED))
-		goto out;
-	if (child->state != TASK_STOPPED) {
-		if (request != PTRACE_KILL)
-			goto out;
+		goto out_tsk;
 	}
-	if (child->p_pptr != current)
-		goto out;
+
+	ret = ptrace_check_attach(child, request == PTRACE_KILL);
+	if (ret < 0)
+		goto out_tsk;
 
 	switch (request) {
 	      case PTRACE_PEEKTEXT:
@@ -3105,12 +3102,12 @@ sys32_ptrace (int request, pid_t pid, un
 			ret = put_user(value, (unsigned int *) A(data));
 		else
 			ret = -EIO;
-		goto out;
+		goto out_tsk;
 
 	      case PTRACE_POKETEXT:
 	      case PTRACE_POKEDATA:	/* write the word at location addr */
 		ret = ia32_poke(regs, child, addr, data);
-		goto out;
+		goto out_tsk;
 
 	      case PTRACE_PEEKUSR:	/* read word at addr in USER area */
 		ret = -EIO;
@@ -3185,6 +3182,8 @@ sys32_ptrace (int request, pid_t pid, un
 		break;
 
 	}
+  out_tsk:
+	free_task_struct(child);
   out:
 	unlock_kernel();
 	return ret;

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Received on Thu Mar 27 07:02:59 2003

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:12 EST