Received: by 10.213.65.68 with SMTP id h4csp2123318imn; Sun, 8 Apr 2018 20:16:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx485n3x7ny9/Wj25gP6aTpEffyH/cCaBo/X02aQGMpcWwIvJBtkMKXLW5rFtGAxsQZct0K/Z X-Received: by 10.99.113.70 with SMTP id b6mr7480792pgn.126.1523243811501; Sun, 08 Apr 2018 20:16:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243811; cv=none; d=google.com; s=arc-20160816; b=BhOp20ScVKfEKeA4uOTIyuNLDqKFCdClUhyk2BYW3YKhpvcoU9JYGYV39Q4Bf+vmuQ AWELf4lcPoOaORH9v2rxAiYlf5cDS5mqtgj1TqDtWVI1UPc4AO7IyeMTgtUgkQGxRk0D fzvPPjUHUtVf0P8Kbokc3Te1JyB7sAKD7+5QdC2VMCn1BF9Q8LCAXX/POJkRkqeCNlHO 0ZErYnFQg5HsGXs7NuZxO73RWdfAm6Zn/2RcOMpG12F34zBlaCoEhhqDCKkI6ksf3Rv3 OKYtzQJ8u91QglgWjavUfvnwu+qxXwkAh929acOlf7UxtCjlbfbdvaYh+SeVPElr7Pq4 7a/g== 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=zvhmGgXOI/lO4b9NHhX+WZ4rzYaFveKUUu64lWvYCOI=; b=rBIqssoAPgnqwRTClE1yod2wMMWXJAaIGyNfrNTS7QF9rs3WWFPtdVcmsXWYKW5L0l tF2sLIpNYFGJPslAHL6wHxnD+FO+sUSbRGVNvJp2HOTlviCGQMT94O7MD82Op6TnvKj7 Uo273tm9qq1L0d7NJ1xEiVUM2fuPenwc0i8APCbyXKmkWILi6K8TAwZIP8kdYJMNXImO KDvjUqQox+lEFnqaJlbmQUIZ7XHeiipRGMt5LuuFPhiakUSRpr8yiaOttFuHl7d7VWtl P4i46cm5P37m9epZb/wBvpxdAQH6tF8BRfd1URpzmxar9H3zC9SYBl9EimOUBLTWacfV z3XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=V3lSrDlR; 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 a1-v6si2068249plp.22.2018.04.08.20.16.15; Sun, 08 Apr 2018 20:16:51 -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=V3lSrDlR; 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 S1752627AbeDIDDf (ORCPT + 99 others); Sun, 8 Apr 2018 23:03:35 -0400 Received: from mail-sn1nam02on0136.outbound.protection.outlook.com ([104.47.36.136]:19528 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755097AbeDIAYx (ORCPT ); Sun, 8 Apr 2018 20:24:53 -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=zvhmGgXOI/lO4b9NHhX+WZ4rzYaFveKUUu64lWvYCOI=; b=V3lSrDlRWTGhog/nxzddENEl+m3tKvf5ihkvBca120TuuYs1HpEElMyG0gtR4DKV074mzz4XyXS+Pm6/7ymTu9+554SQo8rJXXOwXV2QqhOYsPtxQLmSM2NiHdilbmBV7Qw9tFgk1RtwLEgxNINqoPHnvPnWaILyvjsvN7D4YPs= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0983.namprd21.prod.outlook.com (52.132.133.29) 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:24:48 +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:24:47 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Alex Estrin , Jason Gunthorpe , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 109/161] IB/hfi1: Fix for potential refcount leak in hfi1_open_file() Thread-Topic: [PATCH AUTOSEL for 4.14 109/161] IB/hfi1: Fix for potential refcount leak in hfi1_open_file() Thread-Index: AQHTz5ivrM+zK9JbsECxT+DJykjAkg== Date: Mon, 9 Apr 2018 00:21:21 +0000 Message-ID: <20180409001936.162706-109-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-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;DM5PR2101MB0983;7:eLYKjq89GghhwxrEnt386W1idAjl5wZenb6XGXdMn3AIi1haN2UbuRg4Q8MBuMU/OTwxCUKQl4njNyn48egOE7ciMhQNujnNqSXyMm5HPqW5LIrewLxR22+KWxbOi+8Fa0HWqDkxSPPEuLP8DHITQNDmueqxyDcqT25QD8fgEBY3Xy/Z2ez0fIzRUds2LZoUB6BmwZTP5Zwk5XeKeCEKgjH7qJZqAptpRPC3pV4zHY3+vNqZOxdS+54HU3fK/jTs;20:7ITSAOWyQxbw3lsrw9L+91YfrohXQm02+EomNLncMaMXZ/TpV9M9GUla3UyR5lsQ//au0ugKw8i/yfGkYgDes0cvI2aMdn+2+EZGGLYC4SzQ2zQ6BM43/ahMNh3GanPc2ZWgYq2/hpqasPDZitPPPdQRSfwilevHeazE3SYlmvk= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 7a5dcb9a-7a6d-46b9-81c1-08d59db04d50 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0983; x-ms-traffictypediagnostic: DM5PR2101MB0983: 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)(228905959029699); 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:DM5PR2101MB0983;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0983; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(346002)(376002)(39380400002)(366004)(199004)(189003)(478600001)(72206003)(10290500003)(3846002)(102836004)(6506007)(6116002)(25786009)(6436002)(66066001)(99286004)(54906003)(86612001)(6666003)(105586002)(53936002)(76176011)(316002)(486006)(7736002)(22452003)(3660700001)(86362001)(97736004)(106356001)(8936002)(110136005)(5660300001)(11346002)(446003)(81166006)(81156014)(2906002)(8676002)(2900100001)(1076002)(476003)(2616005)(10090500001)(6486002)(107886003)(36756003)(4326008)(2501003)(68736007)(186003)(305945005)(3280700002)(5250100002)(6512007)(26005)(14454004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0983;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: rVkxZKbOCtyMyiEWFf0rs8YfK4ocrxncNRs5lnfZp1KdPktqaz5PyToV0CI/Kvwokq9ngRSaOWYHP6AjJof4Kp0haImhJTQyCNutiyq6OO8ALTeTdIN0E4JyocuiXk+J6EZ7szX3phwg29UgtJJj0zEJGg5OEKUhTHsHy0Bv2B4+WWyhcyY5lCW4RMNByvDjB5KcRH9Z5v34XcW8ij+ihmFUWZJKylS9KV2wmw7i+zHqGQWw/boy2Ejr2fy7BQWv+V/ZBOGX4048+yekd8kpP5g1RwqBeXhNG0vfuNMr3uNTk1x+Cp//lEizesTMWRburb5e1rTOBpsIm/QFiuRom//I6ItZ9x0DFir79uzepG6tHLFQi3wMs1cmjoqiKwK7T+X6vmEXVnVI+Ipqsm+8RgK4ZP86qyBjSHdOe7E+eJo= 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: 7a5dcb9a-7a6d-46b9-81c1-08d59db04d50 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:21.4718 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0983 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Estrin [ Upstream commit 2b1e7fe16124e86ee9242aeeee859c79a843e3a2 ] The dd refcount is speculatively incremented prior to allocating the fd memory with kzalloc(). If that kzalloc() failed the dd refcount leaks. Increment refcount on kzalloc success. Fixes: e11ffbd57520 ("IB/hfi1: Do not free hfi1 cdev parent structure early= ") Reviewed-by: Michael J Ruhl Signed-off-by: Alex Estrin Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/file_ops.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/= hfi1/file_ops.c index fd28f09b4445..ee2253d06984 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -191,9 +191,6 @@ static int hfi1_file_open(struct inode *inode, struct f= ile *fp) if (!atomic_inc_not_zero(&dd->user_refcount)) return -ENXIO; =20 - /* Just take a ref now. Not all opens result in a context assign */ - kobject_get(&dd->kobj); - /* The real work is performed later in assign_ctxt() */ =20 fd =3D kzalloc(sizeof(*fd), GFP_KERNEL); @@ -203,6 +200,7 @@ static int hfi1_file_open(struct inode *inode, struct f= ile *fp) fd->mm =3D current->mm; mmgrab(fd->mm); fd->dd =3D dd; + kobject_get(&fd->dd->kobj); fp->private_data =3D fd; } else { fp->private_data =3D NULL; --=20 2.15.1