git: 6deddbb4a679 - releng/15.1 - lookup: hold ni_rbeneath_dpp

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:08:12 UTC
The branch releng/15.1 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6deddbb4a679dbc75185644a9b3521a63cbfde71

commit 6deddbb4a679dbc75185644a9b3521a63cbfde71
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-23 03:59:15 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-16 21:21:09 +0000

    lookup: hold ni_rbeneath_dpp
    
    The vnode is held to ensure the validity of the pointer.
    
    Approved by:    so
    Security:       FreeBSD-SA-26:81.vfs
    Reported by:    pjd
    Sponsored by:   The FreeBSD Foundation
---
 sys/kern/vfs_lookup.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index fb3e6a7a2534..f5dc2322c86a 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -258,6 +258,10 @@ nameicap_cleanup(struct nameidata *ndp, int error)
 		vfs_rel(mp);
 		ndp->ni_nctrack_mnt = NULL;
 	}
+	if (ndp->ni_rbeneath_dpp != NULL) {
+		vdrop(ndp->ni_rbeneath_dpp);
+		ndp->ni_rbeneath_dpp = NULL;
+	}
 }
 
 /*
@@ -419,8 +423,10 @@ namei_setup(struct nameidata *ndp, struct vnode **dpp, struct pwd **pwdp)
 			    NI_LCF_CAP_DOTDOT;
 		}
 	}
-	if (error == 0 && (ndp->ni_lcf & NI_LCF_STRICTREL) != 0)
+	if (error == 0 && (ndp->ni_lcf & NI_LCF_STRICTREL) != 0) {
 		ndp->ni_rbeneath_dpp = *dpp;
+		vholdnz(*dpp);
+	}
 
 	/*
 	 * If we are auditing the kernel pathname, save the user pathname.