summaryrefslogtreecommitdiff
path: root/mm
diff options
context:
space:
mode:
authorBaoquan He <bhe@redhat.com>2025-04-10 11:57:14 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-04-25 10:43:54 +0200
commita6e7f6018dfd2011d741537c9aea0e57e7edd281 (patch)
treecd167b9744ed74c5cf937dce88a1d22a79a3db05 /mm
parent5cdc985c415a604275d75574bc371987b7827db1 (diff)
downloadlinux-a6e7f6018dfd2011d741537c9aea0e57e7edd281.tar.gz
linux-a6e7f6018dfd2011d741537c9aea0e57e7edd281.tar.bz2
linux-a6e7f6018dfd2011d741537c9aea0e57e7edd281.zip
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/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: fe673d3f5bf1 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/gup.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/mm/gup.c b/mm/gup.c
index b1daaa9d89aa..b4edb6708733 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1881,8 +1881,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size)
} while (start != end);
mmap_read_unlock(mm);
- if (size > (unsigned long)uaddr - start)
- return size - ((unsigned long)uaddr - start);
+ if (size > start - (unsigned long)uaddr)
+ return size - (start - (unsigned long)uaddr);
return 0;
}
EXPORT_SYMBOL(fault_in_safe_writeable);