Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jan 2010 19:44:37 +0000 (UTC)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r203236 - projects/capabilities8/sys/kern
Message-ID:  <201001301944.o0UJibZ8089713@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rwatson
Date: Sat Jan 30 19:44:36 2010
New Revision: 203236
URL: http://svn.freebsd.org/changeset/base/203236

Log:
  Merge c173670 from the p4 TrustedBSD Capabilities branch to capabilities8:
  
    Fixed dupfdopen() error in kern_openat() - we must finstall() the file to
    give it a valid descriptor before dupfdopen() is called.
  
  Submitted by:	Jonathan Anderson <jonathan.anderson at cl.cam.ac.uk>

Modified:
  projects/capabilities8/sys/kern/vfs_syscalls.c

Modified: projects/capabilities8/sys/kern/vfs_syscalls.c
==============================================================================
--- projects/capabilities8/sys/kern/vfs_syscalls.c	Sat Jan 30 19:43:27 2010	(r203235)
+++ projects/capabilities8/sys/kern/vfs_syscalls.c	Sat Jan 30 19:44:36 2010	(r203236)
@@ -74,6 +74,9 @@ __FBSDID("$FreeBSD$");
 #ifdef KTRACE
 #include <sys/ktrace.h>
 #endif
+#ifdef KDB
+#include <sys/kdb.h>
+#endif
 
 #include <machine/stdarg.h>
 
@@ -1097,7 +1100,7 @@ kern_openat(struct thread *td, int fd, c
 	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 @@ kern_openat(struct thread *td, int fd, c
 		 * 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 @@ success:
 	}
 	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?201001301944.o0UJibZ8089713>