aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2011-11-27 19:02:18 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2011-11-27 19:02:18 +0000
commit4f5fe897a72c64d41e927b173e76b3c846fe1203 (patch)
treef6d3d06866aec5a6ae71cf074cc3e097a3e41c63
parente72f35d9a35ae60a5738dd8c38ed2dff694161f0 (diff)
Notes
-rw-r--r--sys/kern/vfs_syscalls.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index ec5ad06115cd..076c75d08ab5 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -4342,7 +4342,20 @@ getvnode(struct filedesc *fdp, int fd, cap_rights_t rights,
fp = fp_fromcap;
}
#endif /* CAPABILITIES */
- if (fp->f_vnode == NULL) {
+
+ /*
+ * The file could be not of the vnode type, or it may be not
+ * yet fully initialized, in which case the f_vnode pointer
+ * may be set, but f_ops is still badfileops. E.g.,
+ * devfs_open() transiently create such situation to
+ * facilitate csw d_fdopen().
+ *
+ * Dupfdopen() handling in kern_openat() installs the
+ * half-baked file into the process descriptor table, allowing
+ * other thread to dereference it. Guard against the race by
+ * checking f_ops.
+ */
+ if (fp->f_vnode == NULL || fp->f_ops == &badfileops) {
fdrop(fp, curthread);
return (EINVAL);
}