Skip to content

Commit

Permalink
xfs: fix type confusion in xfs_ioc_swapext
Browse files Browse the repository at this point in the history
When calling fdget() in xfs_ioc_swapext(), we need to verify that
the file descriptors passed into the ioctl point to XFS inodes
before we start operations on them. If we don't do this, we could be
referencing arbitrary kernel memory as an XFS inode. THis could lead
to memory corruption and/or performing locking operations on
attacker-chosen structures in kernel memory.

[dchinner: rewrite commit message ]
[dchinner: add comment explaining new check ]

Signed-off-by: Jann Horn <[email protected]>
Reviewed-by: Dave Chinner <[email protected]>
Signed-off-by: Dave Chinner <[email protected]>
  • Loading branch information
thejh authored and dchinner committed Jul 20, 2016
1 parent 1a695a9 commit 7f1b624
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/xfs/xfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,17 @@ xfs_ioc_swapext(
goto out_put_tmp_file;
}

/*
* We need to ensure that the fds passed in point to XFS inodes
* before we cast and access them as XFS structures as we have no
* control over what the user passes us here.
*/
if (f.file->f_op != &xfs_file_operations ||
tmp.file->f_op != &xfs_file_operations) {
error = -EINVAL;
goto out_put_tmp_file;
}

ip = XFS_I(file_inode(f.file));
tip = XFS_I(file_inode(tmp.file));

Expand Down

0 comments on commit 7f1b624

Please sign in to comment.