From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793831725; b=OVYNHd7oJyN7g9EHBb1eZ63Z3PplsrpZDaSsJmn1lNfn/0M+xb19sS/X/rwvtMpBFTho 1vUW3SEGjTJaJH/Lyw5iLXG7lOsCT0H3ZcqgvTdu6bdNvgvik8XC36JEIbJSsdiSlIM7C TCxfnA/sTUofOJm7brL8rtO9IjiXqlMHsqFI9X54h6WIBis9kzZrEUw/SxG5hbxG/1D7n 3cNGTOYRJP8OhCUs3EJOWctPDGFigPAvbl40XE6t53SWUk+PNBifRNmZthpGmbeS6wG75 dnW94JQaslfQphFtawngVb7YR+v+yp85rhd/ca2qhrPgYPrcIPYW8MjMAuvIzHOS8jA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793831725; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=iaWOuU8NK+2UAhrTS2KOq5G9wL349hzrWzTJ+epcexQ=; b=pDwQuZ16Cn6+A+qjRbmHqAqUDoB8zykv2d3PFrP/Kipir/LPznBNAoL+lskTR8HcCdL0 NmJQf9yUGKddlXGCiIL/lSQxOaztmKcmnoTwrJFj1foFsTSlfmuF6TduC+aqAhu1g2j+U tdtkaO1gJTXCfb3NnCodmYwyWC172QDSnKvMGtzDbCKlJJvNWGfuXJLlFoJ2zcsmPE7vW ceQD2pmjmOlIYLh3oIGpfi+teSoCjgaQqIozTXoI0yi0KBDvZXroPhuw6BpXUliK2fF6w JyRRrKDDHwczwfTzkOwPL1o6/e95Sgy04TBiWE1y5g4u1oNwlgZjuzEVC3dRFoHHw+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XopRXYQt; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8956606A842; Wed, 4 Nov 2026 22:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XopRXYQt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74B721F000C1; Wed, 4 Nov 2026 22:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793831724; bh=iaWOuU8NK+2UAhrTS2KOq5G9wL349hzrWzTJ+epcexQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XopRXYQtJBpMVzeyv+/M9p+YfwUjF/qmjVk+uW2vhsK6c92V2bQA3wTsw9iIikBIE 4QfT8QEe7E+0PpZyCLMyxylIpsQQ/skx9Kcaz4E8nDAEO/l7QL14PDUMAFoQb4A8Ee wPev563CFIBULrCkERgKgagHt4i4XYfIRyWghP9M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Benjamin Coddington , Anna Schumaker Subject: [PATCH 6.18 0875/1005] NFSv4/pnfs: Free the netid when draining a data-server address list Date: Wed, 4 Nov 2026 16:10:08 -0500 Message-ID: <20261104211107.764149445@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261104211043.516122098@linuxfoundation.org> References: <20261104211043.516122098@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Coddington commit a7c8e96d1b9fa327cbdea514d047c8295b28d49a upstream. nfs4_pnfs_ds_addr_free() releases all three of an address entry's allocations, but the four sites that drain a decoded list before it reaches a data server open-code the loop and free only da_remotestr and the entry, leaking da_netid. Both layout drivers drain that list when nfs4_pnfs_ds_add() returned a data server already in the cache, and again on their error exits. Lift the drain into nfs4_pnfs_ds_addr_list_free() so an address list has one owner. A striping mount reaches the cached case on nearly every GETDEVICEINFO, since many deviceIDs name the same data servers. Fixes: 4be78d26810b ("NFSv4/pNFS: Store the transport type in struct nfs4_pnfs_ds_addr") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Benjamin Coddington Signed-off-by: Anna Schumaker Signed-off-by: Greg Kroah-Hartman --- fs/nfs/filelayout/filelayoutdev.c | 17 ++--------------- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 17 ++--------------- fs/nfs/pnfs.h | 1 + fs/nfs/pnfs_nfs.c | 21 +++++++++++++-------- 4 files changed, 18 insertions(+), 38 deletions(-) --- a/fs/nfs/filelayout/filelayoutdev.c +++ b/fs/nfs/filelayout/filelayoutdev.c @@ -177,27 +177,14 @@ nfs4_fl_alloc_deviceid_node(struct nfs_s trace_fl_getdevinfo(server, &pdev->dev_id, dsaddr->ds_list[i]->ds_remotestr); /* If DS was already in cache, free ds addrs */ - while (!list_empty(&dsaddrs)) { - da = list_first_entry(&dsaddrs, - struct nfs4_pnfs_ds_addr, - da_node); - list_del_init(&da->da_node); - kfree(da->da_remotestr); - kfree(da); - } + nfs4_pnfs_ds_addr_list_free(&dsaddrs); } folio_put(scratch); return dsaddr; out_err_drain_dsaddrs: - while (!list_empty(&dsaddrs)) { - da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, - da_node); - list_del_init(&da->da_node); - kfree(da->da_remotestr); - kfree(da); - } + nfs4_pnfs_ds_addr_list_free(&dsaddrs); out_err_free_deviceid: nfs4_fl_free_deviceid(dsaddr); /* stripe_indicies was part of dsaddr */ --- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c +++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c @@ -155,26 +155,13 @@ nfs4_ff_alloc_deviceid_node(struct nfs_s goto out_err_drain_dsaddrs; /* If DS was already in cache, free ds addrs */ - while (!list_empty(&dsaddrs)) { - da = list_first_entry(&dsaddrs, - struct nfs4_pnfs_ds_addr, - da_node); - list_del_init(&da->da_node); - kfree(da->da_remotestr); - kfree(da); - } + nfs4_pnfs_ds_addr_list_free(&dsaddrs); folio_put(scratch); return new_ds; out_err_drain_dsaddrs: - while (!list_empty(&dsaddrs)) { - da = list_first_entry(&dsaddrs, struct nfs4_pnfs_ds_addr, - da_node); - list_del_init(&da->da_node); - kfree(da->da_remotestr); - kfree(da); - } + nfs4_pnfs_ds_addr_list_free(&dsaddrs); kfree(ds_versions); out_scratch: --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h @@ -426,6 +426,7 @@ int nfs4_pnfs_ds_connect(struct nfs_serv struct nfs4_pnfs_ds_addr *nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags); +void nfs4_pnfs_ds_addr_list_free(struct list_head *dsaddrs); void pnfs_layout_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg, struct nfs_commit_info *cinfo, --- a/fs/nfs/pnfs_nfs.c +++ b/fs/nfs/pnfs_nfs.c @@ -633,23 +633,28 @@ static void nfs4_pnfs_ds_addr_free(struc kfree(da); } -static void destroy_ds(struct nfs4_pnfs_ds *ds) +void nfs4_pnfs_ds_addr_list_free(struct list_head *dsaddrs) { struct nfs4_pnfs_ds_addr *da; + while (!list_empty(dsaddrs)) { + da = list_first_entry(dsaddrs, struct nfs4_pnfs_ds_addr, + da_node); + list_del_init(&da->da_node); + nfs4_pnfs_ds_addr_free(da); + } +} +EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_addr_list_free); + +static void destroy_ds(struct nfs4_pnfs_ds *ds) +{ dprintk("--> %s\n", __func__); ifdebug(FACILITY) print_ds(ds); nfs_put_client(ds->ds_clp); - while (!list_empty(&ds->ds_addrs)) { - da = list_first_entry(&ds->ds_addrs, - struct nfs4_pnfs_ds_addr, - da_node); - list_del_init(&da->da_node); - nfs4_pnfs_ds_addr_free(da); - } + nfs4_pnfs_ds_addr_list_free(&ds->ds_addrs); kfree(ds->ds_remotestr); kfree(ds);