summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-03-23 20:13:15 +0300
committerMartin K. Petersen <martin.petersen@oracle.com>2026-03-27 23:32:44 +0300
commit665fb6a64319412f0b811e7d32b25920a177d0ff (patch)
treee0e3c1272e54bfe82d9274866ddf6368bde9c5ff
parent67557418905b103eaa7bacf81999be83accda334 (diff)
downloadlinux-665fb6a64319412f0b811e7d32b25920a177d0ff.tar.xz
scsi: target: Replace strncpy() with strscpy() in VPD dump functions
Replace the deprecated[1] strncpy() with strscpy() in transport_dump_vpd_proto_id(), transport_dump_vpd_assoc(), transport_dump_vpd_ident_type(), and transport_dump_vpd_ident(). All four functions follow the same pattern: a local buf[VPD_TMP_BUF_SIZE] (254 bytes) is zeroed with memset(), populated via sprintf()/snprintf() (always NUL-terminated), then conditionally copied to p_buf with strncpy(). The p_buf destination is used as a C string by all callers in target_core_configfs.c: strlen(buf) and sprintf(page+len, "%s", buf) to build sysfs output. NUL-padding is not required: callers in target_core_configfs.c pre-zero p_buf with memset() or initializer before calling these functions, and consume p_buf only as a NUL-terminated C string via strlen() and "%s", never exposing trailing bytes. No behavioral change: the source buf is always NUL-terminated and shorter than VPD_TMP_BUF_SIZE, so strscpy() produces identical output. Link: https://github.com/KSPP/linux/issues/90 [1] Signed-off-by: Kees Cook <kees@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://patch.msgid.link/20260323171311.work.101-kees@kernel.org Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/target/target_core_transport.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4e8d779dda5e..fad03a15c969 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1150,7 +1150,7 @@ void transport_dump_vpd_proto_id(
}
if (p_buf)
- strncpy(p_buf, buf, p_buf_len);
+ strscpy(p_buf, buf, p_buf_len);
else
pr_debug("%s", buf);
}
@@ -1200,7 +1200,7 @@ int transport_dump_vpd_assoc(
}
if (p_buf)
- strncpy(p_buf, buf, p_buf_len);
+ strscpy(p_buf, buf, p_buf_len);
else
pr_debug("%s", buf);
@@ -1260,7 +1260,7 @@ int transport_dump_vpd_ident_type(
if (p_buf) {
if (p_buf_len < strlen(buf)+1)
return -EINVAL;
- strncpy(p_buf, buf, p_buf_len);
+ strscpy(p_buf, buf, p_buf_len);
} else {
pr_debug("%s", buf);
}
@@ -1314,7 +1314,7 @@ int transport_dump_vpd_ident(
}
if (p_buf)
- strncpy(p_buf, buf, p_buf_len);
+ strscpy(p_buf, buf, p_buf_len);
else
pr_debug("%s", buf);