git: d6978ed95c6f - stable/15 - namei(9): fix restart for NDINIT_ATVP
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 01:09:33 UTC
The branch stable/15 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=d6978ed95c6f1a900afa0ee4d53af23d193dad11
commit d6978ed95c6f1a900afa0ee4d53af23d193dad11
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-08 19:20:37 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-17 00:24:56 +0000
namei(9): fix restart for NDINIT_ATVP
(cherry picked from commit 2f3d64f63677a6ed4c7bb6629d92161555948038)
---
sys/kern/vfs_lookup.c | 27 ++++++++++++++++++++++++++-
sys/sys/namei.h | 10 +++++++---
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index fadc65918657..2d19dc7e818d 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -76,12 +76,15 @@ static void NDVALIDATE_impl(struct nameidata *, int);
/*
* Reset ndp to its original state.
+ * namei() supplies the starting directory again on restart, so unlike
+ * NDREINIT(), NAMEI_DBG_HADSTARTDIR can be set there.
*/
#define NDRESET(ndp) do { \
- NDREINIT_DBG(ndp); \
+ NDRESET_DBG(ndp); \
ndp->ni_resflags = 0; \
ndp->ni_cnd.cn_flags &= ~NAMEI_INTERNAL_FLAGS; \
} while (0)
+
/*
* Prepare namei() to restart. Reset components to its original state and set
* ISRESTARTED flag which signals the underlying lookup code to change the root
@@ -610,6 +613,7 @@ int
namei(struct nameidata *ndp)
{
struct vnode *dp; /* the directory we are searching */
+ struct vnode *atvp; /* NDINIT_ATVP() starting directory */
struct componentname *cnp;
struct thread *td;
struct pwd *pwd;
@@ -632,6 +636,7 @@ namei(struct nameidata *ndp)
abi_suffix_len = 0;
target_resolved = false;
abi_pass = NAMEI_ABI_PASS_ABI;
+ atvp = ndp->ni_startdir;
#ifdef INVARIANTS
KASSERT((ndp->ni_debugflags & NAMEI_DBG_CALLED) == 0,
("%s: repeated call to namei without NDREINIT", __func__));
@@ -701,6 +706,8 @@ restart:
* We may need to start from scratch or pick up where it left off.
*/
error = cache_fplookup(ndp, &status, &pwd);
+ /* cache_can_fplookup() rejects ni_startdir. */
+ MPASS(atvp == NULL || status == CACHE_FPL_STATUS_ABORTED);
switch (status) {
case CACHE_FPL_STATUS_UNSET:
__assert_unreachable();
@@ -743,8 +750,17 @@ restart:
false, ndp);
return (ENOENT);
}
+ /*
+ * namei_setup() and vfs_lookup() consume the reference
+ * on ni_startdir. Hold the NDINIT_ATVP() vnode so that
+ * a restart can reference it again.
+ */
+ if (atvp != NULL)
+ vhold(atvp);
error = namei_setup(ndp, &dp, &pwd);
if (error != 0) {
+ if (atvp != NULL)
+ vdrop(atvp);
namei_cleanup_cnp(cnp);
nameicap_cleanup(ndp, error);
return (error);
@@ -823,6 +839,11 @@ restart:
if (abi_restart)
was_restarted = ISRESTARTED;
ndp->ni_cnd.cn_flags |= was_restarted;
+ if (atvp != NULL) {
+ vref(atvp);
+ ndp->ni_startdir = atvp;
+ vdrop(atvp);
+ }
goto restart;
}
@@ -835,6 +856,8 @@ restart:
nameicap_cleanup(ndp, 0);
pwd_drop(pwd);
uma_zfree(namei_zone, abi_symlink);
+ if (atvp != NULL)
+ vdrop(atvp);
NDVALIDATE(ndp);
return (0);
}
@@ -908,6 +931,8 @@ out:
nameicap_cleanup(ndp, error);
pwd_drop(pwd);
uma_zfree(namei_zone, abi_symlink);
+ if (atvp != NULL)
+ vdrop(atvp);
return (error);
}
diff --git a/sys/sys/namei.h b/sys/sys/namei.h
index 6008d83f729d..2d03bd6deb84 100644
--- a/sys/sys/namei.h
+++ b/sys/sys/namei.h
@@ -235,19 +235,23 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
#define NDINIT_PREFILL(arg) memset(arg, 0xff, offsetof(struct nameidata, \
ni_dvp_seqc))
#define NDINIT_DBG(arg) { (arg)->ni_debugflags = NAMEI_DBG_INITED; }
-#define NDREINIT_DBG(arg) { \
+#define NDRESET_DBG(arg) { \
if (((arg)->ni_debugflags & NAMEI_DBG_INITED) == 0) \
panic("namei data not inited"); \
- if (((arg)->ni_debugflags & NAMEI_DBG_HADSTARTDIR) != 0) \
- panic("NDREINIT on namei data with NAMEI_DBG_HADSTARTDIR"); \
if ((arg)->ni_nctrack_mnt != NULL) \
panic("NDREINIT on namei data with leaked ni_nctrack_mnt"); \
if (!TAILQ_EMPTY(&(arg)->ni_cap_tracker)) \
panic("NDREINIT on namei data with leaked ni_cap_tracker"); \
+}
+#define NDREINIT_DBG(arg) { \
+ NDRESET_DBG(arg); \
+ if (((arg)->ni_debugflags & NAMEI_DBG_HADSTARTDIR) != 0) \
+ panic("NDREINIT on namei data with NAMEI_DBG_HADSTARTDIR"); \
(arg)->ni_debugflags = NAMEI_DBG_INITED; \
}
#else
#define NDINIT_PREFILL(arg) do { } while (0)
+#define NDRESET_DBG(arg) do { } while (0)
#define NDINIT_DBG(arg) do { } while (0)
#define NDREINIT_DBG(arg) do { } while (0)
#endif