Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: ibmvscsi: Replace all non-returning strlcpy with strscpy

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Acked-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230517143409.1520298-1-azeemshaikh38@gmail.com

authored by

Azeem Shaikh and committed by
Kees Cook
3b92d34a 883f8fe8

+3 -3
+3 -3
drivers/scsi/ibmvscsi/ibmvscsi.c
··· 250 250 251 251 ppartition_name = of_get_property(of_root, "ibm,partition-name", NULL); 252 252 if (ppartition_name) 253 - strlcpy(partition_name, ppartition_name, 253 + strscpy(partition_name, ppartition_name, 254 254 sizeof(partition_name)); 255 255 p_number_ptr = of_get_property(of_root, "ibm,partition-no", NULL); 256 256 if (p_number_ptr) ··· 1282 1282 if (hostdata->client_migrated) 1283 1283 hostdata->caps.flags |= cpu_to_be32(CLIENT_MIGRATED); 1284 1284 1285 - strlcpy(hostdata->caps.name, dev_name(&hostdata->host->shost_gendev), 1285 + strscpy(hostdata->caps.name, dev_name(&hostdata->host->shost_gendev), 1286 1286 sizeof(hostdata->caps.name)); 1287 1287 1288 1288 location = of_get_property(of_node, "ibm,loc-code", NULL); 1289 1289 location = location ? location : dev_name(hostdata->dev); 1290 - strlcpy(hostdata->caps.loc, location, sizeof(hostdata->caps.loc)); 1290 + strscpy(hostdata->caps.loc, location, sizeof(hostdata->caps.loc)); 1291 1291 1292 1292 req->common.type = cpu_to_be32(VIOSRP_CAPABILITIES_TYPE); 1293 1293 req->buffer = cpu_to_be64(hostdata->caps_addr);