Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3586221pxb; Mon, 24 Jan 2022 12:53:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJMCSYsP3f5t/P/qMl/ugzqZo24TbuXn0Zu879Ylvm8Cr57XrRQGkITMabyPxxtYXktFHb X-Received: by 2002:a17:902:e552:b0:149:b7bf:9b42 with SMTP id n18-20020a170902e55200b00149b7bf9b42mr15227611plf.70.1643057599127; Mon, 24 Jan 2022 12:53:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057599; cv=none; d=google.com; s=arc-20160816; b=Bfmv15dE82Ry3w2JfLDdbM75aTz4VGn5/Lmd2dqw7n7U07UCa2RXZ5Nx2ozg+tYXbJ RZevHchr4gN6DJINM8pSLfqrb/hUs7NEVmRP+VZhmwpM/M0VK4hx4nDDJviJCzBAWepY D1OGxLzNQYCa4pms0UZyptUJNuOXxllVTD66z1TvBPheZZQnPfMN/FZ6EwCkgq6SihuH S5ilBwEExBf6+ZLLRiQZ4zVAjENlRVHxOFLgLVxn+99TRQb5ZAvC1bFmybkCA/v34zDF lsHgc6C+k8ZLLijIFRDxGO4ZY/+TWREMxITVwGQ7XXbH6DK9YX9/MKywH7AIQunXJG/H Y0mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Itm1qhYKEpxH4RZHWkrN0iaeOmS9yC5N6jDI6/BF740=; b=vjO6LbSV1m09avLnbpTGho8npMoA/mdQeBvnvuMp3CHQcLeLzaI3Hvwm4RS4XvJdWN Tk/e8hzv2tNUFwQ9fBokYmRtl7yuYLmL7Xf/Ir6BCAHNbYHs/uqPr1730nfGOP+7CRGv SEgxHz1EPkg+7kIEISeXeHOGFmyUrpAe8Io3vIzrmjK0vmr23IUtVyDBtgDjdhCIdv2K EfBStJmvKbUd7LVGn4sP/iZs9HanU8f0UcSrLX5Spy2eHcz0/tJEFLmmq/HFyuZK8E/D sDU/dqi/85eQNcmGYPReY+9QzcIkscBrmGJsMJCjtFJxvochLu4j83qqR9vmmuIP1Juh ReZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F7+yRoJz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o8si13174719pgv.112.2022.01.24.12.53.07; Mon, 24 Jan 2022 12:53:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F7+yRoJz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377799AbiAXUKo (ORCPT + 99 others); Mon, 24 Jan 2022 15:10:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352597AbiAXTw7 (ORCPT ); Mon, 24 Jan 2022 14:52:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58B39C061397; Mon, 24 Jan 2022 11:26:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EA55C61490; Mon, 24 Jan 2022 19:26:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADDACC340E5; Mon, 24 Jan 2022 19:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052392; bh=Jz8l2tb5cXNmDSk3HR4LSQ6/l4bmgntUbC1cSU0TCuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7+yRoJzMJEmK4n4vmK7TRRqQIhwTC/SWUgnsf5Jn4ulssXU6reuOfa9sK+bkkhbr BTB3QHSQWjUNmroqODQRZseqwLU0bnA7TwvUggNFR18KwJ9SqB3/VKXC7kFBUViMxp EkBB4Es+v08cCJ2ormbE7swVrkdYEoUetJciw7jc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunfei Wang , Robin Murphy , Will Deacon Subject: [PATCH 5.4 026/320] iommu/io-pgtable-arm-v7s: Add error handle for page table allocation failure Date: Mon, 24 Jan 2022 19:40:10 +0100 Message-Id: <20220124183954.649197168@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunfei Wang commit a556cfe4cabc6d79cbb7733f118bbb420b376fe6 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: 29859aeb8a6e ("iommu/io-pgtable-arm-v7s: Abort allocation when table address overflows the PTE") Signed-off-by: Yunfei Wang Cc: # 5.10.* Acked-by: Robin Murphy Link: https://lore.kernel.org/r/20211207113315.29109-1-yf.wang@mediatek.com Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/io-pgtable-arm-v7s.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/iommu/io-pgtable-arm-v7s.c +++ b/drivers/iommu/io-pgtable-arm-v7s.c @@ -244,13 +244,17 @@ static void *__arm_v7s_alloc_table(int l __GFP_ZERO | ARM_V7S_TABLE_GFP_DMA, get_order(size)); else if (lvl == 2) table = kmem_cache_zalloc(data->l2_tables, gfp); + + if (!table) + return NULL; + phys = virt_to_phys(table); if (phys != (arm_v7s_iopte)phys) { /* Doesn't fit in PTE */ dev_err(dev, "Page table does not fit in PTE: %pa", &phys); goto out_free; } - if (table && !cfg->coherent_walk) { + if (!cfg->coherent_walk) { dma = dma_map_single(dev, table, size, DMA_TO_DEVICE); if (dma_mapping_error(dev, dma)) goto out_free;