thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-hw-scsi-scsi-disk-MODE_PAGE_ALLS-not-allowed-in-MODE.patch

893208
From 60b05771b8afc08e0ca9956658d2c55cd1739652 Mon Sep 17 00:00:00 2001
893208
From: Mauro Matteo Cascella <mcascell@redhat.com>
893208
Date: Thu, 4 Nov 2021 17:31:38 +0100
893208
Subject: [PATCH 1/2] hw/scsi/scsi-disk: MODE_PAGE_ALLS not allowed in MODE
893208
 SELECT commands
893208
MIME-Version: 1.0
893208
Content-Type: text/plain; charset=UTF-8
893208
Content-Transfer-Encoding: 8bit
893208
893208
RH-Author: Jon Maloy <jmaloy@redhat.com>
893208
RH-MergeRequest: 70: hw/scsi/scsi-disk: MODE_PAGE_ALLS not allowed in MODE SELECT commands
893208
RH-Commit: [1/1] bd3de8bdf48aa6c522612505d08c23dafb122a34 (jmaloy/qemu-kvm)
893208
RH-Bugzilla: 2025605
893208
RH-Acked-by: Paolo Bonzini <None>
893208
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
893208
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
893208
893208
This avoids an off-by-one read of 'mode_sense_valid' buffer in
893208
hw/scsi/scsi-disk.c:mode_sense_page().
893208
893208
Fixes: CVE-2021-3930
893208
Cc: qemu-stable@nongnu.org
893208
Reported-by: Alexander Bulekov <alxndr@bu.edu>
893208
Fixes: a8f4bbe2900 ("scsi-disk: store valid mode pages in a table")
893208
Fixes: #546
893208
Reported-by: Qiuhao Li <Qiuhao.Li@outlook.com>
893208
Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
893208
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
893208
(cherry picked from commit b3af7fdf9cc537f8f0dd3e2423d83f5c99a457e8)
893208
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
893208
---
893208
 hw/scsi/scsi-disk.c | 6 ++++++
893208
 1 file changed, 6 insertions(+)
893208
893208
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
893208
index 5cb5fd35bd..1d0ea72289 100644
893208
--- a/hw/scsi/scsi-disk.c
893208
+++ b/hw/scsi/scsi-disk.c
893208
@@ -1086,6 +1086,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
893208
     uint8_t *p = *p_outbuf + 2;
893208
     int length;
893208
 
893208
+    assert(page < ARRAY_SIZE(mode_sense_valid));
893208
     if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
893208
         return -1;
893208
     }
893208
@@ -1427,6 +1428,11 @@ static int scsi_disk_check_mode_select(SCSIDiskState *s, int page,
893208
         return -1;
893208
     }
893208
 
893208
+    /* MODE_PAGE_ALLS is only valid for MODE SENSE commands */
893208
+    if (page == MODE_PAGE_ALLS) {
893208
+        return -1;
893208
+    }
893208
+
893208
     p = mode_current;
893208
     memset(mode_current, 0, inlen + 2);
893208
     len = mode_sense_page(s, page, &p, 0);
893208
-- 
893208
2.27.0
893208