git: 922eaa623076 - main - namei(9): allow NDINIT_ATVP() lookups in capability mode

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

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

commit 922eaa623076b4b8878022b3cbad1bef1f023de8
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-08 04:11:21 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-10 00:13:34 +0000

    namei(9): allow NDINIT_ATVP() lookups in capability mode
    
    NDINIT_ATVP() initializes dirfd to AT_FDCWD, which is denied for a
    process already in cap mode.  Since NDINIT_ATVP() is a special lookup
    operation performed by the kernel, it should be allowed to proceed for
    the paths beneath vp.
    
    Fabricate a pseudo dirfd value that is an unused placeholder,
    which fails the AT_FDCWD comparison and allows the lookup to proceed in
    cap mode.
    
    Note that failed cap-mode NDINIT_ATVP lookup returned ECAPMODE without
    releasing the caller reference on ni_startdir, which is fixed by this
    change.
    
    Reported by:    ivy
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D61315
---
 sys/sys/namei.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/sys/namei.h b/sys/sys/namei.h
index 2d03bd6deb84..6ba3415a026b 100644
--- a/sys/sys/namei.h
+++ b/sys/sys/namei.h
@@ -216,6 +216,7 @@ int	cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
 /*
  * Initialization of a nameidata structure.
  */
+#define	AT_ATVP		(-101)		/* NDINIT_ATVP dirfd */
 #define	NDINIT(ndp, op, flags, segflg, namep)				\
 	NDINIT_ALL(ndp, op, flags, segflg, namep, AT_FDCWD, NULL, &cap_no_rights)
 #define	NDINIT_AT(ndp, op, flags, segflg, namep, dirfd)			\
@@ -223,7 +224,7 @@ int	cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
 #define	NDINIT_ATRIGHTS(ndp, op, flags, segflg, namep, dirfd, rightsp) 	\
 	NDINIT_ALL(ndp, op, flags, segflg, namep, dirfd, NULL, rightsp)
 #define	NDINIT_ATVP(ndp, op, flags, segflg, namep, vp)			\
-	NDINIT_ALL(ndp, op, flags, segflg, namep, AT_FDCWD, vp, &cap_no_rights)
+	NDINIT_ALL(ndp, op, flags, segflg, namep, AT_ATVP, vp, &cap_no_rights)
 
 /*
  * Note the constant pattern may *hide* bugs.