PERFORCE change 15388 for review

Robert Watson rwatson at freebsd.org
Thu Aug 1 16:45:29 GMT 2002


http://people.freebsd.org/~peter/p4db/chv.cgi?CH=15388

Change 15388 by rwatson at rwatson_paprika on 2002/08/01 09:45:20

	Alternate formulate of security checks in vn_open_cred() that
	does enforce appropriate protections at open-time for MAC
	despite O_CREAT being set or not.  As with other failures
	during the O_CREAT case, a dud file is left around to be
	cleaned up by the user.  Remove various comments about problems
	that this change should fix.

Affected files ...

.. //depot/projects/trustedbsd/mac/sys/kern/vfs_vnops.c#35 edit

Differences ...

==== //depot/projects/trustedbsd/mac/sys/kern/vfs_vnops.c#35 (text+ko) ====

@@ -196,32 +196,29 @@
 		error = EOPNOTSUPP;
 		goto bad;
 	}
+	mode = 0;
+	if (fmode & (VWRITE | O_TRUNC)) {
+		if (vp->v_type == VDIR) {
+			error = EISDIR;
+			goto bad;
+		}
+		mode |= VWRITE;
+	}
+	if (fmode & FREAD)
+		mode |= VREAD;
+	if (fmode & O_APPEND)
+		mode |= VAPPEND;
+#ifdef MAC
+	error = mac_check_vnode_open(cred, vp, mode);
+	if (error)
+		goto bad;
+#endif
 	if ((fmode & O_CREAT) == 0) {
-		mode = 0;
-		if (fmode & (FWRITE | O_TRUNC)) {
-			if (vp->v_type == VDIR) {
-				error = EISDIR;
-				goto bad;
-			}
+		if (mode & VWRITE) {
 			error = vn_writechk(vp);
 			if (error)
 				goto bad;
-			mode |= VWRITE;
 		}
-		if (fmode & FREAD)
-			mode |= VREAD;
-		if (fmode & O_APPEND)
-			mode |= VAPPEND;
-#ifdef MAC
-		/*
-		 * XXXMAC: Note that for newly created files, we never
-		 * perform an open check.  This is probably wrong, but if
-		 * we add it, the failure modes need to be right.
-		 */
-		error = mac_check_vnode_open(cred, vp, mode);
-		if (error)
-			goto bad;
-#endif /* MAC */
 		if (mode) {
 		        error = VOP_ACCESS(vp, mode, cred, td);
 			if (error)
@@ -232,11 +229,6 @@
 		vp->v_cachedfs = vap->va_fsid;
 		vp->v_cachedid = vap->va_fileid;
 	}
-#ifdef MAC
-	/*
-	 * XXXMAC: Open check should probably be here.
-	 */
-#endif
 	if ((error = VOP_OPEN(vp, fmode, cred, td)) != 0)
 		goto bad;
 	/*
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message



More information about the trustedbsd-cvs mailing list