Re: [PATCH v2 3/7] scsi: qedf: replace deprecated strncpy with strscpy

Kees Cook
2024-02-29T00:04:10Z

On Wed, Feb 28, 2024 at 10:59:03PM +0000, Justin Stitt wrote:
> We expect slowpath_params.name to be NUL-terminated based on its future
> usage with other string APIs:
>
> | static int qed_slowpath_start(struct qed_dev *cdev,
> | struct qed_slowpath_params *params)
> ...
> | strscpy(drv_version.name, params->name,
> | MCP_DRV_VER_STR_SIZE - 4);
>
> Moreover, NUL-padding is not necessary as the only use for this slowpath
> name parameter is to copy into the drv_version.name field.
>
> Also, let's prefer using strscpy(src, dest, sizeof(src)) in two
> instances (one of which is outside of the scsi system but it is trivial
> and related to this patch).
>
> We can see the drv_version.name size here:
> | struct qed_mcp_drv_version {
> | u32 version;
> | u8 name[MCP_DRV_VER_STR_SIZE - 4];
> | };
>
> Signed-off-by: Justin Stitt <justinstitt@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

--
Kees Cook