Skip to content

Commit cd04466

Browse files
committed
mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable()
commit 8c03ebd Author: Baoquan He <bhe@redhat.com> Date: Thu Apr 10 11:57:14 2025 +0800 mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable() 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/20250410035717.473207-1-bhe@redhat.com Link: https://lkml.kernel.org/r/20250410035717.473207-2-bhe@redhat.com Signed-off-by: Baoquan He <bhe@redhat.com> Fixes: fe673d3 ("mm: gup: make fault_in_safe_writeable() use fixup_user_fault()") Reviewed-by: Oscar Salvador <osalvador@suse.de> Acked-by: David Hildenbrand <david@redhat.com> Cc: Andreas Gruenbacher <agruenba@redhat.com> Cc: Yanjun.Zhu <yanjun.zhu@linux.dev> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> JIRA: https://issues.redhat.com/browse/RHEL-77742 Signed-off-by: Nico Pache <npache@redhat.com>
1 parent 0ea13c4 commit cd04466

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
@@ -2210,8 +2210,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size)
22102210
} while (start != end);
22112211
mmap_read_unlock(mm);
22122212

2213-
if (size > (unsigned long)uaddr - start)
2214-
return size - ((unsigned long)uaddr - start);
2213+
if (size > start - (unsigned long)uaddr)
2214+
return size - (start - (unsigned long)uaddr);
22152215
return 0;
22162216
}
22172217
EXPORT_SYMBOL(fault_in_safe_writeable);

0 commit comments

Comments
 (0)