Re: [PATCH] ksmbd: do not read past a directory entry name in __query_dir()

From: Namjae Jeon

Date: Sat Dec 05 2026 - 07:41:21 EST


> @@ -6832,6 +6833,16 @@ static bool __query_dir(struct dir_context *ctx, const char *name, int namlen,
> priv = buf->private;
> d_info = priv->d_info;
>
> + /*
> + * The filesystem need not NUL-terminate name, and the checks below
> + * read it as a string: give them a terminated copy.
> + */
> + if (namlen >= PATH_MAX)
> + return true;
> + memcpy(priv->name_buf, name, namlen);
Could we make the veto check use namlen and check the name directly?
That would avoid copying overhead.

> + priv->name_buf[namlen] = '\0';
> + name = priv->name_buf;