diff mbox series

[v2] netfs: Miscellaneous fixes

Message ID 3737237.1619472003@warthog.procyon.org.uk (mailing list archive)
State New, archived
Headers show
Series [v2] netfs: Miscellaneous fixes | expand

Commit Message

David Howells April 26, 2021, 9:20 p.m. UTC
Okay, how about the attached, then?

David
---
netfs: Miscellaneous fixes
    
Fix some miscellaneous things in the new netfs lib[1]:

 (1) The kerneldoc for netfs_readpage() shouldn't say netfs_page().

 (2) netfs_readpage() can get an integer overflow on 32-bit when it
     multiplies page_index(page) by PAGE_SIZE.  It should use
     page_file_offset() instead.

 (3) netfs_write_begin() should use page_offset() to avoid the same
     overflow.

Note that netfs_readpage() needs to use page_file_offset() rather than
page_offset() as it may see swap-over-NFS.

Reported-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://lore.kernel.org/r/161789062190.6155.12711584466338493050.stgit@warthog.procyon.org.uk/ [1]
---
 fs/netfs/read_helper.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Matthew Wilcox April 26, 2021, 10:06 p.m. UTC | #1
On Mon, Apr 26, 2021 at 10:20:03PM +0100, David Howells wrote:
> Okay, how about the attached, then?

LGTM!  Thanks.
Jeff Layton April 26, 2021, 10:17 p.m. UTC | #2
On Mon, 2021-04-26 at 22:20 +0100, David Howells wrote:
> Okay, how about the attached, then?
> 
> David
> ---
> netfs: Miscellaneous fixes
>     
> 
> 
> 
> Fix some miscellaneous things in the new netfs lib[1]:
> 
>  (1) The kerneldoc for netfs_readpage() shouldn't say netfs_page().
> 
>  (2) netfs_readpage() can get an integer overflow on 32-bit when it
>      multiplies page_index(page) by PAGE_SIZE.  It should use
>      page_file_offset() instead.
> 
>  (3) netfs_write_begin() should use page_offset() to avoid the same
>      overflow.
> 
> Note that netfs_readpage() needs to use page_file_offset() rather than
> page_offset() as it may see swap-over-NFS.
> 
> Reported-by: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Link: https://lore.kernel.org/r/161789062190.6155.12711584466338493050.stgit@warthog.procyon.org.uk/ [1]
> ---
>  fs/netfs/read_helper.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
> index 1d3b50c5db6d..193841d03de0 100644
> --- a/fs/netfs/read_helper.c
> +++ b/fs/netfs/read_helper.c
> @@ -933,7 +933,7 @@ void netfs_readahead(struct readahead_control *ractl,
>  EXPORT_SYMBOL(netfs_readahead);
>  
> 
> 
> 
>  /**
> - * netfs_page - Helper to manage a readpage request
> + * netfs_readpage - Helper to manage a readpage request
>   * @file: The file to read from
>   * @page: The page to read
>   * @ops: The network filesystem's operations for the helper to use
> @@ -968,7 +968,7 @@ int netfs_readpage(struct file *file,
>  		return -ENOMEM;
>  	}
>  	rreq->mapping	= page_file_mapping(page);
> -	rreq->start	= page_index(page) * PAGE_SIZE;
> +	rreq->start	= page_file_offset(page);
>  	rreq->len	= thp_size(page);
>  
> 
> 
> 
>  	if (ops->begin_cache_operation) {
> @@ -1106,7 +1106,7 @@ int netfs_write_begin(struct file *file, struct address_space *mapping,
>  	if (!rreq)
>  		goto error;
>  	rreq->mapping		= page->mapping;
> -	rreq->start		= page->index * PAGE_SIZE;
> +	rreq->start		= page_offset(page);
>  	rreq->len		= thp_size(page);
>  	rreq->no_unlock_page	= page->index;
>  	__set_bit(NETFS_RREQ_NO_UNLOCK_PAGE, &rreq->flags);
> 

Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff mbox series

Patch

diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index 1d3b50c5db6d..193841d03de0 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -933,7 +933,7 @@  void netfs_readahead(struct readahead_control *ractl,
 EXPORT_SYMBOL(netfs_readahead);
 
 /**
- * netfs_page - Helper to manage a readpage request
+ * netfs_readpage - Helper to manage a readpage request
  * @file: The file to read from
  * @page: The page to read
  * @ops: The network filesystem's operations for the helper to use
@@ -968,7 +968,7 @@  int netfs_readpage(struct file *file,
 		return -ENOMEM;
 	}
 	rreq->mapping	= page_file_mapping(page);
-	rreq->start	= page_index(page) * PAGE_SIZE;
+	rreq->start	= page_file_offset(page);
 	rreq->len	= thp_size(page);
 
 	if (ops->begin_cache_operation) {
@@ -1106,7 +1106,7 @@  int netfs_write_begin(struct file *file, struct address_space *mapping,
 	if (!rreq)
 		goto error;
 	rreq->mapping		= page->mapping;
-	rreq->start		= page->index * PAGE_SIZE;
+	rreq->start		= page_offset(page);
 	rreq->len		= thp_size(page);
 	rreq->no_unlock_page	= page->index;
 	__set_bit(NETFS_RREQ_NO_UNLOCK_PAGE, &rreq->flags);