Subject: mount_null: /mnt (/mnt) and /mnt are not distinct paths
To: None <tech-kern@netbsd.org>
From: Konrad Schroder <perseant@hitl.washington.edu>
List: tech-kern
Date: 06/29/1999 12:02:37
Is there any reason why the various layered filesystems shouldn't be
allowed to mount in-place?  The only current problem seems to be that
lookup() holds the lock on the underlying directory when traversing a
mount point, which it doesn't need to AFAICT ... for reference, the
enclosed patches seem to work for me, for my very limited testing, so I
can
	mount -t null /tmp /tmp

and it does what I expect.

(With this patch as written, one can even "mount -t null /mnt/foo /mnt"
and hide a bunch of files.  This may or may not be desirable; but if not,
shouldn't the check be made in nullfs_mount(9), rather than in
mount_null(8)?)

------------------------------------------------------------------------
Konrad Schroder          http://www.hitl.washington.edu/people/perseant/
System Administrator                        perseant@hitl.washington.edu
Human Interface Technology Lab                    Voice: +1.206.616.1478
Box 352142, University of Washington, 98195, USA    FAX: +1.206.543.5380



Index: sys/kern/vfs_lookup.c
===================================================================
RCS file: /cvsroot/syssrc/sys/kern/vfs_lookup.c,v
retrieving revision 1.30
diff -u -r1.30 vfs_lookup.c
--- vfs_lookup.c	1999/04/30 18:43:00	1.30
+++ vfs_lookup.c	1999/06/29 17:45:50
@@ -505,11 +505,14 @@
 	       (cnp->cn_flags & NOCROSSMOUNT) == 0) {
 		if (vfs_busy(mp, 0, 0))
 			continue;
+		VOP_UNLOCK(dp,0);
 		error = VFS_ROOT(mp, &tdp);
 		vfs_unbusy(mp);
-		if (error)
+		if (error) {
+			VOP_LOCK(dp,0); /* XXX KS - this is stupid */
 			goto bad2;
-		vput(dp);
+		}
+		vrele(dp);
 		ndp->ni_vp = dp = tdp;
 	}
 
Index: sbin/mount_null/mount_null.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_null/mount_null.c,v
retrieving revision 1.6
diff -u -r1.6 mount_null.c
--- mount_null.c	1999/06/25 19:28:37	1.6
+++ mount_null.c	1999/06/29 18:20:17
@@ -99,10 +99,6 @@
 	if (realpath(argv[0], target) == 0)
 		err(1, "%s", target);
 
-	if (subdir(target, argv[1]) || subdir(argv[1], target))
-		errx(1, "%s (%s) and %s are not distinct paths",
-		    argv[0], target, argv[1]);
-
 	args.target = target;
 
 	if (mount(MOUNT_NULL, argv[1], mntflags, &args))