2023-06-20 20:15:32

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: Replace strlcpy with strscpy

On Tue, Jun 20, 2023 at 08:08:32PM +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated [1].
> In an effort to remove strlcpy() completely [2], replace
> strlcpy() here with strscpy().
>
> Direct replacement is safe here since return value of -errno
> is used to check for truncation instead of sizeof(dest).
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
> [2] https://github.com/KSPP/linux/issues/89
>
> Signed-off-by: Azeem Shaikh <[email protected]>

Thanks for fixing up the variable type. (And thank you Eric for catching
the signedness problem!)

Reviewed-by: Kees Cook <[email protected]>

--
Kees Cook


2023-07-10 02:46:56

by Azeem Shaikh

[permalink] [raw]
Subject: Re: [PATCH v2] crypto: Replace strlcpy with strscpy

On Tue, Jun 20, 2023 at 4:12 PM Kees Cook <[email protected]> wrote:
>
> On Tue, Jun 20, 2023 at 08:08:32PM +0000, Azeem Shaikh wrote:
> > strlcpy() reads the entire source buffer first.
> > This read may exceed the destination size limit.
> > This is both inefficient and can lead to linear read
> > overflows if a source string is not NUL-terminated [1].
> > In an effort to remove strlcpy() completely [2], replace
> > strlcpy() here with strscpy().
> >
> > Direct replacement is safe here since return value of -errno
> > is used to check for truncation instead of sizeof(dest).
> >
> > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
> > [2] https://github.com/KSPP/linux/issues/89
> >
> > Signed-off-by: Azeem Shaikh <[email protected]>
>
> Thanks for fixing up the variable type. (And thank you Eric for catching
> the signedness problem!)
>
> Reviewed-by: Kees Cook <[email protected]>
>

Friendly ping on this.