diff options
author | Tomas Henzl <thenzl@redhat.com> | 2023-02-02 17:24:50 +0100 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2023-02-21 23:32:04 +0100 |
commit | 801ab13d50cf3d26170ee073ea8bb4eececb76ab (patch) | |
tree | c25665ddd28628cae9faf093a4023ba657b0ae74 | |
parent | scsi: ses: Fix possible addl_desc_ptr out-of-bounds accesses (diff) | |
download | linux-801ab13d50cf3d26170ee073ea8bb4eececb76ab.tar.xz linux-801ab13d50cf3d26170ee073ea8bb4eececb76ab.zip |
scsi: ses: Fix possible desc_ptr out-of-bounds accesses
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>
-rw-r--r-- | drivers/scsi/ses.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c index 458ca7abbbef..f8031d0782f7 100644 --- a/drivers/scsi/ses.c +++ b/drivers/scsi/ses.c @@ -578,15 +578,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 || |