linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 01/14] mm: fix invalid page pointer returned with FOLL_PIN gups
@ 2022-04-28 15:42 Greg Kroah-Hartman
  2022-04-28 15:42 ` [PATCH AUTOSEL 02/14] mm: fix missing cache flush for all tail pages of compound page Greg Kroah-Hartman
                   ` (12 more replies)
  0 siblings, 13 replies; 21+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-28 15:42 UTC (permalink / raw)
  To: stable, linux-kernel
  Cc: Peter Xu, John Hubbard, Claudio Imbrenda, Alex Williamson,
	Christoph Hellwig, Jan Kara, Andrea Arcangeli,
	Kirill A . Shutemov, Jason Gunthorpe, David Hildenbrand,
	Lukas Bulwahn, Matthew Wilcox, Jason Gunthorpe, Andrew Morton,
	Linus Torvalds, Greg Kroah-Hartman

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(-)

diff --git a/mm/gup.c b/mm/gup.c
index 7bc1ba9ce440..41da0bd61bec 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -465,7 +465,7 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address,
 		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) {
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-05-02  8:46 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 15:42 [PATCH AUTOSEL 01/14] mm: fix invalid page pointer returned with FOLL_PIN gups Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 02/14] mm: fix missing cache flush for all tail pages of compound page Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 03/14] mm: hugetlb: fix missing cache flush in copy_huge_page_from_user() Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 04/14] mm: hugetlb: fix missing cache flush in hugetlb_mcopy_atomic_pte() Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 05/14] mm: shmem: fix missing cache flush in shmem_mfill_atomic_pte() Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 06/14] mm: userfaultfd: fix missing cache flush in mcopy_atomic_pte() and __mcopy_atomic() Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 07/14] mm/page_alloc: fetch the correct pcp buddy during bulk free Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 08/14] mm/page_alloc: check high-order pages for corruption during PCP operations Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 09/14] mm/hwpoison: fix error page recovered but reported "not recovered" Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 10/14] mm/mlock: fix potential imbalanced rlimit ucounts adjustment Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 11/14] mm,migrate: fix establishing demotion target Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 12/14] mm/thp: refix __split_huge_pmd_locked() for migration PMD Greg Kroah-Hartman
2022-04-28 15:42 ` [PATCH AUTOSEL 13/14] mm/thp: ClearPageDoubleMap in first page_add_file_rmap() Greg Kroah-Hartman
2022-04-28 16:51   ` Hugh Dickins
2022-04-28 16:58     ` Greg Kroah-Hartman
2022-04-28 19:27       ` Hugh Dickins
2022-04-28 22:45         ` Sean Christopherson
2022-04-29 12:13           ` Greg Kroah-Hartman
2022-04-30  0:27         ` Sasha Levin
2022-05-02  8:45       ` Pavel Machek
2022-04-28 15:42 ` [PATCH AUTOSEL 14/14] mm/thp: fix NR_FILE_MAPPED accounting in page_*_file_rmap() Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).