]> granicus.if.org Git - zfs/commitdiff
Fixed invalid resource re-use in file_find()
authorGunnar Beutner <gunnar@beutner.name>
Tue, 11 Oct 2011 16:50:52 +0000 (09:50 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 11 Oct 2011 16:51:51 +0000 (09:51 -0700)
File descriptors are a per-process resource. The same descriptor
in different processes can refer to different files. find_file()
incorrectly assumed that file descriptors are globally unique.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes ZFS issue #386

include/sys/vnode.h
module/spl/spl-vnode.c

index 7d655e5ef79a2826b91d5af8a6af737d844a790c..36605ca4a56287830838769ae3a2c3cf9dd939da 100644 (file)
@@ -158,6 +158,7 @@ typedef struct vnode {
 
 typedef struct vn_file {
        int             f_fd;           /* linux fd for lookup */
+       struct task_struct *f_task;     /* linux task this fd belongs to */
        struct file     *f_file;        /* linux file struct */
        atomic_t        f_ref;          /* ref count */
        kmutex_t        f_lock;         /* struct lock */
index c46643175a88644d01ac00bab3ab9d4750dd4120..1b5cc5a0824413cfb56a54bc81fa01586b1670d2 100644 (file)
@@ -511,7 +511,7 @@ file_find(int fd)
        ASSERT(spin_is_locked(&vn_file_lock));
 
         list_for_each_entry(fp, &vn_file_list,  f_list) {
-               if (fd == fp->f_fd) {
+               if (fd == fp->f_fd && fp->f_task == current) {
                        ASSERT(atomic_read(&fp->f_ref) != 0);
                         return fp;
                }
@@ -550,6 +550,7 @@ vn_getf(int fd)
        mutex_enter(&fp->f_lock);
 
        fp->f_fd = fd;
+       fp->f_task = current;
        fp->f_offset = 0;
        atomic_inc(&fp->f_ref);