Skip to contentSkip to conversation

FAILED: patch "[PATCH] s390/pci_mmio: fully validate the VMA before calling" failed to apply to 5.10-stable tree

PATCH In review [email protected] 2 participants 3 messages Sep 20, 2021 – Sep 23, 2021

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From a8b92b8c1eac8d655a97b1e90f4d83c25d9b9a18 Mon Sep 17 00:00:00 2001
From: David Hildenbrand <[email protected]>
Date: Thu, 9 Sep 2021 16:59:42 +0200
Subject: [PATCH] s390/pci_mmio: fully validate the VMA before calling
follow_pte()

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.

Fixes dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in munmap")
arch/s390/pci/pci_mmio.c +2 -2
index ae683aa623ac..c5b35ea129cf 100644
@@ -159,7 +159,7 @@ SYSCALL_DEFINE3(s390_pci_mmio_write, unsigned long, mmio_addr,
 
 	mmap_read_lock(current->mm);
 	ret = -EINVAL;
-	vma = find_vma(current->mm, mmio_addr);
+	vma = vma_lookup(current->mm, mmio_addr);
 	if (!vma)
 		goto out_unlock_mmap;
 	if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
@@ -298,7 +298,7 @@ SYSCALL_DEFINE3(s390_pci_mmio_read, unsigned long, mmio_addr,
 
 	mmap_read_lock(current->mm);
 	ret = -EINVAL;
-	vma = find_vma(current->mm, mmio_addr);
+	vma = vma_lookup(current->mm, mmio_addr);
 	if (!vma)
 		goto out_unlock_mmap;
 	if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
#1 lore raw

PATCH 1/1 s390/pci_mmio: fully validate the VMA before calling follow_pte()

commit a8b92b8c1eac8d655a97b1e90f4d83c25d9b9a18 upstream.

Note: We don't have vma_lookup() in the 5.4-stable tree, so perform the VMA check manually.

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.

Fixes dd2283f2605e ("mm: mmap: zap pages with read mmap_sem in munmap")
---
 arch/s390/pci/pci_mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/pci/pci_mmio.c +1 -1
index 401cf670a243..37b1bbd1a27c 100644
@@ -128,7 +128,7 @@ static long get_pfn(unsigned long user_addr, unsigned long access,
 	mmap_read_lock(current->mm);
 	ret = -EINVAL;
 	vma = find_vma(current->mm, user_addr);
-	if (!vma)
+	if (!vma || user_addr < vma->vm_start)
 		goto out;
 	ret = -EACCES;
 	if (!(vma->vm_flags & access))
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

Re: [PATCH 5.10 STABLE] s390/pci_mmio: fully validate the VMA before calling follow_pte()

Quoted 4 lines · David Hildenbrand

commit a8b92b8c1eac8d655a97b1e90f4d83c25d9b9a18 upstream.

Note: We don't have vma_lookup() in the 5.4-stable tree, so perform the VMA check manually.

Both backports now queued up, thanks.

greg k-h