Skip to content

Commit 0680674

Browse files
yunfeimmgregkh
authored andcommitted
iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure
commit a556cfe upstream. 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: 29859ae ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3dae11f commit 0680674

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎drivers/iommu/io-pgtable-arm-v7s.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,17 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
242242
__GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size));
243243
else if (lvl == 2)
244244
table = kmem_cache_zalloc(data->l2_tables, gfp);
245+
246+
if (!table)
247+
return NULL;
248+
245249
phys = virt_to_phys(table);
246250
if (phys != (arm_v7s_iopte)phys) {
247251
/* Doesn't fit in PTE */
248252
dev_err(dev, "Page table does not fit in PTE: %pa", &phys);
249253
goto out_free;
250254
}
251-
if (table && !cfg->coherent_walk) {
255+
if (!cfg->coherent_walk) {
252256
dma = dma_map_single(dev, table, size, DMA_TO_DEVICE);
253257
if (dma_mapping_error(dev, dma))
254258
goto out_free;

0 commit comments

Comments
 (0)