Subject: procfs_readdir partially broken with linux compat flag
To: NetBSD current <current-users@NetBSD.org>
From: Nicolas Joly <njoly@pasteur.fr>
List: current-users
Date: 12/04/2006 18:00:52
--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


Hi,

I, and some others, recently noticed that procfs with compat linux
flag enabled do not show linux specific files anymore during root
directory listing.

njoly@lanfeust [~]> mount -vv | grep proc
procfs on /usr/pkg/emul/linux/proc type procfs (local, fsid: 0x1b02/0x1ae1b, reads: sync 0 async 0, writes: sync 0 async 0, [procfs: version=1, flags=0x1<linuxcompat>])

njoly@lanfeust [~]> ls -l /usr/pkg/emul/linux/proc | grep cpuinfo
njoly@lanfeust [~]> ls -l /usr/pkg/emul/linux/proc/cpuinfo
-r--r--r--  1 root  wheel  0 Dec  4 17:08 /usr/pkg/emul/linux/proc/cpuinfo

I tracked it to the `procfs_readdir()', which is calling
`procfs_validfile_linux()' to check if the filesystem has the linux
mount option and this file is valid.

In revision 1.136 of procfs_vnops.c, procfs_validfile() was fixed
apparently to avoid NULL pointer dereference ... And some checks, to
check for NULL lwp/proc were removed from procfs_validfile_linux() at
the same time.

Unfortunately, procfs_readdir() calls procfs_validfile_linux() with
its first argument being NULL (== lwp), which always results in
procfs_validfile() returning 0 ... and skipping all linux specific
files in root directory listings !

For now, i restored the expected behaviour by checking for NULL lwp
and proc again ...

Hope this helps,
Regards.

-- 
Nicolas Joly

Biological Software and Databanks.
Institut Pasteur, Paris.

--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="netbsd-procfslinux.diff"

Index: sys/miscfs/procfs/procfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_vnops.c,v
retrieving revision 1.141
diff -u -r1.141 procfs_vnops.c
--- sys/miscfs/procfs/procfs_vnops.c	3 Dec 2006 13:24:10 -0000	1.141
+++ sys/miscfs/procfs/procfs_vnops.c	4 Dec 2006 16:38:24 -0000
@@ -1090,7 +1090,8 @@
 	int flags;
 
 	flags = VFSTOPROC(mp)->pmnt_flags;
-	return (flags & PROCFSMNT_LINUXCOMPAT) && procfs_validfile(l, mp);
+	return (flags & PROCFSMNT_LINUXCOMPAT) &&
+	    (l == NULL || l->l_proc == NULL || procfs_validfile(l, mp));
 }
 
 struct procfs_root_readdir_ctx {

--azLHFNyN32YCQGCU--