fs/stat: reject invalid flags for empty paths
PATCH v2 1/1 fs/stat: reject invalid flags for empty paths
vfs_fstatat() and statx() take the file descriptor fast path for empty paths when AT_EMPTY_PATH is set. These paths bypass the flag validation in vfs_statx(), allowing unsupported flags such as AT_RECURSIVE to succeed.
Return -EINVAL for unsupported flags in the vfs_fstatat() fast path, and validate flags in vfs_statx_fd() as is already done in vfs_statx().
---
v2:
- return -EINVAL directly for unsupported flags in vfs_fstatat()
- validate flags in vfs_statx_fd() instead of changing statx() dispatch (as suggested by Jan Kara)
fs/stat.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/stat.c +10 -1
@@ -322,6 +322,11 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat, u32 request_mask) {CLASS (fd_raw, f)(fd); + +if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )) +return -EINVAL ; +if (fd_empty (f))return -EBADF ;return vfs_statx_path (&fd_file (f)->f_path, flags, stat, request_mask);
@@ -371,8 +376,12 @@ int vfs_fstatat(int dfd, const char __user *filename, {CLASS (filename_maybe_null, name)(filename, flags); -if (!name && dfd >=0 ) +if (!name && dfd >=0 ) { +if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )) +return -EINVAL ;return vfs_fstat (dfd, stat); + }return vfs_statx (dfd, name, flags |AT_NO_AUTOMOUNT , stat,STATX_BASIC_STATS );
base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd
Signature · 1 line
2.43.0
Quoted 10 lines · Avi Weiss
vfs_fstatat()andstatx()take the file descriptor fast path for empty paths whenAT_EMPTY_PATHis set. These paths bypass the flag validation invfs_statx(), allowing unsupported flags such asAT_RECURSIVEto succeed.Return
-EINVALfor unsupported flags in thevfs_fstatat()fast path, and validate flags invfs_statx_fd()as is already done invfs_statx().Fixes e896474fe485 ("getname_maybe_null() - the third variant of pathname copy-in")Signed-off-by Avi Weiss <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 44 lines
---
v2:
- return-EINVALdirectly for unsupported flags invfs_fstatat()
- validate flags invfs_statx_fd()instead of changingstatx()dispatch (as suggested by Jan Kara)fs/stat.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)fs/stat.c +10
-1@@ -322,6 +322,11 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat, u32 request_mask) {CLASS (fd_raw, f)(fd); + +if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )) +return -EINVAL ; +if (fd_empty (f))return -EBADF ;return vfs_statx_path (&fd_file (f)->f_path, flags, stat, request_mask);@@ -371,8 +376,12 @@ int vfs_fstatat(int dfd, const char __user *filename, {CLASS (filename_maybe_null, name)(filename, flags); -if (!name && dfd >=0 ) +if (!name && dfd >=0 ) { +if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )) +return -EINVAL ;return vfs_fstat (dfd, stat); + }return vfs_statx (dfd, name, flags |AT_NO_AUTOMOUNT , stat,STATX_BASIC_STATS );base-commit:
fa4ad798f6f681031775266044ba1b0cf3c670bdSignature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 9 lines · Avi Weiss
vfs_fstatat()andstatx()take the file descriptor fast path for empty paths whenAT_EMPTY_PATHis set. These paths bypass the flag validation invfs_statx(), allowing unsupported flags such asAT_RECURSIVEto succeed.Return
-EINVALfor unsupported flags in thevfs_fstatat()fast path, and validate flags invfs_statx_fd()as is already done invfs_statx().[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] fs/stat: reject invalid flags for empty paths
https://git.kernel.org/vfs/vfs/c/9a74699d0073