Skip to content

Commit aba6fae

Browse files
surenbaghdasaryanakpm00
authored andcommitted
userfaultfd: fix a crash in UFFDIO_MOVE when PMD is a migration entry
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. [[email protected]: remove extra folio check, per David] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Fixes: adef440 ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Suren Baghdasaryan <[email protected]> Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Peter Xu <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Lokesh Gidra <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cf1b80d commit aba6fae

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
@@ -1821,13 +1821,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
18211821
/* Check if we can move the pmd without splitting it. */
18221822
if (move_splits_huge_pmd(dst_addr, src_addr, src_start + len) ||
18231823
!pmd_none(dst_pmdval)) {
1824-
struct folio *folio = pmd_folio(*src_pmd);
1825-
1826-
if (!folio || (!is_huge_zero_folio(folio) &&
1827-
!PageAnonExclusive(&folio->page))) {
1828-
spin_unlock(ptl);
1829-
err = -EBUSY;
1830-
break;
1824+
/* Can be a migration entry */
1825+
if (pmd_present(*src_pmd)) {
1826+
struct folio *folio = pmd_folio(*src_pmd);
1827+
1828+
if (!is_huge_zero_folio(folio) &&
1829+
!PageAnonExclusive(&folio->page)) {
1830+
spin_unlock(ptl);
1831+
err = -EBUSY;
1832+
break;
1833+
}
18311834
}
18321835

18331836
spin_unlock(ptl);

0 commit comments

Comments
 (0)