mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
FROMGIT: userfaultfd: fix PTE unmapping stack-allocated PTE copies
Current implementation of move_pages_pte() copies source and destination PTEs in order to detect concurrent changes to PTEs involved in the move. However these copies are also used to unmap the PTEs, which will fail if CONFIG_HIGHPTE is enabled because the copies are allocated on the stack. Fix this by using the actual PTEs which were kmap()ed. Link: https://lkml.kernel.org/r/20250226185510.2732648-3-surenb@google.com Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Suren Baghdasaryan <surenb@google.com> Reported-by: Peter Xu <peterx@redhat.com> Reviewed-by: Peter Xu <peterx@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Barry Song <21cnbao@gmail.com> Cc: Barry Song <v-songbaohua@oppo.com> Cc: David Hildenbrand <david@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Jann Horn <jannh@google.com> Cc: Kalesh Singh <kaleshsingh@google.com> Cc: Liam R. Howlett <Liam.Howlett@Oracle.com> Cc: Lokesh Gidra <lokeshgidra@google.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Matthew Wilcow (Oracle) <willy@infradead.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Lokesh Gidra <lokeshgidra@google.com> (cherry-picked from commit 927e926d72d9155fde3264459fe9bfd7b5e40d28 https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-hotfixes-stable) Change-Id: I0ee6c1b509ea7c4fa68056d6e512d4ac167c9234 Bug: 401790618
This commit is contained in:
committed by
Lokesh Gidra
parent
af439accc7
commit
8d8d44ff91
@@ -1175,8 +1175,8 @@ retry:
|
|||||||
spin_unlock(src_ptl);
|
spin_unlock(src_ptl);
|
||||||
|
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
pte_unmap(&orig_src_pte);
|
pte_unmap(src_pte);
|
||||||
pte_unmap(&orig_dst_pte);
|
pte_unmap(dst_pte);
|
||||||
src_pte = dst_pte = NULL;
|
src_pte = dst_pte = NULL;
|
||||||
/* now we can block and wait */
|
/* now we can block and wait */
|
||||||
folio_lock(src_folio);
|
folio_lock(src_folio);
|
||||||
@@ -1192,8 +1192,8 @@ retry:
|
|||||||
/* at this point we have src_folio locked */
|
/* at this point we have src_folio locked */
|
||||||
if (folio_test_large(src_folio)) {
|
if (folio_test_large(src_folio)) {
|
||||||
/* split_folio() can block */
|
/* split_folio() can block */
|
||||||
pte_unmap(&orig_src_pte);
|
pte_unmap(src_pte);
|
||||||
pte_unmap(&orig_dst_pte);
|
pte_unmap(dst_pte);
|
||||||
src_pte = dst_pte = NULL;
|
src_pte = dst_pte = NULL;
|
||||||
err = split_folio(src_folio);
|
err = split_folio(src_folio);
|
||||||
if (err)
|
if (err)
|
||||||
@@ -1218,8 +1218,8 @@ retry:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!anon_vma_trylock_write(src_anon_vma)) {
|
if (!anon_vma_trylock_write(src_anon_vma)) {
|
||||||
pte_unmap(&orig_src_pte);
|
pte_unmap(src_pte);
|
||||||
pte_unmap(&orig_dst_pte);
|
pte_unmap(dst_pte);
|
||||||
src_pte = dst_pte = NULL;
|
src_pte = dst_pte = NULL;
|
||||||
/* now we can block and wait */
|
/* now we can block and wait */
|
||||||
anon_vma_lock_write(src_anon_vma);
|
anon_vma_lock_write(src_anon_vma);
|
||||||
@@ -1237,8 +1237,8 @@ retry:
|
|||||||
entry = pte_to_swp_entry(orig_src_pte);
|
entry = pte_to_swp_entry(orig_src_pte);
|
||||||
if (non_swap_entry(entry)) {
|
if (non_swap_entry(entry)) {
|
||||||
if (is_migration_entry(entry)) {
|
if (is_migration_entry(entry)) {
|
||||||
pte_unmap(&orig_src_pte);
|
pte_unmap(src_pte);
|
||||||
pte_unmap(&orig_dst_pte);
|
pte_unmap(dst_pte);
|
||||||
src_pte = dst_pte = NULL;
|
src_pte = dst_pte = NULL;
|
||||||
migration_entry_wait(mm, src_pmd, src_addr);
|
migration_entry_wait(mm, src_pmd, src_addr);
|
||||||
err = -EAGAIN;
|
err = -EAGAIN;
|
||||||
@@ -1281,8 +1281,8 @@ retry:
|
|||||||
src_folio = folio;
|
src_folio = folio;
|
||||||
src_folio_pte = orig_src_pte;
|
src_folio_pte = orig_src_pte;
|
||||||
if (!folio_trylock(src_folio)) {
|
if (!folio_trylock(src_folio)) {
|
||||||
pte_unmap(&orig_src_pte);
|
pte_unmap(src_pte);
|
||||||
pte_unmap(&orig_dst_pte);
|
pte_unmap(dst_pte);
|
||||||
src_pte = dst_pte = NULL;
|
src_pte = dst_pte = NULL;
|
||||||
put_swap_device(si);
|
put_swap_device(si);
|
||||||
si = NULL;
|
si = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user