Received: by 10.192.165.148 with SMTP id m20csp549788imm; Wed, 25 Apr 2018 04:06:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx48SPnEzyOQWjgHyHaXpkI4PdsAZyCuo0TNby3nR9Lp/bE9L6mM3PUTy5NvUeQJVtqaff0GT X-Received: by 10.98.40.68 with SMTP id o65mr27474155pfo.103.1524654385268; Wed, 25 Apr 2018 04:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524654385; cv=none; d=google.com; s=arc-20160816; b=dxnkkEotY7k39WWvgh1LeHLTlKktZ2ITkXcAmUFEOUL2K/ogh7qSuCJDZq9lGEq3gz iFmL1JL+zfM/+UmWP6UJoXkU+SrAPFtDuxlLMKhMGh7F6NZqXI85wYXduKc4d63avVBw NDgy8thvvvI1liab+lYcIfW6xxl9eWR+H0bvAbOUk+m3QZBVwL2e8D/4/6m2gi9ZVyzv NoTR/G4IXETBi+g29pFJatIP74kVys7fbEGIwWln2K2/NPGTPFBVla5uqkWD7LtUJooi Sc2UZYrjtUgBrjRO5o9GBZbO1Dgb6Wpa7r/BX+HJR/h6JGYvqxISy+Sf4KZeKMre6AC+ tvfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=E59AiQf9YqzO1+EoU3wvyqA2UlzHBQZxK91wNJz+VIA=; b=wrfIMTCi8ZuzNax9Z/OsueMMNFSr/NKP9YRpqs0DGGvPR/CgUKp44jC7NToGdRXsL5 nac36nWsggvMCiaIk7EnxU+B3n49kI/0r2++2Tp08lcIBjl3me1ocqPUb5NQdV655CRh c9ZdQD4B9KXwu7oSHJNEP58Hz4sfzlNFAAtiJEjVAADAzPak269Gden5P+KNlaPXfW1Y MJ/xfRVxR3xYdRJk/S6kwuyzLYjko1U5ukwFY4+b4cpkQ5W4Y5R0nwnQKbH6IVbl0FDc mVsJf1Ct5Y6wVDjOonGNJRSC6weIg7He48XmItonIWoCCaPEZhTPvLViTTnkETOPBpH9 DfNA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e187si9333167pgc.127.2018.04.25.04.06.11; Wed, 25 Apr 2018 04:06:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754077AbeDYKmN (ORCPT + 99 others); Wed, 25 Apr 2018 06:42:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52558 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752809AbeDYKmG (ORCPT ); Wed, 25 Apr 2018 06:42:06 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E0BCB36; Wed, 25 Apr 2018 10:42:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael J Ruhl , Alex Estrin , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.14 121/183] IB/hfi1: Fix for potential refcount leak in hfi1_open_file() Date: Wed, 25 Apr 2018 12:35:41 +0200 Message-Id: <20180425103247.294705514@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/hfi1/file_ops.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- 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 * if (!atomic_inc_not_zero(&dd->user_refcount)) return -ENXIO; - /* 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() */ fd = kzalloc(sizeof(*fd), GFP_KERNEL); @@ -203,6 +200,7 @@ static int hfi1_file_open(struct inode * fd->mm = current->mm; mmgrab(fd->mm); fd->dd = dd; + kobject_get(&fd->dd->kobj); fp->private_data = fd; } else { fp->private_data = NULL;