Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4122778ybe; Mon, 9 Sep 2019 04:42:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6W4Ye9svpUHd+iv1yWxmpWupkEl1q63JdRV17klQoC0MvkgV5+RZ8vwGFI0fVQrDtH6ms X-Received: by 2002:aa7:ce02:: with SMTP id d2mr23621081edv.270.1568029349866; Mon, 09 Sep 2019 04:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568029349; cv=none; d=google.com; s=arc-20160816; b=H2sNCD7NbuSvy5G3KiJ35kinfdts10Z6Lgsm2rt0Gj/4QLE0OzQZVqjFy6wfCIRpkU PI/ftDKTkik1771+ZhfnkUw6C1IfSMom2LyJGVImyoneiai/KoFd1a0I0D59gh0yXqRX o8mRxaWiiezdTgyHlg4zyNUN8N7KMvfy2vvifiHVphKPR1Yz7ax3gJHt3WrrkUVR9UQY VSsMD50EJInHCH8wdUqClSPz2fwQ/O4Yco5xjasNl/qBd8ykOYqM5jzmdBaEAFrozTq1 DDumYu5KbVuyfu6TB0OCDJf48YNEUFxDkBFZ21AqhaGJv4XIZSnRi1+nrzxc6JCcJ/Gt pKUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JlR7bdktR0zGJS1SFlz3AY81wMzVEcs8zG0RyRsjaaQ=; b=XFOh3s8gE5qeogXIAWN+p4pdD3OkQo5qmAo9kLoLEdYMNSawyOzebqQb5Qb59Y96d1 UF5a9SFN+QYB8CKchfb/kUJAg8f0WnDBQaB5AsuohIJm4aNwPCGfyYXgD02VINtd9Tbt LVwoc1KNUvwuO/shoU4lO2Vh3Msc77JX00o+ZFTkxCXxCHDvC+BcOAR4RjDYkaNPY54l ZB8chMBSYTwfuR0Y6JewRff0KOvS5N+skVLddIo5tTcDNPBkvrTnAT+QnIXQQ6ACud0p EfS5ftvWqdOGqkm8Cl15fFqpQRubaf2fZXYT481VOIO9nwsdIzgzmvso8FsoZuBCmv3h FaZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vGKOid3D; 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 sa2si7300004ejb.303.2019.09.09.04.42.06; Mon, 09 Sep 2019 04:42:29 -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=@kernel.org header.s=default header.b=vGKOid3D; 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 S1731038AbfIHMs2 (ORCPT + 99 others); Sun, 8 Sep 2019 08:48:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:37518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730954AbfIHMsZ (ORCPT ); Sun, 8 Sep 2019 08:48:25 -0400 Received: from localhost (unknown [62.28.240.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D1EA21924; Sun, 8 Sep 2019 12:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946904; bh=cC6LQjRnHIQNzCIffnzsBRuYfQC1vJcIUY6FOGwSNwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vGKOid3D3ClGYqtI62yIZP1Y/9c2uwHNX1wE2eDeyWP1LoViRyjL89lRwC0OZ/8BV IS96NQ/N3aHSygZ8hWA4Mgdww5dkegK1tZ69F49dvNdYwGXyZ95RDQU8W2nmWoMPRP E5l3NPIjcokk3FFGlQXaHrr+4DRvZiQNPhylMKQM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Leon Romanovsky , Dennis Dalessandro , Doug Ledford , Sasha Levin Subject: [PATCH 4.19 45/57] infiniband: hfi1: fix a memory leak bug Date: Sun, 8 Sep 2019 13:42:09 +0100 Message-Id: <20190908121145.368492256@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121125.608195329@linuxfoundation.org> References: <20190908121125.608195329@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit b08afa064c320e5d85cdc27228426b696c4c8dae ] In fault_opcodes_read(), 'data' is not deallocated if debugfs_file_get() fails, leading to a memory leak. To fix this bug, introduce the 'free_data' label to free 'data' before returning the error. Signed-off-by: Wenwen Wang Reviewed-by: Leon Romanovsky Acked-by: Dennis Dalessandro Link: https://lore.kernel.org/r/1566156571-4335-1-git-send-email-wenwen@cs.uga.edu Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/fault.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/fault.c b/drivers/infiniband/hw/hfi1/fault.c index 7eaff4dcbfd77..72ca0dc5f3b59 100644 --- a/drivers/infiniband/hw/hfi1/fault.c +++ b/drivers/infiniband/hw/hfi1/fault.c @@ -214,7 +214,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf, return -ENOMEM; ret = debugfs_file_get(file->f_path.dentry); if (unlikely(ret)) - return ret; + goto free_data; bit = find_first_bit(fault->opcodes, bitsize); while (bit < bitsize) { zero = find_next_zero_bit(fault->opcodes, bitsize, bit); @@ -232,6 +232,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf, data[size - 1] = '\n'; data[size] = '\0'; ret = simple_read_from_buffer(buf, len, pos, data, size); +free_data: kfree(data); return ret; } -- 2.20.1