Re: [PATCH] proc: use strnlen() for name validation in __proc_create
From: Thorsten Blum
Date: Tue Apr 21 2026 - 10:21:31 EST
On Tue, Apr 21, 2026 at 04:02:24PM +0300, Alexey Dobriyan wrote:
> On Tue, Apr 21, 2026 at 02:26:47PM +0200, Thorsten Blum wrote:
> > Replace strlen(fn) with strnlen(fn, NAME_MAX + 1) when validating the
> > final path component in __proc_create().
> >
> > This preserves the existing name limit while bounding the length scan to
> > one byte past the maximum name length. Handle empty names separately,
> > and treat names longer than NAME_MAX as too long.
>
> 256 in the code is really U8_MAX+1 (see proc_dir_entry.namelen).
>
> The fact that NAME_MAX is also 255 is a coincidence. I didn't thought
> about NAME_MAX when writing this code.
>
> Can you just change 256 to NAME_MAX?
I assume you meant U8_MAX here ^^
I don't mind switching to U8_MAX, but NAME_MAX seems semantically better
since we're validating a filename.
Thanks,
Thorsten