[SRU,Artful,1/1] iov_iter: fix page_copy_sane for compound pages

Message ID 365628d054c3dde892133225ba1337ec2d28a904.1526926496.git.joseph.salisbury@canonical.com
State New
Headers show
Series
  • iov_iter: fix page_copy_sane for compound pages
Related show

Commit Message

Joseph Salisbury June 1, 2018, 4:29 p.m.
From: Petar Penkov <ppenkov@google.com>

BugLink: http://bugs.launchpad.net/bugs/1772031

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: 72e809ed81ed ("iov_iter: sanity checks for copy to/from page
primitives")

Signed-off-by: Petar Penkov <ppenkov@google.com>
CC: Al Viro <viro@zeniv.linux.org.uk>
CC: Eric Dumazet <edumazet@google.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
(cherry picked from commit a90bcb86ae700c12432446c4aa1819e7b8e172ec)
Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>
---
 lib/iov_iter.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Kleber Souza June 5, 2018, 7:36 p.m. | #1
On 06/01/18 09:29, Joseph Salisbury wrote:
> From: Petar Penkov <ppenkov@google.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1772031
> 
> 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: 72e809ed81ed ("iov_iter: sanity checks for copy to/from page
> primitives")
> 
> Signed-off-by: Petar Penkov <ppenkov@google.com>
> CC: Al Viro <viro@zeniv.linux.org.uk>
> CC: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> (cherry picked from commit a90bcb86ae700c12432446c4aa1819e7b8e172ec)
> Signed-off-by: Joseph Salisbury <joseph.salisbury@canonical.com>

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

> ---
>  lib/iov_iter.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> index 52c8dd6..1c1c06d 100644
> --- a/lib/iov_iter.c
> +++ b/lib/iov_iter.c
> @@ -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;
>

Patch

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 52c8dd6..1c1c06d 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -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;