OSDN Git Service

s390/mm: validate VMA in PGSTE manipulation functions
authorDavid Hildenbrand <david@redhat.com>
Thu, 9 Sep 2021 16:22:42 +0000 (18:22 +0200)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Mon, 25 Oct 2021 07:20:38 +0000 (09:20 +0200)
commitfe3d10024073f06f04c74b9674bd71ccc1d787cf
treec8d2ea4cb92999c5d6e80f73c94f7ccc67d87425
parentb159f94c86b43cf7e73e654bc527255b1f4eafc4
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().

Fixes: 2d42f9477320 ("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>
arch/s390/mm/pgtable.c