Skip to content

Commit

Permalink
xfs: prevent swapext from operating on write-only files
Browse files Browse the repository at this point in the history
This patch prevents user "foo" from using the SWAPEXT ioctl to swap
a write-only file owned by user "bar" into a file owned by "foo" and
subsequently reading it.  It does so by checking that the file
descriptors passed to the ioctl are also opened for reading.

Signed-off-by: Dan Rosenberg <dan.j.rosenberg@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Dan Rosenberg authored and Dave Chinner committed Jun 24, 2010
1 parent 7e27d6e commit 1817176
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fs/xfs/xfs_dfrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ xfs_swapext(
goto out;
}

if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) {
if (!(file->f_mode & FMODE_WRITE) ||
!(file->f_mode & FMODE_READ) ||
(file->f_flags & O_APPEND)) {
error = XFS_ERROR(EBADF);
goto out_put_file;
}
Expand All @@ -81,6 +83,7 @@ xfs_swapext(
}

if (!(tmp_file->f_mode & FMODE_WRITE) ||
!(tmp_file->f_mode & FMODE_READ) ||
(tmp_file->f_flags & O_APPEND)) {
error = XFS_ERROR(EBADF);
goto out_put_tmp_file;
Expand Down

0 comments on commit 1817176

Please sign in to comment.