Btrfs: check for read permission on src file in the clone ioctl
authorDan Rosenberg <dan.j.rosenberg@gmail.com>
Sat, 15 May 2010 15:27:37 +0000 (11:27 -0400)
committerChris Mason <chris.mason@oracle.com>
Sat, 15 May 2010 16:05:50 +0000 (12:05 -0400)
The existing code would have allowed you to clone a file that was
only open for writing

Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ioctl.c

index 2b7dd88fc54f22c63a4fe7cf1737d913f3bf3bad..9de6c3a75bfb66ab5850f0d824163d73dcec3785 100644 (file)
@@ -1480,12 +1480,17 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
                ret = -EBADF;
                goto out_drop_write;
        }
+
        src = src_file->f_dentry->d_inode;
 
        ret = -EINVAL;
        if (src == inode)
                goto out_fput;
 
+       /* the src must be open for reading */
+       if (!(src_file->f_mode & FMODE_READ))
+               goto out_fput;
+
        ret = -EISDIR;
        if (S_ISDIR(src->i_mode) || S_ISDIR(inode->i_mode))
                goto out_fput;