s390/sclp: replace deprecated strncpy with strtomem
authorJustin Stitt <justinstitt@google.com>
Mon, 23 Oct 2023 19:14:49 +0000 (19:14 +0000)
committerVasily Gorbik <gor@linux.ibm.com>
Wed, 25 Oct 2023 13:08:30 +0000 (15:08 +0200)
Let's move away from using strncpy() as it is deprecated [1].

Instead use strtomem() as `e.id` is already marked as nonstring:
|       char id[4] __nonstring;

We don't need strtomem_pad() because `e` is already memset to 0 --
rendering any additional NUL-padding useless.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20231023-strncpy-drivers-s390-char-sclp-c-v1-1-eaeef80522bb@google.com
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
drivers/s390/char/sclp.c

index ba9b202c5deeec7a8d88f433e22bef74cb759cc8..d53ee34d398f676d4ed5983d9d7f615c9900705f 100644 (file)
@@ -81,7 +81,7 @@ static inline void sclp_trace(int prio, char *id, u32 a, u64 b, bool err)
        struct sclp_trace_entry e;
 
        memset(&e, 0, sizeof(e));
-       strncpy(e.id, id, sizeof(e.id));
+       strtomem(e.id, id);
        e.a = a;
        e.b = b;
        debug_event(&sclp_debug, prio, &e, sizeof(e));