Commit 7a4c13ac authored by Dan Rosenberg's avatar Dan Rosenberg Committed by Greg Kroah-Hartman

xfs: prevent swapext from operating on write-only files

commit 1817176a upstream.

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: default avatarDan Rosenberg <dan.j.rosenberg@gmail.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 00163203
......@@ -62,7 +62,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;
}
......@@ -74,6 +76,7 @@ xfs_swapext(
}
if (!(target_file->f_mode & FMODE_WRITE) ||
!(target_file->f_mode & FMODE_READ) ||
(target_file->f_flags & O_APPEND)) {
error = XFS_ERROR(EBADF);
goto out_put_target_file;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment