Skip to content

Commit de055e6

Browse files
JustinStittkees
authored andcommitted
bus: fsl-mc: Replace deprecated strncpy() with strscpy_pad()
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. We need to prefer more robust and less ambiguous string interfaces. `obj_desc->(type|label)` are expected to be NUL-terminated strings as per "include/linux/fsl/mc.h +143" | ... | * struct fsl_mc_obj_desc - Object descriptor | * @type: Type of object: NULL terminated string | ... It seems `cmd_params->obj_type` is also expected to be a NUL-terminated string. A suitable replacement is `strscpy_pad` due to the fact that it guarantees NUL-termination on the destination buffer whilst keeping the NUL-padding behavior that `strncpy` provides. Padding may not strictly be necessary but let's opt to keep it as this ensures no functional change. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: KSPP#90 Cc: [email protected] Cc: Kees Cook <[email protected]> Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/20230912-strncpy-drivers-bus-fsl-mc-dprc-c-v1-1-cdb56aa3f4f4@google.com Signed-off-by: Kees Cook <[email protected]>
1 parent a952abc commit de055e6

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/bus/fsl-mc/dprc.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,8 @@ int dprc_get_obj(struct fsl_mc_io *mc_io,
450450
obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
451451
obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
452452
obj_desc->flags = le16_to_cpu(rsp_params->flags);
453-
strncpy(obj_desc->type, rsp_params->type, 16);
454-
obj_desc->type[15] = '\0';
455-
strncpy(obj_desc->label, rsp_params->label, 16);
456-
obj_desc->label[15] = '\0';
453+
strscpy_pad(obj_desc->type, rsp_params->type, 16);
454+
strscpy_pad(obj_desc->label, rsp_params->label, 16);
457455
return 0;
458456
}
459457
EXPORT_SYMBOL_GPL(dprc_get_obj);
@@ -491,8 +489,7 @@ int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
491489
cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
492490
cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
493491
cmd_params->obj_id = cpu_to_le32(obj_id);
494-
strncpy(cmd_params->obj_type, obj_type, 16);
495-
cmd_params->obj_type[15] = '\0';
492+
strscpy_pad(cmd_params->obj_type, obj_type, 16);
496493

497494
/* send command to mc*/
498495
return mc_send_command(mc_io, &cmd);
@@ -564,8 +561,7 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
564561
cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params;
565562
cmd_params->obj_id = cpu_to_le32(obj_id);
566563
cmd_params->region_index = region_index;
567-
strncpy(cmd_params->obj_type, obj_type, 16);
568-
cmd_params->obj_type[15] = '\0';
564+
strscpy_pad(cmd_params->obj_type, obj_type, 16);
569565

570566
/* send command to mc*/
571567
err = mc_send_command(mc_io, &cmd);

0 commit comments

Comments
 (0)