Skip to content

Commit d755b6c

Browse files
surenbaghdasaryanopsiff
authored andcommitted
userfaultfd: fix a crash in UFFDIO_MOVE when PMD is a migration entry
commit aba6faec0103ed8f169be8dce2ead41fcb689446 upstream. When UFFDIO_MOVE encounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry is swp_entry_t. Add the missing check and let split_huge_pmd() handle migration entries. While at it also remove unnecessary folio check. [surenb@google.com: remove extra folio check, per David] Link: https://lkml.kernel.org/r/20250807200418.1963585-1-surenb@google.com Link: https://lkml.kernel.org/r/20250806220022.926763-1-surenb@google.com Fixes: adef440 ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reported-by: syzbot+b446dbe27035ef6bd6c2@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/68794b5c.a70a0220.693ce.0050.GAE@google.com/ Reviewed-by: Peter Xu <peterx@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit bb81c18dbd42650c844e160cafa7cbb20243a96a)
1 parent 9c493f7 commit d755b6c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

mm/userfaultfd.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,13 +1800,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
18001800
/* Check if we can move the pmd without splitting it. */
18011801
if (move_splits_huge_pmd(dst_addr, src_addr, src_start + len) ||
18021802
!pmd_none(dst_pmdval)) {
1803-
struct folio *folio = pmd_folio(*src_pmd);
1804-
1805-
if (!folio || (!is_huge_zero_folio(folio) &&
1806-
!PageAnonExclusive(&folio->page))) {
1807-
spin_unlock(ptl);
1808-
err = -EBUSY;
1809-
break;
1803+
/* Can be a migration entry */
1804+
if (pmd_present(*src_pmd)) {
1805+
struct folio *folio = pmd_folio(*src_pmd);
1806+
1807+
if (!is_huge_zero_folio(folio) &&
1808+
!PageAnonExclusive(&folio->page)) {
1809+
spin_unlock(ptl);
1810+
err = -EBUSY;
1811+
break;
1812+
}
18101813
}
18111814

18121815
spin_unlock(ptl);

0 commit comments

Comments
 (0)