From sanewo@ba2.so-net.ne.jp  Sat Aug 18 03:57:38 2001
Return-Path: <sanewo@ba2.so-net.ne.jp>
Received: from mgate05.so-net.ne.jp (mgate05.so-net.ne.jp [210.139.254.152])
	by hub.freebsd.org (Postfix) with ESMTP id C0F0437B410
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Aug 2001 03:57:37 -0700 (PDT)
	(envelope-from sanewo@ba2.so-net.ne.jp)
Received: from mail.ba2.so-net.ne.jp (mspool12.so-net.ne.jp [210.139.248.12])
	by mgate05.so-net.ne.jp (8.8.8+3.0Wbeta9/3.6W01060506) with ESMTP id TAA14987
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Aug 2001 19:57:36 +0900 (JST)
Received: from ba2.so-net.ne.jp (pd301e9.tkyoea00.ap.so-net.ne.jp [61.211.1.233])
	by mail.ba2.so-net.ne.jp  with ESMTP id f7IAvZV17400
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 18 Aug 2001 19:57:35 +0900 (JST)
Received: (from sanewo@localhost)
	by ba2.so-net.ne.jp (8.11.5/8.11.5) id f7IAvYU79589;
	Sat, 18 Aug 2001 19:57:34 +0900 (JST)
	(envelope-from sanewo)
Message-Id: <200108181057.f7IAvYU79589@ba2.so-net.ne.jp>
Date: Sat, 18 Aug 2001 19:57:34 +0900 (JST)
From: Takanori Saneto <sanewo@ba2.so-net.ne.jp>
To: FreeBSD-gnats-submit@freebsd.org
Subject: setpgrp does not behave as manual says
X-Send-Pr-Version: 3.113

>Number:         29844
>Category:       kern
>Synopsis:       [PATCH] setpgrp does not behave as manual says
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    das
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 18 04:00:02 PDT 2001
>Closed-Date:    Sun Feb 08 04:40:04 PST 2004
>Last-Modified:  Wed Aug 25 16:30:32 GMT 2004
>Originator:     Takanori Saneto
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD muse.sanewo 5.0-CURRENT FreeBSD 5.0-CURRENT #8: Sat Aug 18 13:15:18 JST 2001 root@:/export/usr.obj/usr/src/sys/MUSE i386

Confirmed on 5.0-CURRENT as of today and 4.3-STABLE as of Jul 29 2001.

By checking the source, I believe that this bug was in 4.4BSD-Lite as well.

>Description:

As superuser, setpgrp(1,1) fails (errno=ESRCH).

setpgrp(2) says:

	If the invoker is not the super-user, then the affected
	process must have the same effective user-id as the invoker or
	be a descendant of the invoking process.

Actually, document says nothing about what should happen when the invoker is
the super-user. So it might not be a software bug, but a poor documentation...

>How-To-Repeat:

Compile following program:

main() { if (setpgrp(1,1) < 0) perror("setpgrp"); }

and run it as root.

>Fix:

1. Fix the document

--- setpgid.2.orig	Sat Aug 18 19:53:12 2001
+++ setpgid.2	Sat Aug 18 19:53:34 2001
@@ -57,7 +57,7 @@
 .Fa pid
 is zero, then the call applies to the current process.
 .Pp
-If the invoker is not the super-user, then the affected process
+Affected process
 must have the same effective user-id as the invoker or be a descendant
 of the invoking process.
 .Sh RETURN VALUES

Or

2. Fix the kernel source

--- kern_prot.c.orig	Sat Aug 18 19:54:23 2001
+++ kern_prot.c	Sat Aug 18 19:54:57 2001
@@ -368,7 +368,7 @@
 	if (uap->pgid < 0)
 		return (EINVAL);
 	if (uap->pid != 0 && uap->pid != curp->p_pid) {
-		if ((targp = pfind(uap->pid)) == NULL || !inferior(targp)) {
+		if ((targp = pfind(uap->pid)) == NULL || (!suser(curp) && !inferior(targp))) {
 			if (targp)
 				PROC_UNLOCK(targp);
 			return (ESRCH);
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->standards 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Fri Sep 20 10:37:13 PDT 2002 
Responsible-Changed-Why:  
Can the standards people please have a look at this and decide 
which of the patches is the way to go? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29844 
Responsible-Changed-From-To: standards->das 
Responsible-Changed-By: das 
Responsible-Changed-When: Sun Feb 8 04:04:48 PST 2004 
Responsible-Changed-Why:  
I'll take a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29844 
State-Changed-From-To: open->closed 
State-Changed-By: das 
State-Changed-When: Sun Feb 8 04:39:41 PST 2004 
State-Changed-Why:  
The documentation was outdated.  Fixed in 
src/lib/libc/sys/setpgid.2,v 1.14.  Thanks for the report! 

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

From: dada@sbox.tugraz.at
To: FreeBSD problem reports <freebsd-gnats-submit@freebsd.org>
Cc: das@freebsd.org
Subject: Re: kern/29844: [PATCH] setpgrp does not behave as manual says
Date: Wed, 25 Aug 2004 18:29:38 +0200

 This PR is closed. However the fix still needs to be MFC.
 
>Unformatted:
