git: 2c5f0480c211 - stable/13 - fstatat(2): handle non-vnode file descriptors for AT_EMPTY_PATH

Konstantin Belousov kib at FreeBSD.org
Thu Aug 19 11:22:59 UTC 2021


The branch stable/13 has been updated by kib:

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

commit 2c5f0480c211ef1373a0e01aa4ce1b64d8e2e10e
Author:     Konstantin Belousov <kib at FreeBSD.org>
AuthorDate: 2021-08-13 17:40:10 +0000
Commit:     Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-08-19 11:21:57 +0000

    fstatat(2): handle non-vnode file descriptors for AT_EMPTY_PATH
    
    (cherry picked from commit 9446d9e88fd7b203fa50c015f29b636db5b1d52b)
---
 sys/kern/vfs_lookup.c   | 2 +-
 sys/kern/vfs_syscalls.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index e0b98c9f5661..a827c87538b8 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -489,6 +489,7 @@ namei_emptypath(struct nameidata *ndp)
 	MPASS((cnp->cn_flags & EMPTYPATH) != 0);
 	MPASS((cnp->cn_flags & (LOCKPARENT | WANTPARENT)) == 0);
 
+	ndp->ni_resflags |= NIRES_EMPTYPATH;
 	error = namei_setup(ndp, &dp, &pwd);
 	if (error != 0) {
 		namei_cleanup_cnp(cnp);
@@ -501,7 +502,6 @@ namei_emptypath(struct nameidata *ndp)
 	ndp->ni_vp = dp;
 	namei_cleanup_cnp(cnp);
 	pwd_drop(pwd);
-	ndp->ni_resflags |= NIRES_EMPTYPATH;
 	NDVALIDATE(ndp);
 	if ((cnp->cn_flags & LOCKLEAF) != 0) {
 		VOP_LOCK(dp, (cnp->cn_flags & LOCKSHARED) != 0 ?
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 855943adecef..8fae55c2862d 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -2426,8 +2426,12 @@ kern_statat(struct thread *td, int flag, int fd, const char *path,
 	    AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH) | LOCKSHARED | LOCKLEAF |
 	    AUDITVNODE1, pathseg, path, fd, &cap_fstat_rights, td);
 
-	if ((error = namei(&nd)) != 0)
+	if ((error = namei(&nd)) != 0) {
+		if (error == ENOTDIR &&
+		    (nd.ni_resflags & NIRES_EMPTYPATH) != 0)
+			error = kern_fstat(td, fd, sbp);
 		return (error);
+	}
 	error = VOP_STAT(nd.ni_vp, sbp, td->td_ucred, NOCRED, td);
 	if (error == 0) {
 		if (__predict_false(hook != NULL))


More information about the dev-commits-src-branches mailing list