scsi: qedf: Avoid reading past end of buffer
authorKees Cook <keescook@chromium.org>
Fri, 5 May 2017 22:42:55 +0000 (15:42 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 9 May 2017 02:07:48 +0000 (22:07 -0400)
Using memcpy() from a string that is shorter than the length copied
means the destination buffer is being filled with arbitrary data from
the kernel rodata segment. Instead, use strncpy() which will fill the
trailing bytes with zeros.

This was found with the future CONFIG_FORTIFY_SOURCE feature.

Cc: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Chad Dupuis <chad.dupuis@cavium.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/qedf/qedf_main.c

index cceddd995a4bf46605ae94143cfcff9df693fb83..a5c97342fd5d2bc5f9826d34974e8d7b7c285dd3 100644 (file)
@@ -2895,7 +2895,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode)
        slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER;
        slowpath_params.drv_rev = QEDF_DRIVER_REV_VER;
        slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER;
-       memcpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
+       strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE);
        rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params);
        if (rc) {
                QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n");