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

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