Subject: kern/32692: Linux compatibility broken in procfs despite -o linux (/proc/self)
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <mm_lists@pulsar-zone.net>
List: netbsd-bugs
Date: 02/01/2006 21:40:00
>Number:         32692
>Category:       kern
>Synopsis:       Linux compatibility broken in procfs despite -o linux (/proc/self)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 01 21:40:00 +0000 2006
>Originator:     Matthew Mondor
>Release:        3.0_STABLE
>Organization:
>Environment:
NetBSD hal.xisop 3.0 NetBSD 3.0 (GENERIC) #0: Wed Jan  4 18:57:53 EST 2006  root@hal.xisop:/usr/src/sys/arch/i386/compile/GENERIC i386
>Description:
On Linux, /proc/self consists of a symbolic link to the directory/PID
of the current process.  Our /proc/self however currently is a symbolic
link to curproc, which is the NetBSD equivalent (which behaves the same
as on Linux).

Linux programs using readlink(2) or lstat(2) on /proc/self to obtain
the current process's PID/directory fail, because instead of obtaining
the PID link, they obtain 'curproc'.  And some programs do this.

Thanks to Kailash Sethuraman for reporting this compatibility bug.
>How-To-Repeat:
 --- (ttyp1) mmondor@sat.xisop $ readlink /proc/self
curproc
 --- (ttyp1) mmondor@sat.xisop $ readlink /proc/curproc
5716

>Fix:
Probably that the following diff fixes it (untested):

Index: sys/miscfs/procfs/procfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_vnops.c,v
retrieving revision 1.121
diff -u -p -r1.121 procfs_vnops.c
--- sys/miscfs/procfs/procfs_vnops.c    26 Feb 2005 22:59:00 -0000      1.121
+++ sys/miscfs/procfs/procfs_vnops.c    1 Feb 2006 21:18:43 -0000
@@ -610,7 +610,10 @@ procfs_getattr(v)
                vap->va_bytes = vap->va_size = DEV_BSIZE;
                break;
 
-       case PFScurproc: {
+       case PFScurproc:
+               /* FALLTHROUGH */
+       case PFSself:
+       {
                char buf[16];           /* should be enough */
                vap->va_nlink = 1;
                vap->va_uid = 0;
@@ -620,13 +623,6 @@ procfs_getattr(v)
                break;
        }
 
-       case PFSself:
-               vap->va_nlink = 1;
-               vap->va_uid = 0;
-               vap->va_gid = 0;
-               vap->va_bytes = vap->va_size = sizeof("curproc") - 1;
-               break;
-
        case PFSfd:
                if (pfs->pfs_fd != -1) {
                        struct file *fp;