Commit add66fcb authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Darrick J. Wong

iomap: Fix overflow in iomap_page_mkwrite

On architectures where loff_t is wider than pgoff_t, the expression
((page->index + 1) << PAGE_SHIFT) can overflow.  Rewrite to use the page
offset, which we already compute here anyway.
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent a9010042
...@@ -1067,20 +1067,19 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops) ...@@ -1067,20 +1067,19 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)
lock_page(page); lock_page(page);
size = i_size_read(inode); size = i_size_read(inode);
if ((page->mapping != inode->i_mapping) || offset = page_offset(page);
(page_offset(page) > size)) { if (page->mapping != inode->i_mapping || offset > size) {
/* We overload EFAULT to mean page got truncated */ /* We overload EFAULT to mean page got truncated */
ret = -EFAULT; ret = -EFAULT;
goto out_unlock; goto out_unlock;
} }
/* page is wholly or partially inside EOF */ /* page is wholly or partially inside EOF */
if (((page->index + 1) << PAGE_SHIFT) > size) if (offset > size - PAGE_SIZE)
length = offset_in_page(size); length = offset_in_page(size);
else else
length = PAGE_SIZE; length = PAGE_SIZE;
offset = page_offset(page);
while (length > 0) { while (length > 0) {
ret = iomap_apply(inode, offset, length, ret = iomap_apply(inode, offset, length,
IOMAP_WRITE | IOMAP_FAULT, ops, page, IOMAP_WRITE | IOMAP_FAULT, ops, page,
......
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