s390/ipl: refactor deprecated strncpy
authorJustin Stitt <justinstitt@google.com>
Fri, 11 Aug 2023 21:56:15 +0000 (21:56 +0000)
committerHeiko Carstens <hca@linux.ibm.com>
Fri, 18 Aug 2023 13:08:12 +0000 (15:08 +0200)
`strncpy` is deprecated for use on NUL-terminated destination strings [1].

Use `strscpy` which has the same behavior as `strncpy` here with the
extra safeguard of guaranteeing NUL-termination of destination
strings.  In it's current form, this may result in silent truncation
if the src string has the same size as the destination string.

[hca@linux.ibm.com: use strscpy() instead of strscpy_pad()]
Link: 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
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230811-arch-s390-kernel-v1-1-7edbeeab3809@google.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/kernel/ipl.c

index 7f3a84e414a47c702981b922f23c1fd79ff616cc..05e51666db033f1b82f2efb1439c2c3ea5e99364 100644 (file)
@@ -266,7 +266,7 @@ static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj,        \
                struct kobj_attribute *attr,                            \
                const char *buf, size_t len)                            \
 {                                                                      \
-       strncpy(_value, buf, sizeof(_value) - 1);                       \
+       strscpy(_value, buf, sizeof(_value));                           \
        strim(_value);                                                  \
        return len;                                                     \
 }                                                                      \