Subject: please test linux programs with latest procfs
To: None <current-users@netbsd.org, port-i386@netbsd.org>
From: Antti Kantee <pooka@cs.hut.fi>
List: current-users
Date: 07/22/2007 16:40:18
--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Hi,

I committed a workaround to kern/36669 which loses some information
in procfs.  While this shouldn't affect any valid use of procfs, you
can never be too sure.  Please test linux programs and procfs_vnops.c
revision 1.158.

If you run netbsd-4, it is even more important that you test.  Please
apply the attached patch.

In case there are no complaints, this patch is going into the (hopefully
imminent) NetBSD 4.0 release to workaround a "any user can panic the
system" situation.

thanks,
  antti

-- 
Antti Kantee <pooka@iki.fi>                     Of course he runs NetBSD
http://www.iki.fi/pooka/                          http://www.NetBSD.org/
    "la qualité la plus indispensable du cuisinier est l'exactitude"

--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=procfs_patch-netbsd-4

Index: procfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_vnops.c,v
retrieving revision 1.140.2.5
diff -p -u -r1.140.2.5 procfs_vnops.c
--- procfs_vnops.c	31 Mar 2007 16:13:18 -0000	1.140.2.5
+++ procfs_vnops.c	22 Jul 2007 11:53:08 -0000
@@ -537,6 +537,18 @@ procfs_dir(pfstype t, struct lwp *caller
 		return (NULL);
 	}
 
+	/*
+	 * XXX: this horrible kludge avoids locking panics when
+	 * attempting to lookup links that point to within procfs
+	 */
+	if (vp != NULL && vp->v_tag == VT_PROCFS) {
+		if (bpp) {
+			*--bp = '/';
+			*bpp = bp;
+		}
+		return vp;
+	}
+
 	if (rvp == NULL)
 		rvp = rootvnode;
 	if (vp == NULL || getcwd_common(vp, rvp, bp ? &bp : NULL, path,
@@ -1451,11 +1463,20 @@ procfs_readlink(v)
 			}
 			bp = path + MAXPATHLEN;
 			*--bp = '\0';
-			vp = curproc->p_cwdi->cwdi_rdir;
-			if (vp == NULL)
-				vp = rootvnode;
-			error = getcwd_common(vxp, vp, &bp, path,
-			    MAXPATHLEN / 2, 0, curlwp);
+
+ 			/*
+ 			 * XXX: kludge to avoid locking against ourselves
+ 			 * in getcwd()
+ 			 */
+ 			if (vxp->v_tag == VT_PROCFS) {
+ 				*--bp = '/';
+ 			} else {
+ 				vp = curproc->p_cwdi->cwdi_rdir; /* XXXSMP */
+ 				if (vp == NULL)
+ 					vp = rootvnode;
+ 				error = getcwd_common(vxp, vp, &bp, path,
+ 				    MAXPATHLEN / 2, 0, curlwp);
+ 			}
 			FILE_UNUSE(fp, proc_representative_lwp(pown));
 			if (error) {
 				free(path, M_TEMP);

--Nq2Wo0NMKNjxTN9z--