Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure

In __arm_v7s_alloc_table function:
iommu call kmem_cache_alloc to allocate page table, this function
allocate memory may fail, when kmem_cache_alloc fails to allocate
table, call virt_to_phys will be abnomal and return unexpected phys
and goto out_free, then call kmem_cache_free to release table will
trigger KE, __get_free_pages and free_pages have similar problem,
so add error handle for page table allocation failure.

Fixes: 29859aeb8a6e ("iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE")
Signed-off-by: Yunfei Wang <yf.wang@mediatek.com>
Cc: <stable@vger.kernel.org> # 5.10.*
Acked-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20211207113315.29109-1-yf.wang@mediatek.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Yunfei Wang and committed by
Will Deacon
a556cfe4 17d9a4b4

+5 -1
+5 -1
drivers/iommu/io-pgtable-arm-v7s.c
··· 246 246 __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size)); 247 247 else if (lvl == 2) 248 248 table = kmem_cache_zalloc(data->l2_tables, gfp); 249 + 250 + if (!table) 251 + return NULL; 252 + 249 253 phys = virt_to_phys(table); 250 254 if (phys != (arm_v7s_iopte)phys) { 251 255 /* Doesn't fit in PTE */ 252 256 dev_err(dev, "Page table does not fit in PTE: %pa", &phys); 253 257 goto out_free; 254 258 } 255 - if (table && !cfg->coherent_walk) { 259 + if (!cfg->coherent_walk) { 256 260 dma = dma_map_single(dev, table, size, DMA_TO_DEVICE); 257 261 if (dma_mapping_error(dev, dma)) 258 262 goto out_free;