Re: [PATCH 1/3] fuse: reject embedded NULs in readdir entry names

From: Amir Goldstein

Date: Mon Nov 16 2026 - 05:25:47 EST


On Sun, Nov 15, 2026 at 10:10 PM Junyoung Jang
<graypanda.inzag@xxxxxxxxx> wrote:
>
> parse_dirfile() and parse_dirplusfile() reject '/' in dirent->name, but
> do not check for embedded NUL bytes.
>
> Unlike plain getdents() buffers covered by verify_dirent_name() in
> fs/readdir.c, FUSE READDIRPLUS passes dirent->namelen directly to
> QSTR_INIT() in fuse_direntplus_link() and instantiates or aliases live
> dentries via d_splice_alias(). A dirent name containing an embedded NUL
> produces a dentry whose d_name.len extends past the NUL terminator,
> which allows callers such as inotify to copy uninitialized kernel slab
> memory past the NUL byte to userspace.
>
> Reject dirent names containing NUL alongside '/' in the FUSE readdir
> parsers.

My concern is that there are innocent buggy servers that pass NUL
maybe even because of length including the terminating NUL.

It would be more considerate to make this check in fuse_direntplus_link()
rather than to fail the readdir.

See precedent in:
78d04af4995a1 NFS: nfs_prime_dcache must validate the filename

Also, verify_dirent_name() never checks for embedded NUL, so all the
other filesystems can get away with this without failing readdir.

Thanks,
Amir.

>
> Fixes: 0b05b18381ee ("fuse: implement NFS-like readdirplus support")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Gwanhyun Lee <gwanhyunlee@xxxxxxxxx>
> Signed-off-by: Junyoung Jang <graypanda.inzag@xxxxxxxxx>
> ---
> fs/fuse/readdir.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
> index 1f6cf565477f..e8b47c2a9103 100644
> --- a/fs/fuse/readdir.c
> +++ b/fs/fuse/readdir.c
> @@ -126,6 +126,12 @@ static bool fuse_emit(struct file *file, struct dir_context *ctx,
> dirent->type | FILLDIR_FLAG_NOINTR);
> }
>
> +static bool fuse_invalid_dirent_name(const struct fuse_dirent *dirent)
> +{
> + return memchr(dirent->name, '/', dirent->namelen) ||
> + memchr(dirent->name, '\0', dirent->namelen);
> +}
> +
> static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
> struct dir_context *ctx)
> {
> @@ -136,7 +142,7 @@ static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
> return -EIO;
> if (reclen > nbytes)
> break;
> - if (memchr(dirent->name, '/', dirent->namelen) != NULL)
> + if (fuse_invalid_dirent_name(dirent))
> return -EIO;
>
> if (!fuse_emit(file, ctx, dirent))
> @@ -307,7 +313,7 @@ static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
> return -EIO;
> if (reclen > nbytes)
> break;
> - if (memchr(dirent->name, '/', dirent->namelen) != NULL)
> + if (fuse_invalid_dirent_name(dirent))
> return -EIO;
>
> if (!over) {
> @@ -461,7 +467,7 @@ static enum fuse_parse_result fuse_parse_cache(struct fuse_file *ff,
> return FOUND_ERR;
> if (WARN_ON(reclen > nbytes))
> return FOUND_ERR;
> - if (WARN_ON(memchr(dirent->name, '/', dirent->namelen) != NULL))
> + if (WARN_ON(fuse_invalid_dirent_name(dirent)))
> return FOUND_ERR;
>
> if (ff->readdir.pos == ctx->pos) {
> --
> 2.43.0