Skip to content

Commit

Permalink
Btrfs: check for read permission on src file in the clone ioctl
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dan Rosenberg authored and Chris Mason committed May 15, 2010
1 parent 9f680ce commit 5dc6416
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5dc6416

Please sign in to comment.