* [PATCH] auxdisplay: panel: refactor deprecated strncpy
@ 2023-09-11 20:51 Justin Stitt
2023-09-15 3:18 ` Kees Cook
2023-09-29 18:42 ` Kees Cook
0 siblings, 2 replies; 4+ messages in thread
From: Justin Stitt @ 2023-09-11 20:51 UTC (permalink / raw
To: Willy Tarreau, Ksenija Stanojevic, Miguel Ojeda
Cc: linux-kernel, linux-hardening, Kees Cook, Justin Stitt
`strncpy` is deprecated and as such we should prefer more robust and
less ambiguous interfaces.
In this case, all of `press_str`, `repeat_str` and `release_str` are
explicitly marked as nonstring:
| struct { /* valid when type == INPUT_TYPE_KBD */
| char press_str[sizeof(void *) + sizeof(int)] __nonstring;
| char repeat_str[sizeof(void *) + sizeof(int)] __nonstring;
| char release_str[sizeof(void *) + sizeof(int)] __nonstring;
| } kbd;
... which makes `strtomem_pad` a suitable replacement as it is
functionally the same whilst being more obvious about its behavior.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Note: build-tested
---
drivers/auxdisplay/panel.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c
index eba04c0de7eb..e20d35bdf5fe 100644
--- a/drivers/auxdisplay/panel.c
+++ b/drivers/auxdisplay/panel.c
@@ -1449,10 +1449,9 @@ static struct logical_input *panel_bind_key(const char *name, const char *press,
key->rise_time = 1;
key->fall_time = 1;
- strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
- strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
- strncpy(key->u.kbd.release_str, release,
- sizeof(key->u.kbd.release_str));
+ strtomem_pad(key->u.kbd.press_str, press, '\0');
+ strtomem_pad(key->u.kbd.repeat_str, repeat, '\0');
+ strtomem_pad(key->u.kbd.release_str, release, '\0');
list_add(&key->list, &logical_inputs);
return key;
}
---
base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
change-id: 20230911-strncpy-drivers-auxdisplay-panel-c-83bce51f32cb
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] auxdisplay: panel: refactor deprecated strncpy
2023-09-11 20:51 [PATCH] auxdisplay: panel: refactor deprecated strncpy Justin Stitt
@ 2023-09-15 3:18 ` Kees Cook
2023-09-29 18:42 ` Kees Cook
1 sibling, 0 replies; 4+ messages in thread
From: Kees Cook @ 2023-09-15 3:18 UTC (permalink / raw
To: Justin Stitt
Cc: Willy Tarreau, Ksenija Stanojevic, Miguel Ojeda, linux-kernel,
linux-hardening
On Mon, Sep 11, 2023 at 08:51:04PM +0000, Justin Stitt wrote:
> `strncpy` is deprecated and as such we should prefer more robust and
> less ambiguous interfaces.
>
> In this case, all of `press_str`, `repeat_str` and `release_str` are
> explicitly marked as nonstring:
> | struct { /* valid when type == INPUT_TYPE_KBD */
> | char press_str[sizeof(void *) + sizeof(int)] __nonstring;
> | char repeat_str[sizeof(void *) + sizeof(int)] __nonstring;
> | char release_str[sizeof(void *) + sizeof(int)] __nonstring;
> | } kbd;
>
> ... which makes `strtomem_pad` a suitable replacement as it is
> functionally the same whilst being more obvious about its behavior.
Yup, this is exactly what strtomem_pad() was made for. :)
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
> Note: build-tested
> ---
> drivers/auxdisplay/panel.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c
> index eba04c0de7eb..e20d35bdf5fe 100644
> --- a/drivers/auxdisplay/panel.c
> +++ b/drivers/auxdisplay/panel.c
> @@ -1449,10 +1449,9 @@ static struct logical_input *panel_bind_key(const char *name, const char *press,
> key->rise_time = 1;
> key->fall_time = 1;
>
> - strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
> - strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
> - strncpy(key->u.kbd.release_str, release,
> - sizeof(key->u.kbd.release_str));
> + strtomem_pad(key->u.kbd.press_str, press, '\0');
> + strtomem_pad(key->u.kbd.repeat_str, repeat, '\0');
> + strtomem_pad(key->u.kbd.release_str, release, '\0');
> list_add(&key->list, &logical_inputs);
> return key;
> }
>
> ---
> base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c
> change-id: 20230911-strncpy-drivers-auxdisplay-panel-c-83bce51f32cb
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] auxdisplay: panel: refactor deprecated strncpy
2023-09-11 20:51 [PATCH] auxdisplay: panel: refactor deprecated strncpy Justin Stitt
2023-09-15 3:18 ` Kees Cook
@ 2023-09-29 18:42 ` Kees Cook
2023-09-29 18:47 ` Miguel Ojeda
1 sibling, 1 reply; 4+ messages in thread
From: Kees Cook @ 2023-09-29 18:42 UTC (permalink / raw
To: Willy Tarreau, Ksenija Stanojevic, Miguel Ojeda, Justin Stitt
Cc: Kees Cook, linux-kernel, linux-hardening
On Mon, 11 Sep 2023 20:51:04 +0000, Justin Stitt wrote:
> `strncpy` is deprecated and as such we should prefer more robust and
> less ambiguous interfaces.
>
> In this case, all of `press_str`, `repeat_str` and `release_str` are
> explicitly marked as nonstring:
> | struct { /* valid when type == INPUT_TYPE_KBD */
> | char press_str[sizeof(void *) + sizeof(int)] __nonstring;
> | char repeat_str[sizeof(void *) + sizeof(int)] __nonstring;
> | char release_str[sizeof(void *) + sizeof(int)] __nonstring;
> | } kbd;
>
> [...]
Applied to for-next/hardening, thanks!
[1/1] auxdisplay: panel: refactor deprecated strncpy
https://git.kernel.org/kees/c/0456f788873d
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] auxdisplay: panel: refactor deprecated strncpy
2023-09-29 18:42 ` Kees Cook
@ 2023-09-29 18:47 ` Miguel Ojeda
0 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2023-09-29 18:47 UTC (permalink / raw
To: Kees Cook
Cc: Willy Tarreau, Ksenija Stanojevic, Miguel Ojeda, Justin Stitt,
linux-kernel, linux-hardening
On Fri, Sep 29, 2023 at 8:42 PM Kees Cook <keescook@chromium.org> wrote:
>
> Applied to for-next/hardening, thanks!
Thanks for picking it up!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-29 18:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-11 20:51 [PATCH] auxdisplay: panel: refactor deprecated strncpy Justin Stitt
2023-09-15 3:18 ` Kees Cook
2023-09-29 18:42 ` Kees Cook
2023-09-29 18:47 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).