]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.15-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 May 2022 14:10:24 +0000 (16:10 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 May 2022 14:10:24 +0000 (16:10 +0200)
added patches:
mm-fix-invalid-page-pointer-returned-with-foll_pin-gups.patch

queue-5.15/mm-fix-invalid-page-pointer-returned-with-foll_pin-gups.patch [new file with mode: 0644]
queue-5.15/series

diff --git a/queue-5.15/mm-fix-invalid-page-pointer-returned-with-foll_pin-gups.patch b/queue-5.15/mm-fix-invalid-page-pointer-returned-with-foll_pin-gups.patch
new file mode 100644 (file)
index 0000000..113de8d
--- /dev/null
@@ -0,0 +1,79 @@
+From 7196040e19ad634293acd3eff7083149d7669031 Mon Sep 17 00:00:00 2001
+From: Peter Xu <peterx@redhat.com>
+Date: Tue, 22 Mar 2022 14:39:37 -0700
+Subject: mm: fix invalid page pointer returned with FOLL_PIN gups
+
+From: Peter Xu <peterx@redhat.com>
+
+commit 7196040e19ad634293acd3eff7083149d7669031 upstream.
+
+Patch series "mm/gup: some cleanups", v5.
+
+This patch (of 5):
+
+Alex reported invalid page pointer returned with pin_user_pages_remote()
+from vfio after upstream commit 4b6c33b32296 ("vfio/type1: Prepare for
+batched pinning with struct vfio_batch").
+
+It turns out that it's not the fault of the vfio commit; however after
+vfio switches to a full page buffer to store the page pointers it starts
+to expose the problem easier.
+
+The problem is for VM_PFNMAP vmas we should normally fail with an
+-EFAULT then vfio will carry on to handle the MMIO regions.  However
+when the bug triggered, follow_page_mask() returned -EEXIST for such a
+page, which will jump over the current page, leaving that entry in
+**pages untouched.  However the caller is not aware of it, hence the
+caller will reference the page as usual even if the pointer data can be
+anything.
+
+We had that -EEXIST logic since commit 1027e4436b6a ("mm: make GUP
+handle pfn mapping unless FOLL_GET is requested") which seems very
+reasonable.  It could be that when we reworked GUP with FOLL_PIN we
+could have overlooked that special path in commit 3faa52c03f44 ("mm/gup:
+track FOLL_PIN pages"), even if that commit rightfully touched up
+follow_devmap_pud() on checking FOLL_PIN when it needs to return an
+-EEXIST.
+
+Attaching the Fixes to the FOLL_PIN rework commit, as it happened later
+than 1027e4436b6a.
+
+[jhubbard@nvidia.com: added some tags, removed a reference to an out of tree module.]
+
+Link: https://lkml.kernel.org/r/20220207062213.235127-1-jhubbard@nvidia.com
+Link: https://lkml.kernel.org/r/20220204020010.68930-1-jhubbard@nvidia.com
+Link: https://lkml.kernel.org/r/20220204020010.68930-2-jhubbard@nvidia.com
+Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages")
+Signed-off-by: Peter Xu <peterx@redhat.com>
+Signed-off-by: John Hubbard <jhubbard@nvidia.com>
+Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
+Reported-by: Alex Williamson <alex.williamson@redhat.com>
+Debugged-by: Alex Williamson <alex.williamson@redhat.com>
+Tested-by: Alex Williamson <alex.williamson@redhat.com>
+Reviewed-by: Christoph Hellwig <hch@lst.de>
+Reviewed-by: Jan Kara <jack@suse.cz>
+Cc: Andrea Arcangeli <aarcange@redhat.com>
+Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
+Cc: Jason Gunthorpe <jgg@ziepe.ca>
+Cc: David Hildenbrand <david@redhat.com>
+Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
+Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
+Cc: Jason Gunthorpe <jgg@nvidia.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/gup.c |    2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/mm/gup.c
++++ b/mm/gup.c
+@@ -465,7 +465,7 @@ static int follow_pfn_pte(struct vm_area
+               pte_t *pte, unsigned int flags)
+ {
+       /* No page to get reference */
+-      if (flags & FOLL_GET)
++      if (flags & (FOLL_GET | FOLL_PIN))
+               return -EFAULT;
+       if (flags & FOLL_TOUCH) {
index 3b4aec096248686a704fa42bcdfa6948653e8ea9..c53931864fa91568c648d0da59ecc2552266d522 100644 (file)
@@ -18,3 +18,4 @@ mm-shmem-fix-missing-cache-flush-in-shmem_mfill_atomic_pte.patch
 mm-userfaultfd-fix-missing-cache-flush-in-mcopy_atomic_pte-and-__mcopy_atomic.patch
 mm-hwpoison-fix-error-page-recovered-but-reported-not-recovered.patch
 mm-mlock-fix-potential-imbalanced-rlimit-ucounts-adjustment.patch
+mm-fix-invalid-page-pointer-returned-with-foll_pin-gups.patch