Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2895732pxb; Tue, 24 Aug 2021 10:04:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR3ct/qsRWjBtx0j3JUDHxkZ0XQwMZ/cY5Q2bMKy5A4HUBywOIGqxj7VI4Fd/DwFonTuya X-Received: by 2002:a17:906:7714:: with SMTP id q20mr42392933ejm.551.1629824687461; Tue, 24 Aug 2021 10:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629824687; cv=none; d=google.com; s=arc-20160816; b=x3Deh98zKvYBsP2VQzEBrcjnCgy0ELcUUPWSrpZ7lvrD8J8YHr4nQmLGv7Q6HS0+pI 4ukL+EAwt7Wx0REPeTsESnbTHaMVYegm3gzMIsKbfEYZPKBB3iOtmo4TCDjxc6/SJ+CL A/CCvg0ZTE18UZvIJYI5RIzQSx4gEs7cjBTiPv0nNw35rCwhDWpTCrlcrZQRV7ZtDD+g MKlFOSmXEJOmyYWfdtGwJNjudnIzkEFF7LE3gB1/vHhSYvU8ToiPWMIv3mZJBvMgjNHM Ju/LSTDdrLKJM5bH3qMHWTmv/ZwYDfMCobDAOUyTSS8a65WYH9Q7OkJhG9EeWXP4d3w7 7DyQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uoTyY+Mm13ruLSpGIeXdBiXTWyXIONChMBppxu7G+RU=; b=nRM4G02v1hzovwce1KOJwieqsWi803z1V4H7qhamICmRSYsv1t9Keqnd0IzK5Hb+IE XegKcjDlA4gq0r/WYNrqnDLSTxSZydu+n4SVAoJ7aC/wPPy1Ea1acS0fmqfsOhxo+t+S tYQ4cUgy2eA8X7x/obG0vq/nwppCa3pi3nvoVfBY8ky/Igr2LQSFeNFtMk2u+ZvnvWOG w34pLVIw82nVJH3iWVl10Arqvk0uYMmR5kH7wOPQG2oM/b5VUxuPtC5flKiYZVd9lx5p TKLZ9gdIN9KKI8qhfROuoQGCkwKwBBgT3a0F+155uz+0quIp5wuFNEJCCfkpQBm36MA/ zuHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qxoauR7u; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si1766351edb.149.2021.08.24.10.04.23; Tue, 24 Aug 2021 10:04:47 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=qxoauR7u; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbhHXRDl (ORCPT + 99 others); Tue, 24 Aug 2021 13:03:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:39218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238541AbhHXRAY (ORCPT ); Tue, 24 Aug 2021 13:00:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3422061423; Tue, 24 Aug 2021 16:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629824266; bh=fIgXm5lMO8H0fbyfCXDDBANto3gNQUwWOSYpNyxVF0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qxoauR7uOp+fKWB8kAtQJU7DAB8uWktwN1g5Z6h8Pg+IsBFDIxVZ2o53mky/1GLxS TA85+RGY8exJVbp0N/lu/lzje5T0FSxvhYvEPvpjhw/KUPQIeqWAZQYcFOjzjmfI8j mo0Nm2jxQH4X8kGuiWJa4xxITRHRexH5qScpZFKP2Shb9nUBlAMJIZGe9WLrL2S+sw wmw8hd0ftrOCt5OzfA9mMLE9d72qa4oIv9YRC/7RxWVe7bS/4i/K9O9RYB9fGG54qe BPyXFTuprVyQFqG7mc5J7ML8UUIk5yt7ETrX59/I8Al7zEpVxqJQv47pS3Rl1+W646 Ogn2a/yug5eyg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.13 100/127] ipack: tpci200: fix many double free issues in tpci200_pci_probe Date: Tue, 24 Aug 2021 12:55:40 -0400 Message-Id: <20210824165607.709387-101-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210824165607.709387-1-sashal@kernel.org> References: <20210824165607.709387-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.13.13-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.13.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.13.13-rc1 X-KernelTest-Deadline: 2021-08-26T16:55+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 57a1681095f912239c7fb4d66683ab0425973838 ] The function tpci200_register called by tpci200_install and tpci200_unregister called by tpci200_uninstall are in pair. However, tpci200_unregister has some cleanup operations not in the tpci200_register. So the error handling code of tpci200_pci_probe has many different double free issues. Fix this problem by moving those cleanup operations out of tpci200_unregister, into tpci200_pci_remove and reverting the previous commit 9272e5d0028d ("ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe"). Fixes: 9272e5d0028d ("ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe") Cc: stable@vger.kernel.org Reported-by: Dongliang Mu Signed-off-by: Dongliang Mu Link: https://lore.kernel.org/r/20210810100323.3938492-1-mudongliangabcd@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/ipack/carriers/tpci200.c | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/ipack/carriers/tpci200.c b/drivers/ipack/carriers/tpci200.c index e1822e87ec3d..33a1b17a2628 100644 --- a/drivers/ipack/carriers/tpci200.c +++ b/drivers/ipack/carriers/tpci200.c @@ -91,16 +91,13 @@ static void tpci200_unregister(struct tpci200_board *tpci200) free_irq(tpci200->info->pdev->irq, (void *) tpci200); pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs); - pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs); pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR); pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR); pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR); pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR); - pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR); pci_disable_device(tpci200->info->pdev); - pci_dev_put(tpci200->info->pdev); } static void tpci200_enable_irq(struct tpci200_board *tpci200, @@ -529,7 +526,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev, tpci200->info = kzalloc(sizeof(struct tpci200_infos), GFP_KERNEL); if (!tpci200->info) { ret = -ENOMEM; - goto out_err_info; + goto err_tpci200; } pci_dev_get(pdev); @@ -540,7 +537,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev, if (ret) { dev_err(&pdev->dev, "Failed to allocate PCI Configuration Memory"); ret = -EBUSY; - goto out_err_pci_request; + goto err_tpci200_info; } tpci200->info->cfg_regs = ioremap( pci_resource_start(pdev, TPCI200_CFG_MEM_BAR), @@ -548,7 +545,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev, if (!tpci200->info->cfg_regs) { dev_err(&pdev->dev, "Failed to map PCI Configuration Memory"); ret = -EFAULT; - goto out_err_ioremap; + goto err_request_region; } /* Disable byte swapping for 16 bit IP module access. This will ensure @@ -571,7 +568,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev, if (ret) { dev_err(&pdev->dev, "error during tpci200 install\n"); ret = -ENODEV; - goto out_err_install; + goto err_cfg_regs; } /* Register the carrier in the industry pack bus driver */ @@ -583,7 +580,7 @@ static int tpci200_pci_probe(struct pci_dev *pdev, dev_err(&pdev->dev, "error registering the carrier on ipack driver\n"); ret = -EFAULT; - goto out_err_bus_register; + goto err_tpci200_install; } /* save the bus number given by ipack to logging purpose */ @@ -594,19 +591,16 @@ static int tpci200_pci_probe(struct pci_dev *pdev, tpci200_create_device(tpci200, i); return 0; -out_err_bus_register: +err_tpci200_install: tpci200_uninstall(tpci200); - /* tpci200->info->cfg_regs is unmapped in tpci200_uninstall */ - tpci200->info->cfg_regs = NULL; -out_err_install: - if (tpci200->info->cfg_regs) - iounmap(tpci200->info->cfg_regs); -out_err_ioremap: +err_cfg_regs: + pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs); +err_request_region: pci_release_region(pdev, TPCI200_CFG_MEM_BAR); -out_err_pci_request: - pci_dev_put(pdev); +err_tpci200_info: kfree(tpci200->info); -out_err_info: + pci_dev_put(pdev); +err_tpci200: kfree(tpci200); return ret; } @@ -616,6 +610,12 @@ static void __tpci200_pci_remove(struct tpci200_board *tpci200) ipack_bus_unregister(tpci200->info->ipack_bus); tpci200_uninstall(tpci200); + pci_iounmap(tpci200->info->pdev, tpci200->info->cfg_regs); + + pci_release_region(tpci200->info->pdev, TPCI200_CFG_MEM_BAR); + + pci_dev_put(tpci200->info->pdev); + kfree(tpci200->info); kfree(tpci200); } -- 2.30.2