NetBSD Problem Report #8884

Received: (qmail 9584 invoked from network); 26 Nov 1999 18:20:59 -0000
Message-Id: <199911261820.SAA26506@tachyon.mono.org>
Date: Fri, 26 Nov 1999 18:20:55 GMT
From: norm@mono.org
Reply-To: norm@mono.org
To: gnats-bugs@gnats.netbsd.org
Subject: NFS caching error in 1.4.1
X-Send-Pr-Version: 3.95

>Number:         8884
>Category:       kern
>Synopsis:       Files aren't totally secure over NFS
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 26 10:24:01 +0000 1999
>Closed-Date:    Sun Dec 05 13:44:29 +0000 1999
>Last-Modified:  Sun Dec 05 13:45:07 +0000 1999
>Originator:     NoRM
>Release:        1.4.1
>Organization:
Monochrome BBS
>Environment:
NetBSD electron.mono.org 1.4.1 NetBSD 1.4.1 (MONO_CLIENT) #3: Fri Nov 12 20:40:09 GMT 1999 norm@lambda.mono.org:/files/src/sys/arch/sparc/compile/MONO_CLIENT sparc

>Description:
    When mounting an NFS filesystem under 1.4.1, it is sometimes possible
    to gain more information than should be possible  (looks cache related).

    For example:
    > amf@le> ls -ld /mono/u1/norm/help
    > ls: help: Permission denied

    (user with permission to access those files does so)

    > amf@le> ls -ld /mono/u1/norm/help
    > drwxr-x---  11 norm  mono  512 Nov 12 11:17 /mono/u1/norm/help/
    > amf@le> ls -ld /mono/u1/norm/help/help.mn
    > -rw-r-----  1 norm  mono  768 Feb  8  1999 /mono/u1/norm/help/help.mn

    The user amf in this case is not a member of group 'mono' so shouldn't
    be able to do that.  As was shown earlier.


>How-To-Repeat:
    Export a filesystem (mine is from a 1.3.2 box).  Do the following as 
    user1:

	% mkdir test
	% cd test
	% mkdir bob
	% chmod 700 . bob
	% echo ok > bob/jim
	% chmod 444 bob/jim

    Mount this on a 1.4.1 client machine, and do the following:

	# mount server:/filesystem /mnt
	# su user2
	% cd /mnt ; ls -la test/bob/jim
	ls: test/bob/jim: Permission denied
	% cat test/bob/jim
	cat: test/bob/jim: Permission denied
	% exit
	# su user1 
	% cd /mnt ; cat test/bob/jim
	ok
	% exit
	# su user2
	% cat test/bob/jim
	ok

>Fix:
    I, personally speaking, have no idea!  :)
>Release-Note:
>Audit-Trail:

