Re: [PATCH] ksmbd: do not read past a directory entry name in __query_dir()
From: Piyus Kedia
Date: Sat Dec 05 2026 - 15:24:03 EST
Hi Namjae,
Sorry, somehow the patch also went out as a reply to this thread. We
have submitted another patch with the fix you suggested and have also
tested it. In particular, we removed additional allocation and copy.
We reused the bound information already available in the code. Please
take a look.
https://lore.kernel.org/all/20261205195745.508424-1-piyus@xxxxxxxxxxx/
Thanks,
Piyus
On Sat, Dec 5, 2026 at 6:11 PM Namjae Jeon <linkinjeon@xxxxxxxxxx> wrote:
>
> > @@ -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;