summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Henzl <thenzl@redhat.com>2023-02-02 19:24:50 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-03-10 11:34:29 +0300
commit414418abc19fa4ccf730d273061a426c07a061d6 (patch)
tree4abb112db6eb8cd66b3a84b5b7822791be5cf172
parent27067c672980b497cc34048b69b12820851ac6b9 (diff)
downloadlinux-414418abc19fa4ccf730d273061a426c07a061d6.tar.xz
scsi: ses: Fix possible desc_ptr out-of-bounds accesses
commit 801ab13d50cf3d26170ee073ea8bb4eececb76ab 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>
-rw-r--r--drivers/scsi/ses.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index 4b66f9aec0f4..77f4322e2f71 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -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 ||