Blob Blame History Raw
From: David Hildenbrand <david@redhat.com>
Date: Thu, 9 Sep 2021 16:59:42 +0200
Subject: s390/pci_mmio: fully validate the VMA before calling follow_pte()
Git-commit: a8b92b8c1eac8d655a97b1e90f4d83c25d9b9a18
Patch-mainline: v5.15-rc2
References: git-fixes

We should not walk/touch page tables outside of VMA boundaries when
holding only the mmap sem in read mode. Evil user space can modify the
VMA layout just before this function runs and e.g., trigger races with
page table removal code since commit dd2283f2605e ("mm: mmap: zap pages
with read mmap_sem in munmap").

find_vma() does not check if the address is >= the VMA start address;
use vma_lookup() instead.

Reviewed-by: Niklas Schnelle <schnelle@linux.ibm.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Fixes: dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in munmap")
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
[ ptesarik: Only one hunk is needed, because SLE15-SP3 does not have
  upstream commit a67a88b0b8de16b4cd6ad50bfe0e03605904dc75. ]
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 arch/s390/pci/pci_mmio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/s390/pci/pci_mmio.c
+++ b/arch/s390/pci/pci_mmio.c
@@ -127,7 +127,7 @@ static long get_pfn(unsigned long user_a
 
 	down_read(&current->mm->mmap_sem);
 	ret = -EINVAL;
-	vma = find_vma(current->mm, user_addr);
+	vma = vma_lookup(current->mm, user_addr);
 	if (!vma)
 		goto out;
 	ret = -EACCES;