]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
mm/shmem: use page_mapping() to detect page cache for uffd continue
authorPeter Xu <peterx@redhat.com>
Wed, 2 Nov 2022 18:41:52 +0000 (14:41 -0400)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 14 Dec 2022 12:59:24 +0000 (13:59 +0100)
commit 93b0d9178743a68723babe8448981f658aebc58e upstream.

mfill_atomic_install_pte() checks page->mapping to detect whether one page
is used in the page cache.  However as pointed out by Matthew, the page
can logically be a tail page rather than always the head in the case of
uffd minor mode with UFFDIO_CONTINUE.  It means we could wrongly install
one pte with shmem thp tail page assuming it's an anonymous page.

It's not that clear even for anonymous page, since normally anonymous
pages also have page->mapping being setup with the anon vma.  It's safe
here only because the only such caller to mfill_atomic_install_pte() is
always passing in a newly allocated page (mcopy_atomic_pte()), whose
page->mapping is not yet setup.  However that's not extremely obvious
either.

For either of above, use page_mapping() instead.

Link: https://lkml.kernel.org/r/Y2K+y7wnhC4vbnP2@x1n
Fixes: 153132571f02 ("userfaultfd/shmem: support UFFDIO_CONTINUE for shmem")
Signed-off-by: Peter Xu <peterx@redhat.com>
Reported-by: Matthew Wilcox <willy@infradead.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Axel Rasmussen <axelrasmussen@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 81fc8f90b8855809d7be6fe5c679026ebade0378)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
mm/userfaultfd.c

index 3bbaf5f5353edbd7d35de3e63426f5b10d5eea1d..d0a7271a6cd5020b34eb390c575ea87e844d09ee 100644 (file)
@@ -63,7 +63,7 @@ int mfill_atomic_install_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd,
        pte_t _dst_pte, *dst_pte;
        bool writable = dst_vma->vm_flags & VM_WRITE;
        bool vm_shared = dst_vma->vm_flags & VM_SHARED;
-       bool page_in_cache = page->mapping;
+       bool page_in_cache = page_mapping(page);
        spinlock_t *ptl;
        struct inode *inode;
        pgoff_t offset, max_off;