git: 5feb271df85f - main - namei(9): fix two ni_startdir leaks

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 10 Nov 2026 19:54:21 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=5feb271df85fe6bd968052d5bdd02b6d80335610

commit 5feb271df85fe6bd968052d5bdd02b6d80335610
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-10 00:49:33 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-10 19:53:27 +0000

    namei(9): fix two ni_startdir leaks
    
    namei() leaks the caller's ni_startdir reference on the empty-path
    ENOENT return and on namei_getpath() failure.
    
    On ZFS with the default zfs_xattr_compat=1, an empty user-namespace
    extattr name on a file that has an xattr directory leaks one reference
    on that directory per call.
    
    Reported by:    llm-postcr
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D61366
---
 sys/kern/vfs_lookup.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index 2960d3aafb92..6fb1d33a0e37 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -681,11 +681,14 @@ restart:
 		 */
 		MPASS(cnp->cn_pnbuf != NULL);
 		error = 0;
-	} else
+	} else {
 		error = namei_getpath(ndp);
+	}
 	if (__predict_false(error != 0)) {
 		namei_cleanup_cnp(cnp);
 		nameicap_cleanup(ndp, error);
+		if (ndp->ni_startdir != NULL)
+			vrele(ndp->ni_startdir);
 		SDT_PROBE4(vfs, namei, lookup, return, error, NULL,
 		    false, ndp);
 		return (error);
@@ -746,6 +749,8 @@ restart:
 			}
 			namei_cleanup_cnp(cnp);
 			nameicap_cleanup(ndp, ENOENT);
+			if (ndp->ni_startdir != NULL)
+				vrele(ndp->ni_startdir);
 			SDT_PROBE4(vfs, namei, lookup, return, ENOENT, NULL,
 			    false, ndp);
 			return (ENOENT);