Re: [PATCH v3] um: refactor deprecated strncpy to memcpy
From: Kees Cook
Date: Thu Aug 10 2023 - 15:05:08 EST
On Wed, Aug 09, 2023 at 06:19:32PM +0000, Justin Stitt wrote:
> Use `memcpy` since `console_buf` is not expected to be NUL-terminated
> and it more accurately describes what is happening with the buffers
> `console_buf` and `string` as per Kees' analysis [1].
>
> Also mark char buffer as `__nonstring` as per Kees' suggestion [2].
>
> This change now makes it more clear what this code does and that
> `console_buf` is not expected to be NUL-terminated.
>
> Link: https://lore.kernel.org/all/202308081708.D5ADC80F@keescook/ [1]
> Link: https://github.com/KSPP/linux/issues/90 [2]
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
> Cc: linux-hardening@xxxxxxxxxxxxxxx
> Suggested-by: Kees Cook <keescook@xxxxxxxxxxxx>
> Signed-off-by: Justin Stitt <justinstitt@xxxxxxxxxx>
Thanks for digging through this!
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
--
Kees Cook