Skip to content

Commit c0205ea

Browse files
SENSEIIIIIakpm00
authored andcommitted
userfaultfd: change src_folio after ensuring it's unpinned in UFFDIO_MOVE
Commit d7a0883 ("mm: userfaultfd: fix unexpected change to src_folio when UFFDIO_MOVE fails") moved the src_folio->{mapping, index} changing to after clearing the page-table and ensuring that it's not pinned. This avoids failure of swapout+migration and possibly memory corruption. However, the commit missed fixing it in the huge-page case. Link: https://lkml.kernel.org/r/20240404171726.2302435-1-lokeshgidra@google.com Fixes: adef440 ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Kalesh Singh <kaleshsingh@google.com> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Nicolas Geoffray <ngeoffray@google.com> Cc: Peter Xu <peterx@redhat.com> Cc: Qi Zheng <zhengqi.arch@bytedance.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 631426b commit c0205ea

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

mm/huge_memory.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,9 +2259,6 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
22592259
goto unlock_ptls;
22602260
}
22612261

2262-
folio_move_anon_rmap(src_folio, dst_vma);
2263-
WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
2264-
22652262
src_pmdval = pmdp_huge_clear_flush(src_vma, src_addr, src_pmd);
22662263
/* Folio got pinned from under us. Put it back and fail the move. */
22672264
if (folio_maybe_dma_pinned(src_folio)) {
@@ -2270,6 +2267,9 @@ int move_pages_huge_pmd(struct mm_struct *mm, pmd_t *dst_pmd, pmd_t *src_pmd, pm
22702267
goto unlock_ptls;
22712268
}
22722269

2270+
folio_move_anon_rmap(src_folio, dst_vma);
2271+
WRITE_ONCE(src_folio->index, linear_page_index(dst_vma, dst_addr));
2272+
22732273
_dst_pmd = mk_huge_pmd(&src_folio->page, dst_vma->vm_page_prot);
22742274
/* Follow mremap() behavior and treat the entry dirty after the move */
22752275
_dst_pmd = pmd_mkwrite(pmd_mkdirty(_dst_pmd), dst_vma);

0 commit comments

Comments
 (0)