From: Greg Kroah-Hartman Date: Tue, 20 Feb 2024 15:45:08 +0000 (+0100) Subject: 6.1-stable patches X-Git-Tag: v4.19.307~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c97c7da2f7a644b24249e36abeb0dbbae0a9737a;p=thirdparty%2Fkernel%2Fstable-queue.git 6.1-stable patches added patches: userfaultfd-fix-mmap_changing-checking-in-mfill_atomic_hugetlb.patch --- diff --git a/queue-6.1/series b/queue-6.1/series index 6d7c8fcc33b..2a0440b33dc 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -194,3 +194,4 @@ net-prevent-mss-overflow-in-skb_segment.patch bpf-add-struct-for-bin_args-arg-in-bpf_bprintf_prepare.patch bpf-do-cleanup-in-bpf_bprintf_cleanup-only-when-needed.patch bpf-remove-trace_printk_lock.patch +userfaultfd-fix-mmap_changing-checking-in-mfill_atomic_hugetlb.patch diff --git a/queue-6.1/userfaultfd-fix-mmap_changing-checking-in-mfill_atomic_hugetlb.patch b/queue-6.1/userfaultfd-fix-mmap_changing-checking-in-mfill_atomic_hugetlb.patch new file mode 100644 index 00000000000..2e783f989d7 --- /dev/null +++ b/queue-6.1/userfaultfd-fix-mmap_changing-checking-in-mfill_atomic_hugetlb.patch @@ -0,0 +1,81 @@ +From 67695f18d55924b2013534ef3bdc363bc9e14605 Mon Sep 17 00:00:00 2001 +From: Lokesh Gidra +Date: Wed, 17 Jan 2024 14:37:29 -0800 +Subject: userfaultfd: fix mmap_changing checking in mfill_atomic_hugetlb + +From: Lokesh Gidra + +commit 67695f18d55924b2013534ef3bdc363bc9e14605 upstream. + +In mfill_atomic_hugetlb(), mmap_changing isn't being checked +again if we drop mmap_lock and reacquire it. When the lock is not held, +mmap_changing could have been incremented. This is also inconsistent +with the behavior in mfill_atomic(). + +Link: https://lkml.kernel.org/r/20240117223729.1444522-1-lokeshgidra@google.com +Fixes: df2cc96e77011 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races") +Signed-off-by: Lokesh Gidra +Cc: Andrea Arcangeli +Cc: Mike Rapoport +Cc: Axel Rasmussen +Cc: Brian Geffon +Cc: David Hildenbrand +Cc: Jann Horn +Cc: Kalesh Singh +Cc: Matthew Wilcox (Oracle) +Cc: Nicolas Geoffray +Cc: Peter Xu +Cc: Suren Baghdasaryan +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Mike Rapoport (IBM) +Signed-off-by: Greg Kroah-Hartman +--- + mm/userfaultfd.c | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +--- a/mm/userfaultfd.c ++++ b/mm/userfaultfd.c +@@ -327,6 +327,7 @@ static __always_inline ssize_t __mcopy_a + unsigned long dst_start, + unsigned long src_start, + unsigned long len, ++ atomic_t *mmap_changing, + enum mcopy_atomic_mode mode, + bool wp_copy) + { +@@ -445,6 +446,15 @@ retry: + goto out; + } + mmap_read_lock(dst_mm); ++ /* ++ * If memory mappings are changing because of non-cooperative ++ * operation (e.g. mremap) running in parallel, bail out and ++ * request the user to retry later ++ */ ++ if (mmap_changing && atomic_read(mmap_changing)) { ++ err = -EAGAIN; ++ break; ++ } + + dst_vma = NULL; + goto retry; +@@ -480,6 +490,7 @@ extern ssize_t __mcopy_atomic_hugetlb(st + unsigned long dst_start, + unsigned long src_start, + unsigned long len, ++ atomic_t *mmap_changing, + enum mcopy_atomic_mode mode, + bool wp_copy); + #endif /* CONFIG_HUGETLB_PAGE */ +@@ -601,8 +612,8 @@ retry: + */ + if (is_vm_hugetlb_page(dst_vma)) + return __mcopy_atomic_hugetlb(dst_mm, dst_vma, dst_start, +- src_start, len, mcopy_mode, +- wp_copy); ++ src_start, len, mmap_changing, ++ mcopy_mode, wp_copy); + + if (!vma_is_anonymous(dst_vma) && !vma_is_shmem(dst_vma)) + goto out_unlock;