Skip site navigation (1)Skip section navigation (2)
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:   kern/29844: setpgrp does not behave as manual says
Message-ID:  <200108181057.f7IAvYU79589@ba2.so-net.ne.jp>

index | next in thread | raw e-mail


>Number:         29844
>Category:       kern
>Synopsis:       setpgrp does not behave as manual says
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 18 04:00:02 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108181057.f7IAvYU79589>