Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1976230ybh; Tue, 14 Jul 2020 12:05:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBai76I5srDl2g7rA1KMc4iYc2/YN6FG2th1+A23ZeQ/VRoQKPEoNrmm8DAdaGpxFRhuXD X-Received: by 2002:a50:9f8c:: with SMTP id c12mr5961830edf.149.1594753541085; Tue, 14 Jul 2020 12:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753541; cv=none; d=google.com; s=arc-20160816; b=qVV7rJDgOHTGMDa4aV+CLp5Sye1c57F6X99q/FV//HayWfNdNIT/UvWgcAs825xay/ WKioLa5K8r1XIGyV3o3DewUWLlu15GdQhJPXZBul9l5js3Xy1gKS1LqWmbcWqnGecv63 9qHzZlbJkpE4sW69P+Xtfu5mvH4ccFc15UP6+s3/wLBeun8hckyEpQ2VC/w7dG640561 fpBEQvu6573P3dGQXBbHUmgGk5TqaHvl8dowMHfpTGxwje2dbkinLEVdghY+yJuB/1un UmrEpqhOO7Tofd+ZewzXPnUpGtYNNSC8ibDqI9Xb1eHpzQxfGyYjIV9XdMo2Qtq5NJAf Ryig== 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=TOx0RrpD2qGA9awA6vOokEBnNiNraX8OtfDyk/RXMAE=; b=ms2NjVVKXS5q+sWJLSkcdGbC53uFDBObBY08sjIuCLKx+wxFK6UsuTAltlkptfTPA/ 9YXrimb2WG4msLvqfZ4XqODOokz5/zUvufLKHRrrLJ8xNo0AGn6sqCiEtH1NQMTQOIb7 x42P+FcAv7t6xg2H7I3JDoM8I9XgeoiAXwAT6oCYRfr18Ke/6+vGbpq9fn1jJl14JBvX vBcOHzeJGOLnb927fR4ddH9gqDJEgIxLOqh47TMYlBOOvZyP+ehRgNwfud5nRqqcTg4j quU/tFifr7qkB2ynQe1n8/Zsmcgg/Oowzu9/RGdEyVyticBSSoVZM5nyESMM4itmiqOG 3Urg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KABGEfNk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si9646547edw.426.2020.07.14.12.05.17; Tue, 14 Jul 2020 12:05:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KABGEfNk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730716AbgGNTFN (ORCPT + 99 others); Tue, 14 Jul 2020 15:05:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:52584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729554AbgGNSzB (ORCPT ); Tue, 14 Jul 2020 14:55:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 87BE322BF3; Tue, 14 Jul 2020 18:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594752901; bh=sj7Mgy53uvCuBJN5AxCbcIf+Ao8fcs55/4IY3bzKD68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KABGEfNkMwcFlZZAjPTzoqFKhxezYb914OoGcmVe7mYkpCueCFe8RmEFa5M4JHJ2O Cfu7ym5gpd/cLQOS5WWqv6GSjhUOBhJSBYaEMHgR8Pfojl98NheaKqJ2ICAxACtZUx XT0P5UXA7+OH9Zzjge/0LnCD3w5/9Dc5PdcRqfTs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , Anna Schumaker , Sasha Levin Subject: [PATCH 5.7 043/166] nfs: Fix memory leak of export_path Date: Tue, 14 Jul 2020 20:43:28 +0200 Message-Id: <20200714184117.942167644@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714184115.844176932@linuxfoundation.org> References: <20200714184115.844176932@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 From: Tom Rix [ Upstream commit 4659ed7cc8514369043053463514408ca16ad6f3 ] The try_location function is called within a loop by nfs_follow_referral. try_location calls nfs4_pathname_string to created the export_path. nfs4_pathname_string allocates the memory. export_path is stored in the nfs_fs_context/fs_context structure similarly as hostname and source. But whereas the ctx hostname and source are freed before assignment, export_path is not. So if there are multiple loops, the new export_path will overwrite the old without the old being freed. So call kfree for export_path. Signed-off-by: Tom Rix Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/nfs4namespace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index a3ab6e219061b..873342308dc0d 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c @@ -308,6 +308,7 @@ static int try_location(struct fs_context *fc, if (IS_ERR(export_path)) return PTR_ERR(export_path); + kfree(ctx->nfs_server.export_path); ctx->nfs_server.export_path = export_path; source = kmalloc(len + 1 + ctx->nfs_server.export_path_len + 1, -- 2.25.1