scsi: qedf: Replace deprecated strncpy() with strscpy()
authorJustin Stitt <justinstitt@google.com>
Tue, 5 Mar 2024 23:34:38 +0000 (23:34 +0000)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sun, 10 Mar 2024 22:37:43 +0000 (18:37 -0400)
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];
| };

Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240305-strncpy-drivers-scsi-mpi3mr-mpi3mr_fw-c-v3-3-5b78a13ff984@google.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/net/ethernet/qlogic/qed/qed_main.c
drivers/scsi/qedf/qedf_main.c

index c278f8893042b3a88466452cd205348aebac609c..d39e198fe8dbe8f6f32df9a74fb8ce506470ca0c 100644 (file)
@@ -1351,7 +1351,7 @@ static int qed_slowpath_start(struct qed_dev *cdev,
                                      (params->drv_rev << 8) |
                                      (params->drv_eng);
                strscpy(drv_version.name, params->name,
-                       MCP_DRV_VER_STR_SIZE - 4);
+                       sizeof(drv_version.name));
                rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
                                              &drv_version);
                if (rc) {
index a58353b7b4e8bad1430581b09cb0c08a8b85125c..fd12439cbaab6bf6df58d2bc76e1b282b0392ad0 100644 (file)
@@ -3468,7 +3468,7 @@ retry_probe:
        slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER;
        slowpath_params.drv_rev = QEDF_DRIVER_REV_VER;
        slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER;
-       strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
+       strscpy(slowpath_params.name, "qedf", sizeof(slowpath_params.name));
        rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params);
        if (rc) {
                QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n");