Skip to content

Commit aa20e96

Browse files
David Hildenbrandgregkh
authored andcommitted
s390/mm: validate VMA in PGSTE manipulation functions
commit fe3d100 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 dd2283f ("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(). Fixes: 2d42f94 ("s390/kvm: Add PGSTE manipulation functions") Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Acked-by: Heiko Carstens <hca@linux.ibm.com> Link: https://lore.kernel.org/r/20210909162248.14969-4-david@redhat.com Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a94e4a7 commit aa20e96

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎arch/s390/mm/pgtable.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ EXPORT_SYMBOL(get_guest_storage_key);
988988
int pgste_perform_essa(struct mm_struct *mm, unsigned long hva, int orc,
989989
unsigned long *oldpte, unsigned long *oldpgste)
990990
{
991+
struct vm_area_struct *vma;
991992
unsigned long pgstev;
992993
spinlock_t *ptl;
993994
pgste_t pgste;
@@ -997,6 +998,10 @@ int pgste_perform_essa(struct mm_struct *mm, unsigned long hva, int orc,
997998
WARN_ON_ONCE(orc > ESSA_MAX);
998999
if (unlikely(orc > ESSA_MAX))
9991000
return -EINVAL;
1001+
1002+
vma = find_vma(mm, hva);
1003+
if (!vma || hva < vma->vm_start || is_vm_hugetlb_page(vma))
1004+
return -EFAULT;
10001005
ptep = get_locked_pte(mm, hva, &ptl);
10011006
if (unlikely(!ptep))
10021007
return -EFAULT;
@@ -1089,10 +1094,14 @@ EXPORT_SYMBOL(pgste_perform_essa);
10891094
int set_pgste_bits(struct mm_struct *mm, unsigned long hva,
10901095
unsigned long bits, unsigned long value)
10911096
{
1097+
struct vm_area_struct *vma;
10921098
spinlock_t *ptl;
10931099
pgste_t new;
10941100
pte_t *ptep;
10951101

1102+
vma = find_vma(mm, hva);
1103+
if (!vma || hva < vma->vm_start || is_vm_hugetlb_page(vma))
1104+
return -EFAULT;
10961105
ptep = get_locked_pte(mm, hva, &ptl);
10971106
if (unlikely(!ptep))
10981107
return -EFAULT;
@@ -1117,9 +1126,13 @@ EXPORT_SYMBOL(set_pgste_bits);
11171126
*/
11181127
int get_pgste(struct mm_struct *mm, unsigned long hva, unsigned long *pgstep)
11191128
{
1129+
struct vm_area_struct *vma;
11201130
spinlock_t *ptl;
11211131
pte_t *ptep;
11221132

1133+
vma = find_vma(mm, hva);
1134+
if (!vma || hva < vma->vm_start || is_vm_hugetlb_page(vma))
1135+
return -EFAULT;
11231136
ptep = get_locked_pte(mm, hva, &ptl);
11241137
if (unlikely(!ptep))
11251138
return -EFAULT;

0 commit comments

Comments
 (0)