Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jan 2010 16:10:02 GMT
From:      Jonathan Anderson <jona@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 173670 for review
Message-ID:  <201001251610.o0PGA2VN072204@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=173670

Change 173670 by jona@jona-belle-freebsd8 on 2010/01/25 16:09:42

	Fixed dupfdopen() error in kern_openat() - we must finstall() the file to give it a valid descriptor before dupfdopen() is called

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/sys/kern/vfs_syscalls.c#26 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/sys/kern/vfs_syscalls.c#26 (text+ko) ====

@@ -74,6 +74,9 @@
 #ifdef KTRACE
 #include <sys/ktrace.h>
 #endif
+#ifdef KDB
+#include <sys/kdb.h>
+#endif
 
 #include <machine/stdarg.h>
 
@@ -1097,7 +1100,7 @@
 	struct mount *mp;
 	int cmode;
 	struct file *nfp;
-	int type, indx, error;
+	int type, indx = -1, error;
 	struct flock lf;
 	struct nameidata nd;
 	int vfslocked;
@@ -1159,10 +1162,17 @@
 		 * it ever should.
 		 */
 		if (!nd.ni_basedir && (error == ENODEV || error == ENXIO) &&
-		    td->td_dupfd >= 0 &&		/* XXX from fdopen */
-		    (error =
-			dupfdopen(td, fdp, indx, td->td_dupfd, flags, error)) == 0)
-			goto success;
+		    td->td_dupfd >= 0) {
+			/* XXX from fdopen */
+			int olderror = error;
+
+			if ((error = finstall(td, fp, &indx)) != 0)
+				goto bad_unlocked;
+
+			if ((error = dupfdopen(td, fdp, indx, td->td_dupfd,
+			                      flags, olderror)) == 0)
+				goto success;
+		}
 
 		/*
 		 * Clean up the descriptor, but only if another thread hadn't
@@ -1238,8 +1248,10 @@
 	}
 	else
 #endif
-	if ((error = finstall(td, fp, &indx)) != 0)
-		goto bad_unlocked;
+	/* if we haven't already installed the FD (for dupfdopen), do so now */
+	if (indx == -1)
+	       if((error = finstall(td, fp, &indx)) != 0)
+			goto bad_unlocked;
 
 	/*
 	 * Release our private reference, leaving the one associated with



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001251610.o0PGA2VN072204>