Commit 53b776c7 authored by David Howells's avatar David Howells

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: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/161789062190.6155.12711584466338493050.stgit@warthog.procyon.org.uk/ [1]
parent 3d14ec1f
...@@ -933,7 +933,7 @@ void netfs_readahead(struct readahead_control *ractl, ...@@ -933,7 +933,7 @@ void netfs_readahead(struct readahead_control *ractl,
EXPORT_SYMBOL(netfs_readahead); 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 * @file: The file to read from
* @page: The page to read * @page: The page to read
* @ops: The network filesystem's operations for the helper to use * @ops: The network filesystem's operations for the helper to use
...@@ -968,7 +968,7 @@ int netfs_readpage(struct file *file, ...@@ -968,7 +968,7 @@ int netfs_readpage(struct file *file,
return -ENOMEM; return -ENOMEM;
} }
rreq->mapping = page_file_mapping(page); rreq->mapping = page_file_mapping(page);
rreq->start = page_index(page) * PAGE_SIZE; rreq->start = page_file_offset(page);
rreq->len = thp_size(page); rreq->len = thp_size(page);
if (ops->begin_cache_operation) { if (ops->begin_cache_operation) {
...@@ -1106,7 +1106,7 @@ int netfs_write_begin(struct file *file, struct address_space *mapping, ...@@ -1106,7 +1106,7 @@ int netfs_write_begin(struct file *file, struct address_space *mapping,
if (!rreq) if (!rreq)
goto error; goto error;
rreq->mapping = page->mapping; rreq->mapping = page->mapping;
rreq->start = page->index * PAGE_SIZE; rreq->start = page_offset(page);
rreq->len = thp_size(page); rreq->len = thp_size(page);
rreq->no_unlock_page = page->index; rreq->no_unlock_page = page->index;
__set_bit(NETFS_RREQ_NO_UNLOCK_PAGE, &rreq->flags); __set_bit(NETFS_RREQ_NO_UNLOCK_PAGE, &rreq->flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment