From johans@stack.nl  Wed Dec  7 10:57:15 2005
Return-Path: <johans@stack.nl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id EBFA916A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  7 Dec 2005 10:57:15 +0000 (GMT)
	(envelope-from johans@stack.nl)
Received: from mx1.stack.nl (meestal.stack.nl [131.155.140.141])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 7F80443D5C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  7 Dec 2005 10:57:14 +0000 (GMT)
	(envelope-from johans@stack.nl)
Received: by mx1.stack.nl (Postfix, from userid 65534)
	id B64284AEB7; Wed,  7 Dec 2005 11:56:26 +0100 (CET)
Received: from mud.stack.nl (mud.stack.nl [IPv6:2001:610:1108:5011:207:e9ff:fe14:b498])
	by mx1.stack.nl (Postfix) with ESMTP id 35AD94AEA9
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  7 Dec 2005 11:56:26 +0100 (CET)
Received: by mud.stack.nl (Postfix, from userid 801)
	id 3A44417035; Wed,  7 Dec 2005 11:57:17 +0100 (CET)
Message-Id: <20051207105717.3A44417035@mud.stack.nl>
Date: Wed,  7 Dec 2005 11:57:17 +0100 (CET)
From: Johan van Selst <johans@stack.nl>
Reply-To: Johan van Selst <johans@stack.nl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: procfs: access("/proc/123", F_OK) doesn't work on >= 6.x
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         90063
>Category:       kern
>Synopsis:       [procfs] access("/proc/123", F_OK) doesn't work on >= 6.x
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 07 11:00:11 GMT 2005
>Closed-Date:    Fri Oct 12 19:39:01 UTC 2007
>Last-Modified:  Fri Oct 12 19:39:01 UTC 2007
>Originator:     Johan van Selst
>Release:        FreeBSD 6.0-STABLE i386
>Organization:
>Environment:
System: FreeBSD mud.stack.nl 6.0-STABLE FreeBSD 6.0-STABLE #8: Mon Dec 5 13:04:53 CET 2005 johans@mud.stack.nl:/usr/obj/usr/src/sys/mud i386


	
>Description:
	
A quick and dirty check for a running pid does
	if (access("/proc/123", F_OK))

However on a -CURRENT system, this will always return OK status (0) -
regardless of whether the directory/process is present or not. Only when
checking for permissions (R_OK, X_OK) a real check seems to be performed.
This is not compatible with the behaviour on FreeBSD 5.x and older.

>How-To-Repeat:
	

Compare the result of this code on a 5.x and 6.x system for any
non-existing /proc/1234 entry

        if (access(argv[1], F_OK) < 0)
                return EX_UNAVAILABLE;

        if (access(argv[1], X_OK) < 0)
                return EX_NOPERM;

        return EX_OK;

>Fix:
>Release-Note:
>Audit-Trail:
Adding to audit trail from misfiled PR kern/104871:

Date: Fri, 27 Oct 2006 16:53:37 -0700
From: John <john@8192.net>
 
 Greetings,
 
 I've attached a one-line patch for src/sys/fs/pseudofs/pseudofs_vnops.c 
 to fix the issue outlined in kern/90063. The issue stemmed from pseudofs 
 passing an incorrect PID to pfs_visible inside pfs_lookup. When pseudofs 
 would go to look up a process dependent node, it would correctly parse 
 the PID from the path but then fail to pass that PID on to pfs_visible, 
 instead passing a PID which was always visible and thus always returned 
 successfully. This resulted in F_OK always returning successfully as 
 long as the path looked like it contained a valid PID (eg, any positive 
 integer). The reason X_OK failed correctly was due to pfs_access 
 (through pfs_getattr) passing the correct PID to pfs_visible.
 
 The issue likely also affected linprocfs, as it uses the same facilities 
 inside of pseudofs. This patch was tested on 6.2-PRE and should apply 
 cleanly to anything >= 6.1, but if you'd like I can provide a patch for 
 6.0 as well.
 
 Thanks,
 John
 
 
 
 --------------000701010706070907050402
 Content-Type: text/plain;
  name="pseudofs_vnops.c.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="pseudofs_vnops.c.patch"
 
 --- pseudofs_vnops.c    Fri Oct 27 00:35:25 2006
 +++ pseudofs_vnops.c    Fri Oct 27 00:06:04 2006
 @@ -408,7 +408,7 @@
   got_pnode:
         if (pn != pd->pn_parent && !pn->pn_parent)
                 pn->pn_parent = pd;
 -       if (!pfs_visible(curthread, pn, pvd->pvd_pid, NULL)) {
 +       if (!pfs_visible(curthread, pn, pid, NULL)) {
                 error = ENOENT;
                 goto failed;
         }
 
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Fri Oct 5 17:37:33 UTC 2007 
State-Changed-Why:  
Fix applied to HEAD and will be MFC'd to 6.x in a week or so. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/90063: commit references a PR
Date: Fri,  5 Oct 2007 17:37:32 +0000 (UTC)

 jhb         2007-10-05 17:37:25 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/fs/pseudofs      pseudofs_vnops.c 
   Log:
   Use the correct pid when checking to see whether or not the /proc/<pid>
   directory itself (rather than any of its contents) is visible to the
   current thread.
   
   MFC after:      1 week
   PR:             kern/90063
   Submitted by:   john of 8192.net
   Approved by:    re (kensmith)
   
   Revision  Changes    Path
   1.65      +1 -1      src/sys/fs/pseudofs/pseudofs_vnops.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Fri Oct 12 19:38:47 UTC 2007 
State-Changed-Why:  
Fix merged to 6.x.  Thanks! 

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