From nobody@FreeBSD.org  Fri Apr 30 02:04:49 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 3F50D106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Apr 2010 02:04:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 2E5198FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Apr 2010 02:04:49 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o3U24nrf044087
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Apr 2010 02:04:49 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o3U24mj9044086;
	Fri, 30 Apr 2010 02:04:48 GMT
	(envelope-from nobody)
Message-Id: <201004300204.o3U24mj9044086@www.freebsd.org>
Date: Fri, 30 Apr 2010 02:04:48 GMT
From: Gunnar Hinriksson <tomtinn@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ptrace PT_DETACH undocumented behavior
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         146167
>Category:       kern
>Synopsis:       [ptrace] [patch] ptrace PT_DETACH undocumented behavior
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 30 02:10:01 UTC 2010
>Closed-Date:    Mon Aug 09 20:10:58 UTC 2010
>Last-Modified:  Mon Aug 09 20:10:58 UTC 2010
>Originator:     Gunnar Hinriksson
>Release:        8.0-RELEASE-p2
>Organization:
>Environment:
FreeBSD knut 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Tue Apr 27 04:36:16 UTC 2010     gunnar@knut:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
When using PT_DETACH on ptrace the (caddr_t addr) parameter is not ignored like the documentation suggests.
Instead it proceeds to change the execution address to the value of the parameter if it is not (void *)1.
This can cause portability problems from other systems that implement ptrace and assume that the parameter is ignored.
>How-To-Repeat:
Write a program that uses ptrace to attach to another process and then detach with the parameter (caddr_t addr) value not equal to 1.
This can cause the child process to segfault.
>Fix:
Attached patch.

Patch attached with submission follows:

--- /usr/src/sys/kern/sys_process.c	2009-10-25 01:10:29.000000000 +0000
+++ sys_process.c	2010-04-30 01:32:52.507274805 +0000
@@ -741,10 +741,13 @@
 			break;
 		}
 
