Skip to content

Commit

Permalink
iov_iter: fix page_copy_sane for compound pages
Browse files Browse the repository at this point in the history
Issue is that if the data crosses a page boundary inside a compound
page, this check will incorrectly trigger a WARN_ON.

To fix this, compute the order using the head of the compound page and
adjust the offset to be relative to that head.

Fixes: 72e809e ("iov_iter: sanity checks for copy to/from page
primitives")

Signed-off-by: Petar Penkov <[email protected]>
CC: Al Viro <[email protected]>
CC: Eric Dumazet <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Petar Penkov authored and Al Viro committed Sep 21, 2017
1 parent 2bd6bf0 commit a90bcb8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/iov_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,10 @@ EXPORT_SYMBOL(_copy_from_iter_full_nocache);

static inline bool page_copy_sane(struct page *page, size_t offset, size_t n)
{
size_t v = n + offset;
if (likely(n <= v && v <= (PAGE_SIZE << compound_order(page))))
struct page *head = compound_head(page);
size_t v = n + offset + page_address(page) - page_address(head);

if (likely(n <= v && v <= (PAGE_SIZE << compound_order(head))))
return true;
WARN_ON(1);
return false;
Expand Down

0 comments on commit a90bcb8

Please sign in to comment.