Re: + procfs-replace-all-non-returning-strlcpy-with-strscpy.patch added to mm-nonmm-unstable branch

From: Alexey Dobriyan
Date: Sat May 13 2023 - 06:55:34 EST


On Wed, May 10, 2023 at 09:34:49PM -0700, Andrew Morton wrote:
> Subject: procfs: replace all non-returning strlcpy with strscpy
> 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].

This is funny. C strings are always NUL-terminated by definition.

Reviewed-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>

> --- a/fs/proc/kcore.c~procfs-replace-all-non-returning-strlcpy-with-strscpy
> +++ a/fs/proc/kcore.c
> @@ -419,7 +419,7 @@ static ssize_t read_kcore_iter(struct ki
> char *notes;
> size_t i = 0;
>
> - strlcpy(prpsinfo.pr_psargs, saved_command_line,
> + strscpy(prpsinfo.pr_psargs, saved_command_line,
> sizeof(prpsinfo.pr_psargs));
>
> notes = kzalloc(notes_len, GFP_KERNEL);