Received: by 10.213.65.68 with SMTP id h4csp2115759imn; Sun, 8 Apr 2018 20:06:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx48avUWbT8TiYAp5fMuUTNGNZySThQar+i9HdsIkxiB6oenh6GQqPJEWj+jGVYbLE+NhUbTS X-Received: by 10.99.123.78 with SMTP id k14mr23471579pgn.67.1523243190689; Sun, 08 Apr 2018 20:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243190; cv=none; d=google.com; s=arc-20160816; b=E+tEYTp2Q6nc+WPtumyHhIkhMtfh3Mu1NhDaU4t48/zGKKVNAtDvIs2LN7TSbVP3XE HZIzONiZdK7aBjDzw+7djcxAXf5StA1NK3cMaYCkRCb0qoxhLfd1dXV2RWhAiK92J6bu Pzrb0gsVl4wLWXrrWUcuYA/MLebKIVD4aMu8jUP2NWGYBPRUxLGRslTkKBNflYMDuUdr HJUCX3cW5l3fzy6eatWvnkKCdHga19JOyLLGzkxIq485xMxJnCwsyuABO/HHssm2udUa yJf2wwF/AKC9zBAgtkJgObKvL8U88MzDdvCBcQShVLrrrHbU3BbF7NGUvrQVCOmeCgPE y8mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=4i+UXHWHhB1L4Vt9UTrP5O2z3Dsw9prpIooljoLUbUE=; b=fpnGPIqr7+TbYGSkHgd28P2LYlffN9nLguBMKM7mbeZ5/GTfL+MLrQZmBwiTpvShjp q8UFp3MFB9c9WL7aknCOzLJcLFTmyut8skaLYhOXIxPeTFwvZEq4+wGqQjLeXTbMFGej gZKjJxtFg86R0ykKi39nslZe9kGhi1oZk7pZM7V75g+lfjYWlxf2NIny3fVs8AgRnQyO TRyOaVgpRBFpOEijaDXZ2jUjPR67GIiR/aHBCnxHQwqNAfFVq0meJ+lkc7p9w43+CyNE Pj4pSt0i6UXVMiVhRjOkpEPnX4FFwI1R3c33ZBvmSYhEhkBsf6AkHq1tvyDvTjcBT/o/ vuoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=QA00U2yd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si10384382pgt.130.2018.04.08.20.05.53; Sun, 08 Apr 2018 20:06:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=QA00U2yd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755275AbeDIAbU (ORCPT + 99 others); Sun, 8 Apr 2018 20:31:20 -0400 Received: from mail-by2nam03on0135.outbound.protection.outlook.com ([104.47.42.135]:16544 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756192AbeDIAbM (ORCPT ); Sun, 8 Apr 2018 20:31:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=4i+UXHWHhB1L4Vt9UTrP5O2z3Dsw9prpIooljoLUbUE=; b=QA00U2ydmnz/5MuEtLb5csZJ3/h50/7wx69QplMwpTNsbcjD6neaC65jNE22VNfbRtbQ179iqp04T+0vE7fiH4nZOj0F3NpAK158MpqgLJ6SsQzLYHTvCtR0Uj3AMsblZmKY9uX/iVqhtOeUeUlIK30qrthbhwBMpV8s6Olu12w= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0917.namprd21.prod.outlook.com (52.132.132.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:31:10 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:31:10 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Sebastian Ott , Martin Schwidefsky , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 158/293] s390/pci: improve unreg_ioat error handling Thread-Topic: [PATCH AUTOSEL for 4.9 158/293] s390/pci: improve unreg_ioat error handling Thread-Index: AQHTz5kvETJh8c/cx0m2OzfjOOBGgQ== Date: Mon, 9 Apr 2018 00:24:56 +0000 Message-ID: <20180409002239.163177-158-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0917;7:50W5J6zSgRSzG4ncS8JEXz4e99gQf/l8ZyswnbK4cTzl7itmAKVLofkbZGTwRKsySNKTCqJ41iu4uoUcsVBqzHrm4LSxYFqFTen7OZnfPzoEM+PebGAZkLoj88cZO0f4g2yeTWUvg8ECg5MV9xxRmoCw/19HgKJgVxxBl2oLeTZu0Bc8pXrqdBxJmAyXrLdMk7aTKul+9nExcj77M3LmsrRk4iJIYe6cdS5MKvQr4SixmxJV2VuzV8Nwj35sRHQM;20:Nfoe/cmQxYOvLb2pVnzEtfxWTafmrPwf1BDwIaqM71Pb71nImgNSMezLsStadAwimo/AWxI9uwM+4EFZrkZwqsdpWeSTg0y5monVCHHf2c6A4PrsVCR630CGePulkPM78WP3LijkrxpVQHdHg3W6186KjnB5X39P1colDPNGxBo= X-MS-Office365-Filtering-Correlation-Id: a0812d03-22c4-43c5-0f7f-08d59db13117 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB0917; x-ms-traffictypediagnostic: DM5PR2101MB0917: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(190383065149520)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0917;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0917; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(366004)(396003)(346002)(376002)(189003)(199004)(99286004)(22452003)(106356001)(26005)(110136005)(478600001)(54906003)(10290500003)(316002)(1076002)(72206003)(186003)(4326008)(97736004)(66066001)(11346002)(25786009)(86362001)(476003)(446003)(2906002)(6666003)(6486002)(105586002)(86612001)(3280700002)(3660700001)(6512007)(3846002)(6116002)(6436002)(2616005)(486006)(53936002)(7736002)(8676002)(81166006)(81156014)(8936002)(68736007)(305945005)(10090500001)(76176011)(6506007)(102836004)(36756003)(107886003)(59450400001)(2900100001)(2501003)(14454004)(5660300001)(5250100002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0917;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: xmxdGS4q2833DPj3B2YhW6yesbBBXLzh0ktJ2WboknFdphxb/hut5JxJ/O/t5h5eKl7IcPg21ra25m1QWDzl696aGHa4vsKRutbxpHOvf5rektiXvuJw2V88cBnBR93bLBmlyO+9o1G+dItIGbuE4TGOOq+BuXzjRueIxISaa+2eGNTfhn+KoFNWtOA7hDCUR2wLV3I8YIe1Mbk465FL4l8T7aHnbQU9NfqfXMLG6p0JwekmTitYQ2807UVqi+aPfx6+WFb1LUg4nBLTvI+WSrUlKPHUFFxuj+hZV3ZlD8Or2rNB2USBhWxVFvWEyF6WzRj0I4eOt1zh4TqAQ1aN3wFxkluoO9bOU7K2/tziVLI8zAAuKyQk8DR6uXRYb/8KCl1mAjQzm1o9fgXjzhsLS8EYBQH7JDbglWcBJ8rKubs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0812d03-22c4-43c5-0f7f-08d59db13117 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:56.4876 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0917 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian Ott [ Upstream commit 725708349172f00b86e2bac5c03de360b79aaf65 ] DMA tables are freed in zpci_dma_exit_device regardless of the return code of zpci_unregister_ioat. This could lead to a use after free. On the other hand during function hot-unplug, zpci_unregister_ioat will always fail since the function is already gone. So let zpci_unregister_ioat report success when the function is gone but don't cleanup the dma table when a function could still have it in access. Signed-off-by: Sebastian Ott Reviewed-by: Gerald Schaefer Signed-off-by: Martin Schwidefsky Signed-off-by: Sasha Levin --- arch/s390/pci/pci.c | 19 ++++++++++++++----- arch/s390/pci/pci_dma.c | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 17f81991ee9b..c22b4734fc12 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -169,19 +169,28 @@ static int mod_pci(struct zpci_dev *zdev, int fn, u8 = dmaas, struct mod_pci_args int zpci_register_ioat(struct zpci_dev *zdev, u8 dmaas, u64 base, u64 limit, u64 iota) { - struct mod_pci_args args =3D { base, limit, iota, 0 }; + u64 req =3D ZPCI_CREATE_REQ(zdev->fh, dmaas, ZPCI_MOD_FC_REG_IOAT); + struct zpci_fib fib =3D {0}; + u8 status; =20 WARN_ON_ONCE(iota & 0x3fff); - args.iota |=3D ZPCI_IOTA_RTTO_FLAG; - return mod_pci(zdev, ZPCI_MOD_FC_REG_IOAT, dmaas, &args); + fib.pba =3D base; + fib.pal =3D limit; + fib.iota =3D iota | ZPCI_IOTA_RTTO_FLAG; + return zpci_mod_fc(req, &fib, &status) ? -EIO : 0; } =20 /* Modify PCI: Unregister I/O address translation parameters */ int zpci_unregister_ioat(struct zpci_dev *zdev, u8 dmaas) { - struct mod_pci_args args =3D { 0, 0, 0, 0 }; + u64 req =3D ZPCI_CREATE_REQ(zdev->fh, dmaas, ZPCI_MOD_FC_DEREG_IOAT); + struct zpci_fib fib =3D {0}; + u8 cc, status; =20 - return mod_pci(zdev, ZPCI_MOD_FC_DEREG_IOAT, dmaas, &args); + cc =3D zpci_mod_fc(req, &fib, &status); + if (cc =3D=3D 3) /* Function already gone. */ + cc =3D 0; + return cc ? -EIO : 0; } =20 /* Modify PCI: Set PCI function measurement parameters */ diff --git a/arch/s390/pci/pci_dma.c b/arch/s390/pci/pci_dma.c index 049e3860ac54..be17f05f645e 100644 --- a/arch/s390/pci/pci_dma.c +++ b/arch/s390/pci/pci_dma.c @@ -600,7 +600,9 @@ void zpci_dma_exit_device(struct zpci_dev *zdev) */ WARN_ON(zdev->s390_domain); =20 - zpci_unregister_ioat(zdev, 0); + if (zpci_unregister_ioat(zdev, 0)) + return; + dma_cleanup_tables(zdev->dma_table); zdev->dma_table =3D NULL; vfree(zdev->iommu_bitmap); --=20 2.15.1