mpt3sas: Ensure the connector_name string is NUL-terminated
authorCalvin Owens <calvinowens@fb.com>
Thu, 28 Jul 2016 04:45:51 +0000 (21:45 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 9 Aug 2016 01:05:58 +0000 (21:05 -0400)
We blindly trust the hardware to give us NUL-terminated strings, which
is a bad idea because it doesn't always do that. For example:

  [  481.184784] mpt3sas_cm0:  enclosure level(0x0000), connector name(     \x3)

In this case, connector_name is four spaces. We got lucky here because
the 2nd byte beyond our character array happens to be a NUL. Fix this by
explicitly writing '\0' to the end of the string to ensure we don't run
off the edge of the world in printk().

Signed-off-by: Calvin Owens <calvinowens@fb.com>
Acked-by: Chaitra P B <chaitra.basappa@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/mpt3sas/mpt3sas_base.h
drivers/scsi/mpt3sas/mpt3sas_scsih.c

index 892c9be008b504b5b7eb57438496549bdd034ead..eb7f5b0174ba7b9f3012467a0e63e37a7e69e81e 100644 (file)
@@ -478,7 +478,7 @@ struct _sas_device {
        u8      pfa_led_on;
        u8      pend_sas_rphy_add;
        u8      enclosure_level;
-       u8      connector_name[4];
+       u8      connector_name[5];
        struct kref refcount;
 };
 
index cd91a684c945a2c62e8c3626f6e1001c96935d35..acabe48350fedc0b68fcf312651ce7d3c05c8312 100644 (file)
@@ -5380,8 +5380,9 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc,
                     MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
                        sas_device->enclosure_level =
                                le16_to_cpu(sas_device_pg0.EnclosureLevel);
-                       memcpy(&sas_device->connector_name[0],
-                               &sas_device_pg0.ConnectorName[0], 4);
+                       memcpy(sas_device->connector_name,
+                               sas_device_pg0.ConnectorName, 4);
+                       sas_device->connector_name[4] = '\0';
                } else {
                        sas_device->enclosure_level = 0;
                        sas_device->connector_name[0] = '\0';
@@ -5508,8 +5509,9 @@ _scsih_add_device(struct MPT3SAS_ADAPTER *ioc, u16 handle, u8 phy_num,
        if (sas_device_pg0.Flags & MPI2_SAS_DEVICE0_FLAGS_ENCL_LEVEL_VALID) {
                sas_device->enclosure_level =
                        le16_to_cpu(sas_device_pg0.EnclosureLevel);
-               memcpy(&sas_device->connector_name[0],
-                       &sas_device_pg0.ConnectorName[0], 4);
+               memcpy(sas_device->connector_name,
+                       sas_device_pg0.ConnectorName, 4);
+               sas_device->connector_name[4] = '\0';
        } else {
                sas_device->enclosure_level = 0;
                sas_device->connector_name[0] = '\0';