Received: by 10.213.65.68 with SMTP id h4csp2144475imn; Sun, 8 Apr 2018 20:52:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx48alAAvf5uqzzMJ7CLr2FuLquvlXS0V1KuaeYw6+f6lNlia24P9hgTrTGhN2+718V5+8JLd X-Received: by 2002:a17:902:a9c4:: with SMTP id b4-v6mr37623548plr.333.1523245927627; Sun, 08 Apr 2018 20:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245927; cv=none; d=google.com; s=arc-20160816; b=hc9A8WB02xi1FgtJr7yzVOV0TvLvUtDiiIYSCR3J7ZEXgZ1tdLfE6E8kAa4qKKXY1c klGYLoz9vSp2x4NhDc9WMs7mQ3t8BTCjzHal2agl5GDKmM6FPwYY1bS/0MVL8/d8PUtn TLjpp1BWuOu45fJ0jNXzkNjFy+ZiTTo1Ff86aGUYhRXexPjd8d3WJkP4BsqCqHCyENi4 dSiFHP/ystjKOjtFFUZ3lGcG37zQY1Bn4elepFNKPHtKqM3Q/AYSBTMDxf/ZuiFkGMcL HvqArda9Q0vMvQD7l9JSLi/OZHLjSJz5VGus65dLIOGGqH4gSqfOzIs25/cYZ5iA74d4 WH0w== 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=HDMM9x4mRjf4rceQpxDfjrYFXwj1bdbHnO058vbUK3w=; b=RsbQYXRpeF4z6xbSdRqT8Jpem1KFI78g3JFLOCnLuMIVmqiM+mfH1N2shzi9TQh9aa hQk+HGPaD4rj03ZRw8Yl+WRBxG39I1y1B+rmalQuf6hvn+mcrPn8hE+vDpmSwYVlgTWk CoLrB4eSqqGAsxurU98MPLF8NtMnQpa7Dv2AjBJ340jCfWnmnDkhPeQO7310KyEB+S40 y1wzDWDg5IMcejIq3R8poTAW0GMqaWybVSBb/pGAHjLpGAH2Oe801q2x1Atx068RsRDc dWVFKRncOOM57nIUcJ7x4Y2UYbmK13DC8Gxv9L+yx8ViLWGEXROBuelFHKnH0PjVgXyi bBEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=iF5ayjrM; 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 9-v6si15774403plb.140.2018.04.08.20.51.30; Sun, 08 Apr 2018 20:52:07 -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=iF5ayjrM; 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 S1754531AbeDIDqU (ORCPT + 99 others); Sun, 8 Apr 2018 23:46:20 -0400 Received: from mail-cys01nam02on0118.outbound.protection.outlook.com ([104.47.37.118]:44776 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754083AbeDIAUP (ORCPT ); Sun, 8 Apr 2018 20:20:15 -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=HDMM9x4mRjf4rceQpxDfjrYFXwj1bdbHnO058vbUK3w=; b=iF5ayjrML8AUDR0+m3mBDE6E+Vhsu1akl44qfSdY3CFUTBsNV1ZCDmUMzu/tVJZg2t8ChaChF5eFcOb/ilmlViaEd0HWTHzWF4t5ZVGZz21rPsDOaA6nf0Qp4j9NOYmzC9gBaQx54dzbD91Qa6ijUUY8pikqOwV9RTwvV/P64UU= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1110.namprd21.prod.outlook.com (52.132.131.167) 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:20:11 +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:20:11 +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.15 131/189] IB/hfi1: Fix for potential refcount leak in hfi1_open_file() Thread-Topic: [PATCH AUTOSEL for 4.15 131/189] IB/hfi1: Fix for potential refcount leak in hfi1_open_file() Thread-Index: AQHTz5hKhPDLKs7v9kSV+yCkLiZhXA== Date: Mon, 9 Apr 2018 00:18:31 +0000 Message-ID: <20180409001637.162453-131-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB1110;7:FcT3jMG+yDxS6/9BnoCVv+ZBpIjzS1hXgRYFMbRX56LZPbOMY6Oznnd+/Oml9y4gywKgL+VPI4tptje+pkSn6YJzE9ysiI3fxhG2jUz+pgJpm7b3Qhh2x60tEirFDyhmuya95VmgMj3sauLK9jJt0Mx0v805k2SA62zVnTqwvp42mV9zvSgxklECbtd7YlhtS0TL4EZBZd68zbZXEyaE2RsK5lO4Gj5oj6EhACMOn25VSIJdYGqYsFvbqplYA5IS;20:qoZ8LDLP4P/1EhIK53gG9fiVktPar5SHruzh+ZG36RqYWJd1USPoycyVPzhaDOas9kdffj6gddtfubqJi+TU5iNUl/30wmccA3l0vx2p+HjmSJ4Lcxr6fyTARPRZe/XKYY8bBQQ6xRpdCdRdTxlOuvoq8YM3N/wp7FTxOk+T82g= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 420a4bf0-6baa-4e03-8bdd-08d59dafa859 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1110; x-ms-traffictypediagnostic: DM5PR2101MB1110: 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)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1110;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1110; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(376002)(366004)(346002)(396003)(39380400002)(39860400002)(199004)(189003)(5660300001)(478600001)(86612001)(3846002)(6116002)(106356001)(6486002)(72206003)(25786009)(10290500003)(8936002)(6436002)(76176011)(2616005)(6506007)(2900100001)(97736004)(486006)(26005)(36756003)(10090500001)(81166006)(8676002)(81156014)(102836004)(2906002)(99286004)(11346002)(476003)(3660700001)(66066001)(6512007)(575784001)(86362001)(53936002)(105586002)(186003)(5250100002)(14454004)(22452003)(6666003)(2501003)(446003)(7736002)(316002)(1076002)(110136005)(3280700002)(54906003)(68736007)(107886003)(4326008)(305945005)(22906009)(217873001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1110;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: uX5ME2S5DTsX++y0GSlT/mY9ngP73IT4z+GZxPs3Z4JP/winin99pmkX8b9AzreuiXdfE26KDX0zCBpitddUGEXbUqSMMY+w57/H4dXHd57C0ZxFUWf+BP09quw/X1uNfposlNslE5nGFQYq1b03SKvkQP/IY3VwZc4PxJOgz24fK8NbyxYZuV/0PcssOntR/B6o7NKow4mdstBkW8pbde1qli+mhSGT2m81SqNsFKhqGCeooOxUwW0b+XsherAuYR1AD0mD6MZBp3CREj1h8vvgQWVg9ZqNoHuEXWlDo/5Bttu1WbFDLPy85cth0MrWbqyPihhYGDq3cysdFrj5nHQjQs+iadvb5LdnCTpl3OJg7qmRRXYka/teLOgQ4DD06o6yVdh065a792PKrv9RYSrpDp5JdfOknnxxz38y5OM= 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: 420a4bf0-6baa-4e03-8bdd-08d59dafa859 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:31.6756 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1110 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 1df7da47f431..acf0ba56c309 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -196,9 +196,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); @@ -208,6 +205,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