FAILED: patch "[PATCH] s390/mm: validate VMA in PGSTE manipulation functions" failed to apply to 4.14-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 4.14-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 fe3d10024073f06f04c74b9674bd71ccc1d787cf Mon Sep 17 00:00:00 2001
From: David Hildenbrand <[email protected]>
Date: Thu, 9 Sep 2021 18:22:42 +0200
Subject: [PATCH] s390/mm: validate VMA in PGSTE manipulation functions
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"). gfn_to_hva() will only translate using KVM memory regions, but won't validate the VMA.
Further, we should not allocate page tables outside of VMA boundaries: if evil user space decides to map hugetlbfs to these ranges, bad things will happen because we suddenly have PTE or PMD page tables where we shouldn't have them.
Similarly, we have to check if we suddenly find a hugetlbfs VMA, before calling get_locked_pte().
arch/s390/mm/pgtable.c +13 -0
@@ -988,6 +988,7 @@ EXPORT_SYMBOL(get_guest_storage_key);int pgste_perform_essa (struct mm_struct *mm,unsigned long hva,int orc,unsigned long *oldpte,unsigned long *oldpgste) { +struct vm_area_struct *vma;unsigned long pgstev;spinlock_t *ptl;pgste_t pgste;
@@ -997,6 +998,10 @@ int pgste_perform_essa(struct mm_struct *mm, unsigned long hva, int orc,WARN_ON_ONCE (orc >ESSA_MAX );if (unlikely (orc >ESSA_MAX ))return -EINVAL ; + + vma =vma_lookup (mm, hva); +if (!vma ||is_vm_hugetlb_page (vma)) +return -EFAULT ; ptep =get_locked_pte (mm, hva, &ptl);if (unlikely (!ptep))return -EFAULT ;
@@ -1089,10 +1094,14 @@ EXPORT_SYMBOL(pgste_perform_essa);int set_pgste_bits (struct mm_struct *mm,unsigned long hva,unsigned long bits,unsigned long value) { +struct vm_area_struct *vma;spinlock_t *ptl;pgste_t new;pte_t *ptep; + vma =vma_lookup (mm, hva); +if (!vma ||is_vm_hugetlb_page (vma)) +return -EFAULT ; ptep =get_locked_pte (mm, hva, &ptl);if (unlikely (!ptep))return -EFAULT ;
@@ -1117,9 +1126,13 @@ EXPORT_SYMBOL(set_pgste_bits);*/ int get_pgste (struct mm_struct *mm,unsigned long hva,unsigned long *pgstep) { +struct vm_area_struct *vma;spinlock_t *ptl;pte_t *ptep; + vma =vma_lookup (mm, hva); +if (!vma ||is_vm_hugetlb_page (vma)) +return -EFAULT ; ptep =get_locked_pte (mm, hva, &ptl);if (unlikely (!ptep))return -EFAULT ;
PATCH 1/1 s390/mm: validate VMA in PGSTE manipulation functions
commit fe3d10024073f06f04c74b9674bd71ccc1d787cf upstream.
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"). gfn_to_hva() will only translate using KVM memory regions, but won't validate the VMA.
Further, we should not allocate page tables outside of VMA boundaries: if evil user space decides to map hugetlbfs to these ranges, bad things will happen because we suddenly have PTE or PMD page tables where we shouldn't have them.
Similarly, we have to check if we suddenly find a hugetlbfs VMA, before calling get_locked_pte().
--- arch/s390/mm/pgtable.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/s390/mm/pgtable.c +13 -0
@@ -896,6 +896,7 @@ EXPORT_SYMBOL(get_guest_storage_key);int pgste_perform_essa (struct mm_struct *mm,unsigned long hva,int orc,unsigned long *oldpte,unsigned long *oldpgste) { +struct vm_area_struct *vma;unsigned long pgstev;spinlock_t *ptl;pgste_t pgste;
@@ -905,6 +906,10 @@ int pgste_perform_essa(struct mm_struct *mm, unsigned long hva, int orc,WARN_ON_ONCE (orc >ESSA_MAX );if (unlikely (orc >ESSA_MAX ))return -EINVAL ; + + vma =find_vma (mm, hva); +if (!vma || hva < vma->vm_start ||is_vm_hugetlb_page (vma)) +return -EFAULT ; ptep =get_locked_pte (mm, hva, &ptl);if (unlikely (!ptep))return -EFAULT ;
@@ -997,10 +1002,14 @@ EXPORT_SYMBOL(pgste_perform_essa);int set_pgste_bits (struct mm_struct *mm,unsigned long hva,unsigned long bits,unsigned long value) { +struct vm_area_struct *vma;spinlock_t *ptl;pgste_t new;pte_t *ptep; + vma =find_vma (mm, hva); +if (!vma || hva < vma->vm_start ||is_vm_hugetlb_page (vma)) +return -EFAULT ; ptep =get_locked_pte (mm, hva, &ptl);if (unlikely (!ptep))return -EFAULT ;
@@ -1025,9 +1034,13 @@ EXPORT_SYMBOL(set_pgste_bits);*/ int get_pgste (struct mm_struct *mm,unsigned long hva,unsigned long *pgstep) { +struct vm_area_struct *vma;spinlock_t *ptl;pte_t *ptep; + vma =find_vma (mm, hva); +if (!vma || hva < vma->vm_start ||is_vm_hugetlb_page (vma)) +return -EFAULT ; ptep =get_locked_pte (mm, hva, &ptl);if (unlikely (!ptep))return -EFAULT ;
Signature · 1 line
2.31.1
Greg KH
maintainerRe: [PATCH for 4.14-stable] s390/mm: validate VMA in PGSTE manipulation functions
Quoted 24 lines · David Hildenbrand
commit
fe3d10024073f06f04c74b9674bd71ccc1d787cfupstream.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 readmmap_semin munmap").gfn_to_hva()will only translate using KVM memory regions, but won't validate the VMA.Further, we should not allocate page tables outside of VMA boundaries: if evil user space decides to map hugetlbfs to these ranges, bad things will happen because we suddenly have PTE or PMD page tables where we shouldn't have them.
Similarly, we have to check if we suddenly find a hugetlbfs VMA, before calling
get_locked_pte().Fixes 2d42f9477320 ("s390/kvm: Add PGSTE manipulation functions")Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>Acked-by Heiko Carstens <[email protected]>Signed-off-by Christian Borntraeger <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Quoted 3 lines
--- arch/s390/mm/pgtable.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
What about for 5.10-stable and 5.4-stable and 4.19-stable? Will this commit work there as well?
thanks,
greg k-h
Re: [PATCH for 4.14-stable] s390/mm: validate VMA in PGSTE manipulation functions
Quoted 29 lines · Greg KH
Quoted 24 lines · David Hildenbrand
commit
fe3d10024073f06f04c74b9674bd71ccc1d787cfupstream.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 readmmap_semin munmap").gfn_to_hva()will only translate using KVM memory regions, but won't validate the VMA.Further, we should not allocate page tables outside of VMA boundaries: if evil user space decides to map hugetlbfs to these ranges, bad things will happen because we suddenly have PTE or PMD page tables where we shouldn't have them.
Similarly, we have to check if we suddenly find a hugetlbfs VMA, before calling
get_locked_pte().Fixes 2d42f9477320 ("s390/kvm: Add PGSTE manipulation functions")Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>Acked-by Heiko Carstens <[email protected]>Signed-off-by Christian Borntraeger <[email protected]>Signed-off-by David Hildenbrand <[email protected]>Quoted 3 lines
--- arch/s390/mm/pgtable.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Quoted 2 lines
What about for 5.10-stable and 5.4-stable and 4.19-stable? Will this commit work there as well?
Good point, I only have "FAILED: patch "[PATCH] s390/mm: validate VMA in PGSTE manipulation functions" failed to apply to 4.14-stable tree" in my inbox ... but maybe I accidentally deleted the others.
This commit can also be used for:
- 4.19-stable
- 5.4-stable
- 5.10-stable
They all lack vma_lookup() and we have to implement the start address check manually.
Signature · 3 lines
Thanks, David / dhildenb
Greg KH
maintainerRe: [PATCH for 4.14-stable] s390/mm: validate VMA in PGSTE manipulation functions
Quoted 30 lines · David Hildenbrand
Quoted 29 lines · Greg KH
Quoted 27 lines · David Hildenbrand
commit
fe3d10024073f06f04c74b9674bd71ccc1d787cfupstream.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 readmmap_semin munmap").gfn_to_hva()will only translate using KVM memory regions, but won't validate the VMA.Further, we should not allocate page tables outside of VMA boundaries: if evil user space decides to map hugetlbfs to these ranges, bad things will happen because we suddenly have PTE or PMD page tables where we shouldn't have them.
Similarly, we have to check if we suddenly find a hugetlbfs VMA, before calling
get_locked_pte().Fixes 2d42f9477320 ("s390/kvm: Add PGSTE manipulation functions")Signed-off-by David Hildenbrand <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>Acked-by Heiko Carstens <[email protected]>Signed-off-by Christian Borntraeger <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- arch/s390/mm/pgtable.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Quoted 6 lines
Quoted 2 lines
What about for 5.10-stable and 5.4-stable and 4.19-stable? Will this commit work there as well?
Good point, I only have "FAILED: patch "[PATCH] s390/mm: validate VMA in PGSTE manipulation functions" failed to apply to 4.14-stable tree" in my inbox ... but maybe I accidentally deleted the others.
No, odd, I did not send those out, sorry about that.
Quoted 4 lines
This commit can also be used for:
- 4.19-stable
- 5.4-stable
- 5.10-stable
Thanks, will go take this now for all of those.
greg k-h