From: Frank van der Linden <frank@wins.uva.nl>
To: norm@mono.org
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/8884: NFS caching error in 1.4.1
Date: Tue, 30 Nov 1999 00:42:53 +0100

 I've checked in a fix for this in -current. To be sure, can you verify
 that this patch works for you?

 - Frank

 Index: nfs_node.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/nfs/nfs_node.c,v
 retrieving revision 1.29
 diff -c -r1.29 nfs_node.c
 *** nfs_node.c	1999/07/08 01:06:03	1.29
 --- nfs_node.c	1999/11/29 23:30:57
 ***************
 *** 160,165 ****
 --- 160,166 ----
   		np->n_fhp = &np->n_fh;
   	memcpy((caddr_t)np->n_fhp, (caddr_t)fhp, fhsize);
   	np->n_fhsize = fhsize;
 + 	np->n_accstamp = -1;
   	np->n_vattr = pool_get(&nfs_vattr_pool, PR_WAITOK);
   	memset(np->n_vattr, 0, sizeof (struct vattr));
   	lockmgr(&nfs_hashlock, LK_RELEASE, 0);
 Index: nfs_vnops.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/nfs/nfs_vnops.c,v
 retrieving revision 1.107
 diff -c -r1.107 nfs_vnops.c
 *** nfs_vnops.c	1999/11/15 18:49:12	1.107
 --- nfs_vnops.c	1999/11/29 23:31:00
 ***************
 *** 301,310 ****
   	register caddr_t cp;
   	register int32_t t1, t2;
   	caddr_t bpos, dpos, cp2;
 ! 	int error = 0, attrflag;
   	struct mbuf *mreq, *mrep, *md, *mb, *mb2;
   	u_int32_t mode, rmode;
   	int v3 = NFS_ISV3(vp);

   	/*
   	 * For nfs v3, do an access rpc, otherwise you are stuck emulating
 --- 301,322 ----
   	register caddr_t cp;
   	register int32_t t1, t2;
   	caddr_t bpos, dpos, cp2;
 ! 	int error = 0, attrflag, cachevalid;
   	struct mbuf *mreq, *mrep, *md, *mb, *mb2;
   	u_int32_t mode, rmode;
   	int v3 = NFS_ISV3(vp);
 + 	struct nfsnode *np = VTONFS(vp);
 + 
 + 	cachevalid = (np->n_accstamp != -1 &&
 + 	    (time.tv_sec - np->n_accstamp) < NFS_ATTRTIMEO(np) &&
 + 	    np->n_accuid == ap->a_cred->cr_uid);
 + 
 + 	/*
 + 	 * Check access cache first. If this request has been made for this
 + 	 * uid shortly before, use the cached result.
 + 	 */
 + 	if (cachevalid && ((np->n_accmode & ap->a_mode) == ap->a_mode))
 + 		return np->n_accerror;

   	/*
   	 * For nfs v3, do an access rpc, otherwise you are stuck emulating
 ***************
 *** 350,357 ****
   				error = EACCES;
   		}
   		nfsm_reqdone;
 - 		if (error)
 - 			return (error);
   	} else
   		return (nfsspec_access(ap));
   	/*
 --- 362,367 ----
 ***************
 *** 359,375 ****
   	 * unless the file is a socket, fifo, or a block or character
   	 * device resident on the filesystem.
   	 */
 ! 	if ((ap->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
   		switch (vp->v_type) {
   		case VREG:
   		case VDIR:
   		case VLNK:
 ! 			return (EROFS);
   		default:
   			break;
   		}
   	}
 ! 	return (0);
   }

   /*
 --- 369,403 ----
   	 * unless the file is a socket, fifo, or a block or character
   	 * device resident on the filesystem.
   	 */
 ! 	if (!error && (ap->a_mode & VWRITE) &&
 ! 	    (vp->v_mount->mnt_flag & MNT_RDONLY)) {
   		switch (vp->v_type) {
   		case VREG:
   		case VDIR:
   		case VLNK:
 ! 			error = EROFS;
   		default:
   			break;
   		}
   	}
 ! 
 ! 	if (!error || error == EACCES) {
 ! 		/*
 ! 		 * If we got the same result as for a previous,
 ! 		 * different request, OR it in. Don't update
 ! 		 * the timestamp in that case.
 ! 		 */
 ! 		if (cachevalid && error == np->n_accerror)
 ! 			np->n_accmode |= ap->a_mode;
 ! 		else {
 ! 			np->n_accstamp = time.tv_sec;
 ! 			np->n_accuid = ap->a_cred->cr_uid;
 ! 			np->n_accmode = ap->a_mode;
 ! 			np->n_accerror = error;
 ! 		}
 ! 	}
 ! 
 ! 	return (error);
   }

   /*
 ***************
 *** 748,753 ****
 --- 776,782 ----
   		return (EROFS);
   	if (dvp->v_type != VDIR)
   		return (ENOTDIR);
 + 
   	lockparent = flags & LOCKPARENT;
   	wantparent = flags & (LOCKPARENT|WANTPARENT);
   	nmp = VFSTONFS(dvp->v_mount);
 ***************
 *** 764,769 ****
 --- 793,810 ----
   	 */
   	if ((error = cache_lookup(dvp, vpp, cnp)) >= 0) {
   		struct vattr vattr;
 + 		int err2;
 + 
 + 		if (error && error != ENOENT) {
 + 			*vpp = NULLVP;
 + 			return (error);
 + 		}
 + 
 + 		err2 = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, cnp->cn_proc);
 + 		if (err2) {
 + 			*vpp = NULLVP;
 + 			return (err2);
 + 		}

   		if (error == ENOENT) {
   			if (!VOP_GETATTR(dvp, &vattr, cnp->cn_cred,
 ***************
 *** 773,781 ****
   			cache_purge(dvp);
   			np->n_nctime = 0;
   			goto dorpc;
 ! 		}
 ! 		else if (error > 0)
   			return error;

   		newvp = *vpp;
   		if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred, cnp->cn_proc)
 --- 814,823 ----
   			cache_purge(dvp);
   			np->n_nctime = 0;
   			goto dorpc;
 ! 		} else if (error > 0) {
 ! 			*vpp = NULLVP;
   			return error;
 + 		}

   		newvp = *vpp;
   		if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred, cnp->cn_proc)
 Index: nfsnode.h
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/nfs/nfsnode.h,v
 retrieving revision 1.27
 diff -c -r1.27 nfsnode.h
 *** nfsnode.h	1998/08/10 08:11:13	1.27
 --- nfsnode.h	1999/11/29 23:31:00
 ***************
 *** 94,105 ****
    * There is a unique nfsnode allocated for each active file,
    * each current directory, each mounted-on file, text file, and the root.
    * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
 -  * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite
 -  * type definitions), file handles of > 32 bytes should probably be split out
 -  * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by
 -  * changing the definition in nfsproto.h of NFS_SMALLFH.)
 -  * NB: Hopefully the current order of the fields is such that everything will
 -  *     be well aligned and, therefore, tightly packed.
    */
   struct nfsnode {
   	u_quad_t		n_size;		/* Current size of file */
 --- 94,99 ----
 ***************
 *** 136,141 ****
 --- 130,139 ----
   	short			n_fhsize;	/* size in bytes, of fh */
   	short			n_flag;		/* Flag for locking.. */
   	nfsfh_t			n_fh;		/* Small File Handle */
 + 	time_t			n_accstamp;	/* Access cache timestamp */
 + 	uid_t			n_accuid;	/* Last access requester */
 + 	int			n_accmode;	/* Mode last requested */
 + 	int			n_accerror;	/* Error last returned */
   };

   #define n_atim		n_un1.nf_atim
State-Changed-From-To: open->closed 
State-Changed-By: fvdl 
State-Changed-When: Sun Dec 5 05:44:29 PST 1999 
State-Changed-Why:  
Fixed by inserting an extra VOP_ACCESS call into nfs_lookup. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.