scsi: ses: Fix slab-out-of-bounds in ses_enclosure_data_process()
authorTomas Henzl <thenzl@redhat.com>
Thu, 2 Feb 2023 16:24:48 +0000 (17:24 +0100)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 21 Feb 2023 22:32:03 +0000 (17:32 -0500)
A fix for:

BUG: KASAN: slab-out-of-bounds in ses_enclosure_data_process+0x949/0xe30 [ses]
Read of size 1 at addr ffff88a1b043a451 by task systemd-udevd/3271

Checking after (and before in next loop) addl_desc_ptr[1] is sufficient, we
expect the size to be sanitized before first access to addl_desc_ptr[1].
Make sure we don't walk beyond end of page.

Link: https://lore.kernel.org/r/20230202162451.15346-2-thenzl@redhat.com
Cc: stable@vger.kernel.org
Signed-off-by: Tomas Henzl <thenzl@redhat.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/ses.c

index 869ca9c..034d605 100644 (file)
@@ -609,9 +609,11 @@ static void ses_enclosure_data_process(struct enclosure_device *edev,
                             /* these elements are optional */
                             type_ptr[0] == ENCLOSURE_COMPONENT_SCSI_TARGET_PORT ||
                             type_ptr[0] == ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT ||
-                            type_ptr[0] == ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS))
+                            type_ptr[0] == ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS)) {
                                addl_desc_ptr += addl_desc_ptr[1] + 2;
-
+                               if (addl_desc_ptr + 1 >= ses_dev->page10 + ses_dev->page10_len)
+                                       addl_desc_ptr = NULL;
+                       }
                }
        }
        kfree(buf);