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
Subject: [PATCH] fs/stat: reject invalid flags for empty paths
Date: Sat, 31 Oct 2026 09:58:10 +0200	[thread overview]
Message-ID: <20261031075809.3173603-2-thnkslprpt@gmail.com> (raw)

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.

Fixes: e896474fe485 ("getname_maybe_null() - the third variant of pathname copy-in")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
 fs/stat.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

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


                 reply	other threads:[~2026-10-31  7:58 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=20261031075809.3173603-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®