From patchwork Sun Oct 1 03:54:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dinghao Liu X-Patchwork-Id: 13405276 X-Patchwork-Delegate: kw@linux.com 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 C3CB0E748E9 for ; Sun, 1 Oct 2023 03:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229481AbjJADzP (ORCPT ); Sat, 30 Sep 2023 23:55:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjJADzO (ORCPT ); Sat, 30 Sep 2023 23:55:14 -0400 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED4CADD; Sat, 30 Sep 2023 20:55:09 -0700 (PDT) Received: from localhost.localdomain (unknown [10.192.195.11]) by mail-app3 (Coremail) with SMTP id cC_KCgBXPcCC7RhlwbwsAQ--.29716S4; Sun, 01 Oct 2023 11:54:48 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn Cc: Toan Le , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas , Tanmay Inamdar , Marc Zyngier , Duc Dang , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v3] PCI: xgene-msi: Fix a potential UAF in xgene_msi_probe Date: Sun, 1 Oct 2023 11:54:40 +0800 Message-Id: <20231001035441.30408-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: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vfC2KfnxnU UI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: qrrzjiaqtzq6lmxovvfxof0/1tbiAgwPBmUYLyEI2AAAsk Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org xgene_allocate_domains() will call irq_domain_remove() to free msi->inner_domain on failure. However, its caller, xgene_msi_probe(), will also call irq_domain_remove() through xgene_msi_remove() on the same failure, which may lead to a use-after-free. Remove the first irq_domain_remove() and let xgene_free_domains() cleanup domains. Fixes: dcd19de36775 ("PCI: xgene: Add APM X-Gene v1 PCIe MSI/MSIX termination driver") Signed-off-by: Dinghao Liu --- Changelog: v2: -Remove irq_domain_remove() instead of nulling msi_domain. v3: -Add 'v3' tag in the title. --- drivers/pci/controller/pci-xgene-msi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-xgene-msi.c b/drivers/pci/controller/pci-xgene-msi.c index 3ce38dfd0d29..0f9b9394399d 100644 --- a/drivers/pci/controller/pci-xgene-msi.c +++ b/drivers/pci/controller/pci-xgene-msi.c @@ -251,10 +251,8 @@ static int xgene_allocate_domains(struct xgene_msi *msi) &xgene_msi_domain_info, msi->inner_domain); - if (!msi->msi_domain) { - irq_domain_remove(msi->inner_domain); + if (!msi->msi_domain) return -ENOMEM; - } return 0; }