From patchwork Tue Dec 7 04:31:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yf.wang@mediatek.com X-Patchwork-Id: 521952 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BD2DC433F5 for ; Tue, 7 Dec 2021 04:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236145AbhLGEkA (ORCPT ); Mon, 6 Dec 2021 23:40:00 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:38678 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S236121AbhLGEkA (ORCPT ); Mon, 6 Dec 2021 23:40:00 -0500 X-UUID: d6245042be1e404a95d23e2807e35f31-20211207 X-UUID: d6245042be1e404a95d23e2807e35f31-20211207 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1939152083; Tue, 07 Dec 2021 12:36:26 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 7 Dec 2021 12:36:25 +0800 Received: from mbjsdccf07.mediatek.inc (10.15.20.246) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 7 Dec 2021 12:36:24 +0800 From: To: Will Deacon , Robin Murphy , "Joerg Roedel" , Matthias Brugger , Jean-Philippe Brucker , "moderated list:ARM SMMU DRIVERS" , "open list:IOMMU DRIVERS" , open list , "moderated list:ARM/Mediatek SoC support" CC: , Libo Kang , Yong Wu , Guangming Cao , "Yunfei Wang" , Subject: [PATCH v2] iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure Date: Tue, 7 Dec 2021 12:31:14 +0800 Message-ID: <20211207043116.27319-1-yf.wang@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Yunfei Wang 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: 29859aeb8a6ea ("iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE") Signed-off-by: Yunfei Wang Cc: # 5.10.* --- V2: Cc stable@vger.kernel.org 1. This patch needs to be merged stable branch, add stable@vger.kernel.org in mail list. 2. There is No new code change in V2. --- drivers/iommu/io-pgtable-arm-v7s.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c index bfb6acb651e5..d84240308f4b 100644 --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -246,6 +246,12 @@ static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp, __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size)); else if (lvl == 2) table = kmem_cache_zalloc(data->l2_tables, gfp); + + if (!table) { + dev_err(dev, "Page table allocation failure lvl:%d\n", lvl); + return NULL; + } + phys = virt_to_phys(table); if (phys != (arm_v7s_iopte)phys) { /* Doesn't fit in PTE */