-		if (addr != (void *)1) {
-			error = ptrace_set_pc(td2, (u_long)(uintfptr_t)addr);
-			if (error)
-				break;
+		if (req == PT_CONTINUE)
+		{
+			if (addr != (void *)1) {
+				error = ptrace_set_pc(td2, (u_long)(uintfptr_t)addr);
+				if (error)
+					break;
+			}
 		}
 
 		if (req == PT_DETACH) {


>Release-Note:
>Audit-Trail:

From: Gunnar Hinriksson <tomtinn@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/146167: ptrace PT_DETACH undocumented behavior
Date: Fri, 30 Apr 2010 03:24:28 +0000

 --0016e6d7858ae6a73b04856bc7e8
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 The patch I originally attached breaks functionality.
 The attached patch  is a more proper way to fix the bug.
 
 With Regards
 Gunnar
 
 --0016e6d7858ae6a73b04856bc7e8
 Content-Type: text/plain; charset=US-ASCII; name="patch.txt"
 Content-Disposition: attachment; filename="patch.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_g8mfw6g10
 
 LS0tIC91c3Ivc3JjL3N5cy9rZXJuL3N5c19wcm9jZXNzLmMJMjAxMC0wNC0zMCAwMjo1OTowOC45
 OTIxNTY1NDQgKzAwMDAKKysrIHN5c19wcm9jZXNzLmMJMjAxMC0wNC0zMCAwMjo1OTozOC4xNjYx
 MjY3MDAgKzAwMDAKQEAgLTc0MSwxMCArNzQxLDEzIEBACiAJCQlicmVhazsKIAkJfQogCi0JCWlm
 IChhZGRyICE9ICh2b2lkICopMSkgewotCQkJZXJyb3IgPSBwdHJhY2Vfc2V0X3BjKHRkMiwgKHVf
 bG9uZykodWludGZwdHJfdClhZGRyKTsKLQkJCWlmIChlcnJvcikKLQkJCQlicmVhazsKKwkJaWYg
 KHJlcSAhPSBQVF9ERVRBQ0gpCisJCXsKKwkJCWlmIChhZGRyICE9ICh2b2lkICopMSkgeworCQkJ
 CWVycm9yID0gcHRyYWNlX3NldF9wYyh0ZDIsICh1X2xvbmcpKHVpbnRmcHRyX3QpYWRkcik7CisJ
 CQkJaWYgKGVycm9yKQorCQkJCQlicmVhazsKKwkJCX0KIAkJfQogCiAJCWlmIChyZXEgPT0gUFRf
 REVUQUNIKSB7Cg==
 --0016e6d7858ae6a73b04856bc7e8--

From: John Baldwin <jhb@FreeBSD.org>
To: bug-followup@FreeBSD.org, tomtinn@gmail.com
Cc:  
Subject: Re: kern/146167: [ptrace] [patch] ptrace PT_DETACH undocumented behavior
Date: Tue, 11 May 2010 15:56:09 -0400

 Can you try the alternate patch I mailed to the mailing list?  I 
 actually changed things around so that only PT_CONTINUE honors addr and 
 uses the opportunity to cleanup the code a bit.
 
 -- 
 John Baldwin
State-Changed-From-To: open->feedback 
State-Changed-By: jhb 
State-Changed-When: Tue May 11 20:08:30 UTC 2010 
State-Changed-Why:  
Feedback requested. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=146167 
State-Changed-From-To: feedback->patched 
State-Changed-By: jhb 
State-Changed-When: Tue May 25 21:33:02 UTC 2010 
State-Changed-Why:  
Patch committed to HEAD. 


Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Tue May 25 21:33:02 UTC 2010 
Responsible-Changed-Why:  
Patch committed to HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=146167 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/146167: commit references a PR
Date: Tue, 25 May 2010 21:32:51 +0000 (UTC)

 Author: jhb
 Date: Tue May 25 21:32:37 2010
 New Revision: 208555
 URL: http://svn.freebsd.org/changeset/base/208555
 
 Log:
   Ignore the 'addr' argument passed to PT_STEP (it is required to be '1'
   for PT_STEP which means "ignore") and PT_DETACH.
   
   PR:		kern/146167
   MFC after:	1 week
 
 Modified:
   head/sys/kern/sys_process.c
 
 Modified: head/sys/kern/sys_process.c
 ==============================================================================
 --- head/sys/kern/sys_process.c	Tue May 25 21:20:56 2010	(r208554)
 +++ head/sys/kern/sys_process.c	Tue May 25 21:32:37 2010	(r208555)
 @@ -899,24 +899,29 @@ kern_ptrace(struct thread *td, int req, 
  			if (error)
  				goto out;
  			break;
 +		case PT_CONTINUE:
  		case PT_TO_SCE:
 -			p->p_stops |= S_PT_SCE;
 -			break;
  		case PT_TO_SCX:
 -			p->p_stops |= S_PT_SCX;
 -			break;
  		case PT_SYSCALL:
 -			p->p_stops |= S_PT_SCE | S_PT_SCX;
 -			break;
 -		}
 -
 -		if (addr != (void *)1) {
 -			error = ptrace_set_pc(td2, (u_long)(uintfptr_t)addr);
 -			if (error)
 +			if (addr != (void *)1) {
 +				error = ptrace_set_pc(td2,
 +				    (u_long)(uintfptr_t)addr);
 +				if (error)
 +					goto out;
 +			}
 +			switch (req) {
 +			case PT_TO_SCE:
 +				p->p_stops |= S_PT_SCE;
  				break;
 -		}
 -
 -		if (req == PT_DETACH) {
 +			case PT_TO_SCX:
 +				p->p_stops |= S_PT_SCX;
 +				break;
 +			case PT_SYSCALL:
 +				p->p_stops |= S_PT_SCE | S_PT_SCX;
 +				break;
 +			}
 +			break;
 +		case PT_DETACH:
  			/* reset process parent */
  			if (p->p_oppid != p->p_pptr->p_pid) {
  				struct proc *pp;
 @@ -941,6 +946,7 @@ kern_ptrace(struct thread *td, int req, 
  
  			/* should we send SIGCHLD? */
  			/* childproc_continued(p); */
 +			break;
  		}
  
  	sendsig:
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Mon Aug 9 20:10:42 UTC 2010 
State-Changed-Why:  
Fixed in 7.x and 8.1. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=146167 
>Unformatted:
