]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
xfs: prevent swapext from operating on write-only files
authorDan Rosenberg <dan.j.rosenberg@gmail.com>
Thu, 24 Jun 2010 02:07:47 +0000 (12:07 +1000)
committerDave Chinner <david@fromorbit.com>
Thu, 24 Jun 2010 02:07:47 +0000 (12:07 +1000)
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>
fs/xfs/xfs_dfrag.c

index 5bba29a07812cb761a9094e2ca1448491e99fc27..7f159d2a429a97e8a71e0fd57298ec499519c064 100644 (file)
@@ -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;
        }
@@ -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;