fs/stat: reject invalid flags for empty paths
PATCH 1/1 fs/stat: reject invalid flags for empty paths
vfs_fstatat() and statx() take the file descriptor fast path when AT_EMPTY_PATH is set, even if unsupported flag bits are present. This bypasses vfs_statx() flag validation and lets both syscalls succeed with AT_RECURSIVE.
Restrict the fast paths to supported flags so invalid combinations fall through to vfs_statx() and return -EINVAL.
--- fs/stat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/stat.c +6 -2
@@ -371,7 +371,9 @@ int vfs_fstatat(int dfd, const char __user *filename, {CLASS (filename_maybe_null, name)(filename, flags); -if (!name && dfd >=0 ) +if (!name && dfd >=0 && + !(flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )))return vfs_fstat (dfd, stat); return vfs_statx(dfd, name, flags | AT_NO_AUTOMOUNT,
@@ -812,7 +814,9 @@ SYSCALL_DEFINE5(statx, {CLASS (filename_maybe_null, name)(filename, flags); -if (!name && dfd >=0 ) +if (!name && dfd >=0 && + !(flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )))return do_statx_fd (dfd, flags & ~AT_NO_AUTOMOUNT , mask, buffer);return do_statx (dfd, name, flags, mask, buffer);
base-commit: 36aad21d50d1af3f6954bb0c988257a908202477
Signature · 1 line
2.43.0
Jan Kara
reviewerQuoted 19 lines · Avi Weiss
vfs_fstatat()andstatx()take the file descriptor fast path whenAT_EMPTY_PATHis set, even if unsupported flag bits are present. This bypassesvfs_statx()flag validation and lets both syscalls succeed withAT_RECURSIVE.Restrict the fast paths to supported flags so invalid combinations fall through to
vfs_statx()and return-EINVAL.Fixes e896474fe485 ("getname_maybe_null() - the third variant of pathname copy-in")Signed-off-by Avi Weiss <[email protected]>--- fs/stat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)fs/stat.c +0
-0
fs/stat.c int vfs_fstatat(int dfd, const char __user *filename, · line 377
Quoted 8 lines
fs/stat.c +3
-1@@ -371,7 +371,9 @@ int vfs_fstatat(int dfd, const char __user *filename, {CLASS (filename_maybe_null, name)(filename, flags); -if (!name && dfd >=0 ) +if (!name && dfd >=0 && + !(flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )))return vfs_fstat (dfd, stat);
Shouldn't we just return EINVAL in the case of unsupported flag instead of falling back to vfs_statx() to fail?
fs/stat.c SYSCALL_DEFINE5(statx, · line 820
Quoted 10 lines
fs/stat.c +3
-1return vfs_statx(dfd, name, flags | AT_NO_AUTOMOUNT,@@ -812,7 +814,9 @@ SYSCALL_DEFINE5(statx, {CLASS (filename_maybe_null, name)(filename, flags); -if (!name && dfd >=0 ) +if (!name && dfd >=0 && + !(flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | +AT_EMPTY_PATH |AT_STATX_SYNC_TYPE )))return do_statx_fd (dfd, flags & ~AT_NO_AUTOMOUNT , mask, buffer);
For symmetry this belongs to vfs_statx_fd() similarly as in the other path the checks are done in vfs_statx().
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR