Skip to content

Commit add66fc

Browse files
Andreas Gruenbacherdjwong
authored andcommitted
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: Andreas Gruenbacher <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent a901004 commit add66fc

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

fs/iomap/buffered-io.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,20 +1067,19 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops)
10671067

10681068
lock_page(page);
10691069
size = i_size_read(inode);
1070-
if ((page->mapping != inode->i_mapping) ||
1071-
(page_offset(page) > size)) {
1070+
offset = page_offset(page);
1071+
if (page->mapping != inode->i_mapping || offset > size) {
10721072
/* We overload EFAULT to mean page got truncated */
10731073
ret = -EFAULT;
10741074
goto out_unlock;
10751075
}
10761076

10771077
/* page is wholly or partially inside EOF */
1078-
if (((page->index + 1) << PAGE_SHIFT) > size)
1078+
if (offset > size - PAGE_SIZE)
10791079
length = offset_in_page(size);
10801080
else
10811081
length = PAGE_SIZE;
10821082

1083-
offset = page_offset(page);
10841083
while (length > 0) {
10851084
ret = iomap_apply(inode, offset, length,
10861085
IOMAP_WRITE | IOMAP_FAULT, ops, page,

0 commit comments

Comments
 (0)