iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE
authorJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Tue, 19 Jun 2018 12:52:24 +0000 (13:52 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Sep 2018 06:37:59 +0000 (08:37 +0200)
commit918cad16b45810da7b0d0fa605377630fa9ebedd
tree3143cace25a17bc2b7d8d0222d72422ff7385624
parentea4b3539ab5dfb449a951a38605b553762d34c89
iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE

[ Upstream commit 29859aeb8a6ea17ba207933a81b6b77b4d4df81a ]

When run on a 64-bit system in selftest, the v7s driver may obtain page
table with physical addresses larger than 32-bit. Level-2 tables are 1KB
and are are allocated with slab, which doesn't accept the GFP_DMA32
flag. Currently map() truncates the address written in the PTE, causing
iova_to_phys() or unmap() to access invalid memory. Kasan reports it as
a use-after-free. To avoid any nasty surprise, test if the physical
address fits in a PTE before returning a new table. 32-bit systems,
which are the main users of this page table format, shouldn't see any
difference.

Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iommu/io-pgtable-arm-v7s.c