Return-Path: Received: from mail-by2nam01on0139.outbound.protection.outlook.com ([104.47.34.139]:60384 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754815AbeARVAb (ORCPT ); Thu, 18 Jan 2018 16:00:31 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Sebastian Ott , Martin Schwidefsky , Sasha Levin Subject: [added to the 4.1 stable tree] s390/pci: fix use after free in dma_init Date: Thu, 18 Jan 2018 20:59:53 +0000 Message-ID: <20180118205908.3220-56-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Sebastian Ott This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit dba599091c191d209b1499511a524ad9657c0e5a ] After a failure during registration of the dma_table (because of the function being in error state) we free its memory but don't reset the associated pointer to zero. When we then receive a notification from firmware (about the function being in error state) we'll try to walk and free the dma_table again. Fix this by resetting the dma_table pointer. In addition to that make sure that we free the iommu_bitmap when appropriate. Signed-off-by: Sebastian Ott Reviewed-by: Gerald Schaefer Signed-off-by: Martin Schwidefsky Signed-off-by: Sasha Levin --- arch/s390/pci/pci_dma.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c index 6fd8d5836138..888cc878efaa 100644 --- a/arch/s390/pci/pci_dma.c +++ b/arch/s390/pci/pci_dma.c @@ -432,7 +432,7 @@ int zpci_dma_init_device(struct zpci_dev *zdev) zdev->dma_table =3D dma_alloc_cpu_table(); if (!zdev->dma_table) { rc =3D -ENOMEM; - goto out_clean; + goto out; } =20 zdev->iommu_size =3D (unsigned long) high_memory - PAGE_OFFSET; @@ -440,7 +440,7 @@ int zpci_dma_init_device(struct zpci_dev *zdev) zdev->iommu_bitmap =3D vzalloc(zdev->iommu_pages / 8); if (!zdev->iommu_bitmap) { rc =3D -ENOMEM; - goto out_reg; + goto free_dma_table; } =20 rc =3D zpci_register_ioat(zdev, @@ -449,12 +449,16 @@ int zpci_dma_init_device(struct zpci_dev *zdev) zdev->start_dma + zdev->iommu_size - 1, (u64) zdev->dma_table); if (rc) - goto out_reg; - return 0; + goto free_bitmap; =20 -out_reg: + return 0; +free_bitmap: + vfree(zdev->iommu_bitmap); + zdev->iommu_bitmap =3D NULL; +free_dma_table: dma_free_cpu_table(zdev->dma_table); -out_clean: + zdev->dma_table =3D NULL; +out: return rc; } =20 --=20 2.11.0