mvumi_show_event() prints param_count u32 words from params[] and sense_data_length bytes from sense_data[], but both counts come from the firmware event (struct mvumi_driver_event) and are never checked against the arrays, which hold four words and 30 bytes. A firmware that reports the maximum (255 each) makes the loops read far past the event and past the 512-byte buffer the event block is allocated in, printing the result to the kernel log. Stop each loop at the size of its array. Fixes: f0c568a478f0 ("[SCSI] mvumi: Add Marvell UMI driver") Cc: stable@vger.kernel.org Signed-off-by: Yehyeong Lee --- drivers/scsi/mvumi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c index e70d336b4ab39..38a92f8c25f5b 100644 --- a/drivers/scsi/mvumi.c +++ b/drivers/scsi/mvumi.c @@ -1361,7 +1361,8 @@ static void mvumi_show_event(struct mvumi_hba *mhba, if (ptr->param_count) { printk(KERN_WARNING "Event param(len 0x%x): ", ptr->param_count); - for (i = 0; i < ptr->param_count; i++) + for (i = 0; i < ptr->param_count && + i < ARRAY_SIZE(ptr->params); i++) printk(KERN_WARNING "0x%x ", ptr->params[i]); printk(KERN_WARNING "\n"); @@ -1370,7 +1371,8 @@ static void mvumi_show_event(struct mvumi_hba *mhba, if (ptr->sense_data_length) { printk(KERN_WARNING "Event sense data(len 0x%x): ", ptr->sense_data_length); - for (i = 0; i < ptr->sense_data_length; i++) + for (i = 0; i < ptr->sense_data_length && + i < sizeof(ptr->sense_data); i++) printk(KERN_WARNING "0x%x ", ptr->sense_data[i]); printk(KERN_WARNING "\n"); } -- 2.43.0 mvumi_hs_process_page() checksums and parses a handshake page using frame_length from the page header, a u16 the firmware fills in, without checking it against the HSP_MAX_SIZE buffer the page lives in. mvumi_calculate_checksum() then walks frame_length bytes of frame_content with an unsigned char loop counter, so a frame_length of 256 or more never terminates and the probe path hangs; values between the buffer size and 255 read past the page. Reject a frame_length that does not fit the handshake buffer before using it. Read frame_length once into a local and use it for both the bound check and the checksum, so the device cannot change the value in the DMA page between the two. Fixes: f0c568a478f0 ("[SCSI] mvumi: Add Marvell UMI driver") Cc: stable@vger.kernel.org Signed-off-by: Yehyeong Lee --- drivers/scsi/mvumi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c index 38a92f8c25f5b..910505ef4f3ee 100644 --- a/drivers/scsi/mvumi.c +++ b/drivers/scsi/mvumi.c @@ -1039,9 +1039,15 @@ static int mvumi_hs_process_page(struct mvumi_hba *mhba, { struct mvumi_hs_page1 *hs_page1; unsigned char page_checksum; + u16 frame_length = hs_header->frame_length; - page_checksum = mvumi_calculate_checksum(hs_header, - hs_header->frame_length); + if (frame_length > HSP_MAX_SIZE - sizeof(struct mvumi_hs_header)) { + dev_err(&mhba->pdev->dev, "invalid handshake frame length %d\n", + frame_length); + return -1; + } + + page_checksum = mvumi_calculate_checksum(hs_header, frame_length); if (page_checksum != hs_header->checksum) { dev_err(&mhba->pdev->dev, "checksum error\n"); return -1; -- 2.43.0