1
0
Fork 0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-01-26 18:43:33 -05:00
linux/arch/powerpc/mm
Alexey Kardashevskiy 76fa4975f3 KVM: PPC: Check if IOMMU page is contained in the pinned physical page
A VM which has:
 - a DMA capable device passed through to it (eg. network card);
 - running a malicious kernel that ignores H_PUT_TCE failure;
 - capability of using IOMMU pages bigger that physical pages
can create an IOMMU mapping that exposes (for example) 16MB of
the host physical memory to the device when only 64K was allocated to the VM.

The remaining 16MB - 64K will be some other content of host memory, possibly
including pages of the VM, but also pages of host kernel memory, host
programs or other VMs.

The attacking VM does not control the location of the page it can map,
and is only allowed to map as many pages as it has pages of RAM.

We already have a check in drivers/vfio/vfio_iommu_spapr_tce.c that
an IOMMU page is contained in the physical page so the PCI hardware won't
get access to unassigned host memory; however this check is missing in
the KVM fastpath (H_PUT_TCE accelerated code). We were lucky so far and
did not hit this yet as the very first time when the mapping happens
we do not have tbl::it_userspace allocated yet and fall back to
the userspace which in turn calls VFIO IOMMU driver, this fails and
the guest does not retry,

This stores the smallest preregistered page size in the preregistered
region descriptor and changes the mm_iommu_xxx API to check this against
the IOMMU page size.

This calculates maximum page size as a minimum of the natural region
alignment and compound page size. For the page shift this uses the shift
returned by find_linux_pte() which indicates how the page is mapped to
the current userspace - if the page is huge and this is not a zero, then
it is a leaf pte and the page is mapped within the range.

Fixes: 121f80ba68 ("KVM: PPC: VFIO: Add in-kernel acceleration for VFIO")
Cc: stable@vger.kernel.org # v4.12+
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2018-07-18 16:17:17 +10:00
..
8xx_mmu.c
40x_mmu.c
44x_mmu.c
copro_fault.c
dma-noncoherent.c
drmem.c
dump_hashpagetable.c
dump_linuxpagetables.c
fault.c powerpc updates for 4.18 2018-06-07 10:23:33 -07:00
fsl_booke_mmu.c
hash64_4k.c
hash64_64k.c
hash_low_32.S
hash_native_64.c
hash_utils_64.c
highmem.c
hugepage-hash64.c
hugetlbpage-book3e.c
hugetlbpage-hash64.c
hugetlbpage-radix.c
hugetlbpage.c powerpc/mm/hash/4k: Free hugetlb page table caches correctly. 2018-06-20 09:13:25 +10:00
init-common.c
init_32.c
init_64.c
Makefile
mem.c treewide: use PHYS_ADDR_MAX to avoid type casting ULLONG_MAX 2018-06-15 07:55:25 +09:00
mmap.c
mmu_context.c powerpc/64s/radix: optimise pte_update 2018-06-03 20:40:36 +10:00
mmu_context_book3s64.c
mmu_context_hash32.c
mmu_context_iommu.c KVM: PPC: Check if IOMMU page is contained in the pinned physical page 2018-07-18 16:17:17 +10:00
mmu_context_nohash.c powerpc/mm: Remove stale_map[] handling on non SMP processors 2018-06-04 00:39:16 +10:00
mmu_decl.h
numa.c treewide: kzalloc() -> kcalloc() 2018-06-12 16:19:22 -07:00
pgtable-book3e.c
pgtable-book3s64.c powerpc/mm/hash/4k: Free hugetlb page table caches correctly. 2018-06-20 09:13:25 +10:00
pgtable-hash64.c
pgtable-radix.c powerpc/64s/radix: avoid ptesync after set_pte and ptep_set_access_flags 2018-06-03 20:40:36 +10:00
pgtable.c powerpc/mm/hugetlb: Update hugetlb related locks 2018-06-03 20:40:37 +10:00
pgtable_32.c
pgtable_64.c
pkeys.c powerpc/pkeys: Detach execute_only key on !PROT_EXEC 2018-06-05 11:03:25 +10:00
ppc_mmu_32.c
slb.c powerpc/mm/hash: hard disable irq in the SLB insert path 2018-06-03 20:40:38 +10:00
slb_low.S
slice.c
subpage-prot.c powerpc: Remove -Wattribute-alias pragmas 2018-06-25 23:21:13 +09:00
tlb-radix.c powerpc/64s/radix: Fix radix_kvm_prefetch_workaround paca access of not possible CPU 2018-06-20 09:13:25 +10:00
tlb_hash32.c
tlb_hash64.c
tlb_low_64e.S
tlb_nohash.c
tlb_nohash_low.S
vphn.c
vphn.h