scsi: ses: Fix possible desc_ptr out-of-bounds accesses

commit 801ab13d50 upstream.

Sanitize possible desc_ptr out-of-bounds accesses in
ses_enclosure_data_process().

Link: https://lore.kernel.org/r/20230202162451.15346-4-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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Tomas Henzl 2023-02-02 17:24:50 +01:00 коммит произвёл Greg Kroah-Hartman
Родитель 384aa697d8
Коммит 584892fd29
1 изменённых файлов: 9 добавлений и 5 удалений

Просмотреть файл

@ -572,15 +572,19 @@ static void ses_enclosure_data_process(struct enclosure_device *edev,
int max_desc_len;
if (desc_ptr) {
if (desc_ptr >= buf + page7_len) {
if (desc_ptr + 3 >= buf + page7_len) {
desc_ptr = NULL;
} else {
len = (desc_ptr[2] << 8) + desc_ptr[3];
desc_ptr += 4;
/* Add trailing zero - pushes into
* reserved space */
desc_ptr[len] = '\0';
name = desc_ptr;
if (desc_ptr + len > buf + page7_len)
desc_ptr = NULL;
else {
/* Add trailing zero - pushes into
* reserved space */
desc_ptr[len] = '\0';
name = desc_ptr;
}
}
}
if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||