Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4426178ybe; Mon, 9 Sep 2019 09:06:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUwNd2fQCYa9kDFl6zlT6P4SgMepHwXD+AHWi49MFN2XpNBm8B+asYZjtwYfrDn8S/RlI4 X-Received: by 2002:a17:907:2065:: with SMTP id qp5mr19766882ejb.151.1568045210031; Mon, 09 Sep 2019 09:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568045210; cv=none; d=google.com; s=arc-20160816; b=mg2biYOI+t2dAuQvKgT7nGn1SsHK07yzzoCYNTcAoFhoP38yohezfgm7GimDktgjLu b6pkdl8Oeoks/SGY1oYA25V/+QevpGdvU6SLMicW6C0MRqgwn9oCQu1pWrdF51GKu/5u KinkgHt58Va/1IlCqBs2r7sPH6CTrvLUV6WEvzYWht79BqhNj0Xrsp9KJBU8ebydfqPc Hv9G6x5eyRCXYU2/9CSYFk/OfJq+RH1/ZL/McfG0dr5vDRJvm8hAnZixEanAHLIUB5Hn VzYH5qfueomUVpYM8ECrgfKat7TmxnSDu8khD4DLGD0PQ5yPN86lOX6TS/9He4W1Q9Wd uVmA== 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=6kf11A3kI5sX/j0q3iZW86qlEVmvpC+hxuy3axpjcp0=; b=u3nNQSUAYZRv6+eyFFmlyao0Psd7vmUW6ixjkVLJKeV8N7xT8K8SiEIa8wWqCsuToI 4yl7DHGD/Hrx42WmDlEh8Ru+z1elXCrQNJ98Px97zU9VoedFgvrD/p+hgsGNwzZOCjoz KH8OboFAbzSmWDx2dI4U6dkX+x/26AJ91yU6h0O7c2nMsisWe4seUfDlDhLAs195x5Wa 8YUpkeITNiHgHZBW5s0C9fSfoxF7UGzZgq/dHi0E16z1m/dJm7Bc8Mm8aCGIx/g1WU+u 9XnmJ33gNi6EUZJn2lcXmJKUemTAgkJS/vsUgzYW/nHHI4M8RUNS/3ITXGS1VF0LJlyH T0LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Oj0vFf/X"; 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 y19si9852164edc.363.2019.09.09.09.06.25; Mon, 09 Sep 2019 09:06:50 -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="Oj0vFf/X"; 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 S2387789AbfIHMyY (ORCPT + 99 others); Sun, 8 Sep 2019 08:54:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:44488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732982AbfIHMwT (ORCPT ); Sun, 8 Sep 2019 08:52:19 -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 A0D312082C; Sun, 8 Sep 2019 12:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567947139; bh=FO5gHr8dnNSQ2RU2dbqQBpuvGlmBQpI/J/6PWMXIbSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oj0vFf/XmodhqWBMW3g/JCArlY8Kw9RkJYhpxmkYDqq98lfVe7Dx3NrdZr1MoUNpo ZShq6uVCXDR0xi9RHlLTzxA/gztezmhs9XevUTkY/EP4hCC0JBz0qfns/naznsTM3E bMetpQL0zshA1Aek1fSvcYWo1O9f584j+TIZUf7Q= 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 5.2 76/94] infiniband: hfi1: fix memory leaks Date: Sun, 8 Sep 2019 13:42:12 +0100 Message-Id: <20190908121152.614020707@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121150.420989666@linuxfoundation.org> References: <20190908121150.420989666@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 2323d7baab2b18d87d9bc267452e387aa9f0060a ] In fault_opcodes_write(), 'data' is allocated through kcalloc(). However, it is not deallocated in the following execution if an error occurs, leading to memory leaks. To fix this issue, 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/1566154486-3713-1-git-send-email-wenwen@cs.uga.edu Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/fault.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/fault.c b/drivers/infiniband/hw/hfi1/fault.c index 814324d172950..986c12153e62e 100644 --- a/drivers/infiniband/hw/hfi1/fault.c +++ b/drivers/infiniband/hw/hfi1/fault.c @@ -141,12 +141,14 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, if (!data) return -ENOMEM; copy = min(len, datalen - 1); - if (copy_from_user(data, buf, copy)) - return -EFAULT; + if (copy_from_user(data, buf, copy)) { + ret = -EFAULT; + goto free_data; + } ret = debugfs_file_get(file->f_path.dentry); if (unlikely(ret)) - return ret; + goto free_data; ptr = data; token = ptr; for (ptr = data; *ptr; ptr = end + 1, token = ptr) { @@ -195,6 +197,7 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf, ret = len; debugfs_file_put(file->f_path.dentry); +free_data: kfree(data); return ret; } -- 2.20.1