git: f3e70613c052 - main - lookup: hold ni_rbeneath_dpp

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:01:43 UTC
The branch main has been updated by markj:

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

commit f3e70613c0522029b2bbe981a0e05c9932b15f24
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-10-23 03:59:15 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-17 16:57:00 +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 6fb1d33a0e37..abf306ac9102 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -261,6 +261,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;
+	}
 }
 
 /*
@@ -422,8 +426,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.