git: 9446d9e88fd7 - main - fstatat(2): handle non-vnode file descriptors for AT_EMPTY_PATH
Konstantin Belousov
kib at FreeBSD.org
Fri Aug 13 21:18:35 UTC 2021
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=9446d9e88fd7b203fa50c015f29b636db5b1d52b
commit 9446d9e88fd7b203fa50c015f29b636db5b1d52b
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-13 21:17:18 +0000
fstatat(2): handle non-vnode file descriptors for AT_EMPTY_PATH
Set NIRES_EMPTYPATH earlies, to have use of EMPTYPATH recorded even if
we are going to return error. When namei_setup() refused to accept dirfd,
which is not of the vnode type, and indicated by ENOTDIR error return,
fall back to kern_fstat(dirfd).
Reported by: dchagin
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D31530
---
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 f2ed8d2a9acb..bd496db50e99 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -2438,8 +2438,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-main
mailing list