Skip to content

Commit 5e10335

Browse files
committed
ses: fix additional element traversal bug
KASAN found that our additional element processing scripts drop off the end of the VPD page into unallocated space. The reason is that not every element has additional information but our traversal routines think they do, leading to them expecting far more additional information than is present. Fix this by adding a gate to the traversal routine so that it only processes elements that are expected to have additional information (list is in SES-2 section 6.1.13.1: Additional Element Status diagnostic page overview) Reported-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com> Tested-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com> Cc: stable@vger.kernel.org Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent 3417c1b commit 5e10335

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

drivers/scsi/ses.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,15 @@ static void ses_enclosure_data_process(struct enclosure_device *edev,
559559
if (desc_ptr)
560560
desc_ptr += len;
561561

562-
if (addl_desc_ptr)
562+
if (addl_desc_ptr &&
563+
/* only find additional descriptions for specific devices */
564+
(type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
565+
type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE ||
566+
type_ptr[0] == ENCLOSURE_COMPONENT_SAS_EXPANDER ||
567+
/* these elements are optional */
568+
type_ptr[0] == ENCLOSURE_COMPONENT_SCSI_TARGET_PORT ||
569+
type_ptr[0] == ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT ||
570+
type_ptr[0] == ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS))
563571
addl_desc_ptr += addl_desc_ptr[1] + 2;
564572

565573
}

include/linux/enclosure.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
/* A few generic types ... taken from ses-2 */
3030
enum enclosure_component_type {
3131
ENCLOSURE_COMPONENT_DEVICE = 0x01,
32+
ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07,
33+
ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
34+
ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
3235
ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
36+
ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
3337
};
3438

3539
/* ses-2 common element status */

0 commit comments

Comments
 (0)