From nobody Sat Feb 04 22:46:52 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P8SM06Hsrz3kVnZ; Sat, 4 Feb 2023 22:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P8SM05pYHz3w9F; Sat, 4 Feb 2023 22:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675550812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kE4683zChz4uhxmVDOwUgy5Z10xmrekOyFiASsIs2GM=; b=sxjAaxqI+Gvkyq7UorfbSo48m8ggZPFhOR8VnNxdDNIPiyKJBJ9snFBD82NknB0NBFB81e UscILue7VnZ0a4QxfalnQ4fR/Rof9GuTXMcGeFXk+cIW0p4upL8GuUZC00xfNVDliPDJeX Zon6kNr9td5Z400fRMSxAu78K4dzrsAIk3FT1i8HKYOKCLxiz8CbFoASnw/hZpqgOZmxLD qUfuImD+OEPOavN9Ar/9Uvk0k1ZX4CieHys9aMqaO0f85vZRCBwPyK8qxFACgoBDjQhKG8 K6mHi5UouCsgNd4AoRtwXRZsCoF+RB94ZhvA/Pg00t02JEGxFlh5dJGSLTPm+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675550812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kE4683zChz4uhxmVDOwUgy5Z10xmrekOyFiASsIs2GM=; b=uVy4PEDcZ1iswEk+gp+IPDym3smYWHxGA3oWHeIahhmc6JlBGKZo/Uwfqa3mI3u5W787tA A+OOw11GnRYHQEtDEVnBWfMyfDfJZITBmyif46YWO356PSyMuGP1EtowQ0LRARBjJCh9e9 lR0O9G4cE8IsCwWWN21vBJZhoO9s5eAf3WL+71ZJXBKhFSc/TNBHiE/pmwrhcZQlTKN4Qt 5YATFfi44a0KWBhtKoqfoMdmUb6OSOGf7kYRfXRMSJQ9FbQltD2SSQCOIymJI2WO6gkMOA SPM0o5rSRUdSpBmWHudIxzrSebYfm8OunKpleOSEptCAbpiMY/7IbKJGu0DGig== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675550812; a=rsa-sha256; cv=none; b=ZmOdEV4bysW+pxqG1CBOVtz0fRyKY7YMakcA4d90sul2X2TiIpKacHr8NGr1dNsFa07Cyi 5GlwOrJNUMNofJbXnBR75YL/auW2GuJzhRoFllk+FBvTTQqslXtqKkRzmVxGBMguHBYPfS CRg3KtpuIWxHuf3WG5ZApDKejnheXFhmrfPChtb0wHogbxEEiIhX/j1NN0jMm+JKZ8LMw5 0sJjXJJg9vaRHRXn0lQ9cMLuRIdMgwJ1ghJD4OWbhwN6sLirKApD0jbdzHsaXOEs1fSEzQ NutE1YYrrO7DMMg/V02CBGp4FnZKBJUcdRFC9DanPpGZnXdsq8iaqBXnyLg+5Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P8SM04kCJzXc3; Sat, 4 Feb 2023 22:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 314MkqJO061195; Sat, 4 Feb 2023 22:46:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 314Mkq1n061194; Sat, 4 Feb 2023 22:46:52 GMT (envelope-from git) Date: Sat, 4 Feb 2023 22:46:52 GMT Message-Id: <202302042246.314Mkq1n061194@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: db5655124ca4 - main - vfs_mount.c: Free exports structures in vfs_destroy_mount() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: db5655124ca4047ac397b9421ca4a08868a49ae9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=db5655124ca4047ac397b9421ca4a08868a49ae9 commit db5655124ca4047ac397b9421ca4a08868a49ae9 Author: Rick Macklem AuthorDate: 2023-02-04 22:45:23 +0000 Commit: Rick Macklem CommitDate: 2023-02-04 22:45:23 +0000 vfs_mount.c: Free exports structures in vfs_destroy_mount() During testing of exporting file systems in jails, I noticed that the export structures on a mount were not being free'd when the mount is dismounted. This bug appears to have been in the system for a very long time. It would have resulted in a slow memory leak when exported file systems were dismounted. Prior to r362158, freeing the structures during dismount would not have been safe, since VFS_CHECKEXP() returned a pointer into an export structure, which might still have been used by the NFS server for an in-progress RPC when the file system is dismounted. r362158 fixed this, so it should now be safe to free the structures in vfs_mount_destroy(), which is what this patch does. Reviewed by: kib MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D38385 --- sys/kern/vfs_export.c | 7 ++++--- sys/kern/vfs_mount.c | 4 ++++ sys/sys/mount.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c index 024011de4c89..cab37ce205ad 100644 --- a/sys/kern/vfs_export.c +++ b/sys/kern/vfs_export.c @@ -70,7 +70,6 @@ static MALLOC_DEFINE(M_NETADDR, "export_host", "Export host address structure"); static struct radix_node_head *vfs_create_addrlist_af( struct radix_node_head **prnh, int off); #endif -static void vfs_free_addrlist(struct netexport *nep); static int vfs_free_netcred(struct radix_node *rn, void *w); static void vfs_free_addrlist_af(struct radix_node_head **prnh); static int vfs_hang_addrlist(struct mount *mp, struct netexport *nep, @@ -274,7 +273,7 @@ vfs_free_addrlist_af(struct radix_node_head **prnh) /* * Free the net address hash lists that are hanging off the mount points. */ -static void +void vfs_free_addrlist(struct netexport *nep) { struct ucred *cred; @@ -285,8 +284,10 @@ vfs_free_addrlist(struct netexport *nep) vfs_free_addrlist_af(&nep->ne6); cred = nep->ne_defexported.netc_anon; - if (cred != NULL) + if (cred != NULL) { crfree(cred); + nep->ne_defexported.netc_anon = NULL; + } } diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 67a72f095786..430bafc8502f 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -761,6 +761,10 @@ vfs_mount_destroy(struct mount *mp) #endif if (mp->mnt_opt != NULL) vfs_freeopts(mp->mnt_opt); + if (mp->mnt_export != NULL) { + vfs_free_addrlist(mp->mnt_export); + free(mp->mnt_export, M_MOUNT); + } crfree(mp->mnt_cred); uma_zfree(mount_zone, mp); } diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 4bfc77b7f1a1..5f02f261b8f4 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -1017,6 +1017,7 @@ void vfs_periodic(struct mount *, int); int vfs_busy(struct mount *, int); int vfs_export /* process mount export info */ (struct mount *, struct export_args *); +void vfs_free_addrlist(struct netexport *); void vfs_allocate_syncvnode(struct mount *); void vfs_deallocate_syncvnode(struct mount *); int vfs_donmount(struct thread *td, uint64_t fsflags,