Skip to content

Commit b963112

Browse files
Baoquan Hevijay-suman
authored andcommitted
mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
commit 8c03ebd7cdc06bd0d2fecb4d1a609ef1dbb7d0aa upstream. Not like fault_in_readable() or fault_in_writeable(), in fault_in_safe_writeable() local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calculates the size of the handled range with 'uaddr - start'. Fix it here. Andreas said: : In gfs2, fault_in_iov_iter_writeable() is used in : gfs2_file_direct_read() and gfs2_file_read_iter(), so this potentially : affects buffered as well as direct reads. This bug could cause those : gfs2 functions to spin in a loop. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Baoquan He <[email protected]> Fixes: fe673d3 ("mm: gup: make fault_in_safe_writeable() use fixup_user_fault()") Reviewed-by: Oscar Salvador <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Andreas Gruenbacher <[email protected]> Cc: Yanjun.Zhu <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 7596182dc17f1ede40b5c07f88e893cbe40eef5e) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent f1ff4de commit b963112

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mm/gup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,8 +1768,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size)
17681768
} while (start != end);
17691769
mmap_read_unlock(mm);
17701770

1771-
if (size > (unsigned long)uaddr - start)
1772-
return size - ((unsigned long)uaddr - start);
1771+
if (size > start - (unsigned long)uaddr)
1772+
return size - (start - (unsigned long)uaddr);
17731773
return 0;
17741774
}
17751775
EXPORT_SYMBOL(fault_in_safe_writeable);

0 commit comments

Comments
 (0)