Skip to content

9p: handle long directory entry names in readdir

Haobin Wu linux-fsdevel lkml netdev v9fs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 4 repliesIn review
  2. v22 patches 2 repliesSuperseded

Changes in v3 from the cover letter

- Patch 2: say why the entry is skipped in the debug message and log it at P9_DEBUG_ERROR, the level of the strscpy() message it replaces (Christian, Dominique).
- New patch 3: same NAME_MAX limit in v9fs_dir_readdir() for legacy 9p2000(.u), as its own commit (Christian, Dominique).
- Dropped the Assisted-by: trailers.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/39p: skip intermediate directory entry name copy in p9dirent_read()fs/9p/vfs_dir.c include/net/9p/client.h net/9p/protocol.c+8 -121 reply
2/39p: skip directory entries with names longer than NAME_MAXfs/9p/vfs_dir.c+9 -41 reply
3/39p: skip over-long directory entry names for legacy 9p2000 toofs/9p/vfs_dir.c+12 -22 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchChristian Schoenebeck
1/3R-b
2/3R-b
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] 9p: handle long directory entry names in readdir

A host directory entry whose name is longer than 255 bytes currently makes 9p's readdir fail with -EIO and hides every entry after it, which is how this was noticed on WSL (Plan 9 shares of Windows drives).

Patch 1 drops the copy into the fixed 256-byte p9_dirent::d_name and uses the string p9pdu_vreadf() already allocated, so the listing no longer aborts.

Patch 2 then skips entries whose name is longer than NAME_MAX in the 9p2000.L readdir instead of returning them to userspace, as discussed with Dominique and Jan on v1: the VFS only enforces PATH_MAX in verify_dirent_name(), and nothing can operate on such a name afterwards anyway.

Patch 3 applies the same limit to the legacy 9p2000/9p2000.u readdir. It is a separate commit because it changes behaviour there: such names used to be listed.

On patch 3, to be explicit about why this is a behaviour change: the 256-byte limit lives in p9dirent_read(), whose only caller is the 9p2000.L path. v9fs_dir_readdir() parses with p9stat_read(), where p9_wstat::name comes from the 's' conversion (kmalloc(len + 1), no NAME_MAX check), so legacy really did emit over-long names.

Changes since v2:
- Patch 2: say why the entry is skipped in the debug message and log it at P9_DEBUG_ERROR, the level of the strscpy() message it replaces (Christian, Dominique).
- New patch 3: same NAME_MAX limit in v9fs_dir_readdir() for legacy 9p2000(.u), as its own commit (Christian, Dominique).
- Dropped the Assisted-by: trailers.

Changes since v1:
- Use my real name in From/Signed-off-by (Dominique).
- Split into two patches (Dominique).
- Reworded the subject and commit message of patch 1 to describe the existing readdir path and clarify that no allocation is added (Dominique).
- New patch 2 skipping entries longer than NAME_MAX (Dominique, Jan).
- Dropped the bouncing [email protected] address from Cc.

v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Haobin Wu (3):
9p: skip intermediate directory entry name copy in p9dirent_read() 9p: skip directory entries with names longer than NAME_MAX 9p: skip over-long directory entry names for legacy 9p2000 too

 fs/9p/vfs_dir.c         | 31 +++++++++++++++++++++++++------
 include/net/9p/client.h |  2 +-
 net/9p/protocol.c       | 12 ++----------
 3 files changed, 28 insertions(+), 17 deletions(-)

base-commit: 028ef9c96e96197026887c0f092424679298aae8

Signature · 1 line
2.54.0 (Apple Git-157)