PERFORCE change 163674 for review
Robert Watson
rwatson at FreeBSD.org
Sat Jun 6 22:41:44 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163674
Change 163674 by rwatson at rwatson_freebsd_capabilities on 2009/06/06 22:40:45
Complete merge of new file descriptor referencing and locking
into the capabilities version of _fget(). Improve ifdefing.
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/sys/kern/kern_descrip.c#23 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/sys/kern/kern_descrip.c#23 (text+ko) ====
@@ -2155,7 +2155,10 @@
{
struct filedesc *fdp;
struct file *fp;
+#ifdef CAPABILITIES
+ struct file *fp_fromcap;
int error;
+#endif
/*
* Validate the file descriptor number and find the struct file.
@@ -2170,6 +2173,7 @@
return (EBADF);
}
+#ifdef CAPABILITIES
/*
* If a capability has been requested, return the capability
* directly. Otherwise, check capability rights, extract the
@@ -2177,30 +2181,40 @@
*/
if (fget_flags & FGET_GETCAP) {
if (fp->f_type != DTYPE_CAPABILITY) {
- FILEDESC_SUNLOCK(fdp);
+ fdrop(fp, td);
return (EINVAL);
}
} else {
/*
* If a capability hasn't been requested, then validate the
- * capability and find the underlying object. From now on
- * 'fp' refers to the actual object of interest.
+ * capability and find the underlying object.
*/
if (maxprotp != NULL)
- error = cap_fextract_mmap(fp, rights, maxprotp, &fp);
+ error = cap_fextract_mmap(fp, rights, maxprotp,
+ &fp_fromcap);
else
- error = cap_fextract(fp, rights, &fp);
+ error = cap_fextract(fp, rights, &fp_fromcap);
if (error) {
- FILEDESC_SUNLOCK(fdp);
+ fdrop(fp, td);
return (error);
}
+ /*
+ * Hold the new file descriptor and drop the capability file
+ * descriptor; after this point fp refers to the new object.
+ */
+ fhold(fp_fromcap);
+ fdrop(fp, td);
+ fp = fp_fromcap;
+#endif
if ((flags == FREAD && (fp->f_flag & FREAD) == 0) ||
(flags == FWRITE && (fp->f_flag & FWRITE) == 0)) {
fdrop(fp, td);
return (EBADF);
}
+#ifdef CAPABILITIES
}
+#endif
*fpp = fp;
return (0);
}
@@ -2224,7 +2238,7 @@
fget_read(struct thread *td, int fd, cap_rights_t rights, struct file **fpp)
{
- return(_fget(td, fd, fpp, FWRITE, rights, NULL, 0));
+ return(_fget(td, fd, fpp, FREAD, rights, NULL, 0));
}
int
More information about the p4-projects
mailing list