Skip to content

Commit

Permalink
vfs: read file_handle only once in handle_to_path
Browse files Browse the repository at this point in the history
We used to read file_handle twice.  Once to get the amount of extra
bytes, and once to fetch the entire structure.

This may be problematic since we do size verifications only after the
first read, so if the number of extra bytes changes in userspace between
the first and second calls, we'll have an incoherent view of
file_handle.

Instead, read the constant size once, and copy that over to the final
structure without having to re-read it again.

Signed-off-by: Sasha Levin <[email protected]>
Cc: Al Viro <[email protected]>
Cc: [email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
sashalevin authored and torvalds committed Jun 2, 2015
1 parent f18c34e commit 161f873
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/fhandle.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
goto out_err;
}
/* copy the full handle */
if (copy_from_user(handle, ufh,
sizeof(struct file_handle) +
*handle = f_handle;
if (copy_from_user(&handle->f_handle,
&ufh->f_handle,
f_handle.handle_bytes)) {
retval = -EFAULT;
goto out_handle;
Expand Down

0 comments on commit 161f873

Please sign in to comment.