mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Weiss <thnkslprpt@gmail.com>
To: Christian Brauner <brauner@kernel.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Avi Weiss <thnkslprpt@gmail.com>
Subject: [PATCH v2] fs/stat: reject invalid flags for empty paths
Date: Sun,  8 Nov 2026 14:56:18 +0200	[thread overview]
Message-ID: <20261108125617.2383285-2-thnkslprpt@gmail.com> (raw)

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().

Fixes: e896474fe485 ("getname_maybe_null() - the third variant of pathname copy-in")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
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(-)

diff --git a/fs/stat.c b/fs/stat.c
index a2e63c6c45b7..3013e4ece011 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -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
-- 
2.43.0


                 reply	other threads:[~2026-11-08 12:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261108125617.2383285-2-thnkslprpt@gmail.com \
    --to=thnkslprpt@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®