Skip to content

Commit

Permalink
Btrfs: deal with short returns from copy_from_user
Browse files Browse the repository at this point in the history
When copy_from_user is only able to copy some of the bytes we requested,
we may end up creating a partially up to date page.  To avoid garbage in
the page, we need to treat a partial copy as a zero length copy.

This makes the rest of the file_write code drop the page and
retry the whole copy instead of marking the partially up to
date page as dirty.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
cc: stable@kernel.org
  • Loading branch information
Chris Mason committed Mar 7, 2011
1 parent b1bf862 commit 31339ac
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ static noinline int btrfs_copy_from_user(loff_t pos, int num_pages,

/* Flush processor's dcache for this page */
flush_dcache_page(page);

/*
* if we get a partial write, we can end up with
* partially up to date pages. These add
* a lot of complexity, so make sure they don't
* happen by forcing this copy to be retried.
*
* The rest of the btrfs_file_write code will fall
* back to page at a time copies after we return 0.
*/
if (!PageUptodate(page) && copied < count)
copied = 0;

iov_iter_advance(i, copied);
write_bytes -= copied;
total_copied += copied;
Expand Down

0 comments on commit 31339ac

Please sign in to comment.