From: Haobin Wu <853555@gmail.com>
To: ericvh@kernel.org, lucho@ionkov.net, asmadeus@codewreck.org,
v9fs@lists.linux.dev
Cc: linux_oss@crudebyte.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, aneesh.kumar@linux.vnet.ibm.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, jack@suse.cz, willy@infradead.org,
dhowells@redhat.com, viro@zeniv.linux.org.uk, brauner@kernel.org
Subject: [PATCH v2 2/2] 9p: skip directory entries with names longer than NAME_MAX
Date: Wed, 16 Sep 2026 21:54:03 +0800 [thread overview]
Message-ID: <20260916135403.15789-3-853555@gmail.com> (raw)
In-Reply-To: <20260916135403.15789-1-853555@gmail.com>
The 9p wire format carries directory entry names of up to 65535 bytes
and nothing on the client checks them against NAME_MAX. Since the
previous patch, v9fs_dir_readdir_dotl() passes such names straight to
dir_emit(), and the VFS only rejects names of PATH_MAX bytes or more in
verify_dirent_name(), as -EIO, which again fails the whole getdents64()
call.
A name between NAME_MAX and PATH_MAX is therefore returned to userspace
even though every later operation on it fails with -ENAMETOOLONG, and
POSIX requires readdir() to only return components of at most NAME_MAX
bytes. Nothing can use such an entry, so skip it instead of returning it
or failing the listing, reusing the strlen() result that was already
computed for dir_emit().
Suggested-by: Dominique Martinet <asmadeus@codewreck.org>
Link: https://lore.kernel.org/all/vz5bum547fqyxf5z4m3x7tuqkuq52jlopm65t7hvynqeulh7i3@2t4wnhfxs7qv/
Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Haobin Wu <853555@gmail.com>
---
fs/9p/vfs_dir.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index af00b79d801e..ad6fdc99883d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -173,6 +173,7 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx)
}
while (rdir->head < rdir->tail) {
+ size_t namelen;
err = p9dirent_read(fid->clnt, rdir->buf + rdir->head,
rdir->tail - rdir->head,
@@ -182,10 +183,14 @@ static int v9fs_dir_readdir_dotl(struct file *file, struct dir_context *ctx)
return -EIO;
}
- if (!dir_emit(ctx, curdirent.d_name,
- strlen(curdirent.d_name),
- QID2INO(&curdirent.qid),
- curdirent.d_type)) {
+ namelen = strlen(curdirent.d_name);
+ if (namelen > NAME_MAX) {
+ p9_debug(P9_DEBUG_VFS,
+ "skipping entry with %zu byte name\n",
+ namelen);
+ } else if (!dir_emit(ctx, curdirent.d_name, namelen,
+ QID2INO(&curdirent.qid),
+ curdirent.d_type)) {
kfree(curdirent.d_name);
return 0;
}
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-09-16 13:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 13:54 [PATCH v2 0/2] 9p: handle long directory entry names in readdir Haobin Wu
2026-09-16 13:54 ` [PATCH v2 1/2] 9p: skip intermediate directory entry name copy in p9dirent_read() Haobin Wu
2026-09-16 13:54 ` Haobin Wu [this message]
2026-09-16 20:02 ` [PATCH v2 2/2] 9p: skip directory entries with names longer than NAME_MAX Christian Schoenebeck
2026-09-16 22:45 ` Dominique Martinet
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=20260916135403.15789-3-853555@gmail.com \
--to=853555@gmail.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=asmadeus@codewreck.org \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=ericvh@kernel.org \
--cc=horms@kernel.org \
--cc=jack@suse.cz \
--cc=kuba@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=v9fs@lists.linux.dev \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/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®