cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtio-scsi-fix-buffer-overrun-on-invalid-state-load.patch

eb5a2f
From 1900368b14d425fdfe1b084892d7e2b86ba64903 Mon Sep 17 00:00:00 2001
eb5a2f
From: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Date: Wed, 14 May 2014 08:07:55 +0200
eb5a2f
Subject: [PATCH 06/30] virtio-scsi: fix buffer overrun on invalid state load
eb5a2f
MIME-Version: 1.0
eb5a2f
Content-Type: text/plain; charset=UTF-8
eb5a2f
Content-Transfer-Encoding: 8bit
eb5a2f
eb5a2f
RH-Author: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Message-id: <1400054498-4366-11-git-send-email-mst@redhat.com>
eb5a2f
Patchwork-id: 58844
eb5a2f
O-Subject: [PATCH qemu-kvm RHEL7.0] virtio-scsi: fix buffer overrun on invalid state load
eb5a2f
Bugzilla: 1095741
eb5a2f
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
eb5a2f
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
eb5a2f
RH-Acked-by: Amos Kong <akong@redhat.com>
eb5a2f
eb5a2f
CVE-2013-4542
eb5a2f
eb5a2f
hw/scsi/scsi-bus.c invokes load_request.
eb5a2f
eb5a2f
 virtio_scsi_load_request does:
eb5a2f
    qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
eb5a2f
eb5a2f
this probably can make elem invalid, for example,
eb5a2f
make in_num or out_num huge, then:
eb5a2f
eb5a2f
    virtio_scsi_parse_req(s, vs->cmd_vqs[n], req);
eb5a2f
eb5a2f
will do:
eb5a2f
eb5a2f
    if (req->elem.out_num > 1) {
eb5a2f
        qemu_sgl_init_external(req, &req->elem.out_sg[1],
eb5a2f
                               &req->elem.out_addr[1],
eb5a2f
                               req->elem.out_num - 1);
eb5a2f
    } else {
eb5a2f
        qemu_sgl_init_external(req, &req->elem.in_sg[1],
eb5a2f
                               &req->elem.in_addr[1],
eb5a2f
                               req->elem.in_num - 1);
eb5a2f
    }
eb5a2f
eb5a2f
and this will access out of array bounds.
eb5a2f
eb5a2f
Note: this adds security checks within assert calls since
eb5a2f
SCSIBusInfo's load_request cannot fail.
eb5a2f
For now simply disable builds with NDEBUG - there seems
eb5a2f
to be little value in supporting these.
eb5a2f
eb5a2f
Cc: Andreas Färber <afaerber@suse.de>
eb5a2f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
eb5a2f
Signed-off-by: Juan Quintela <quintela@redhat.com>
eb5a2f
(cherry picked from commit 3c3ce981423e0d6c18af82ee62f1850c2cda5976)
eb5a2f
eb5a2f
Tested: lightly on developer's box
eb5a2f
Brew build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=7450401
eb5a2f
Bugzilla:1095741
eb5a2f
---
eb5a2f
 hw/scsi/virtio-scsi.c | 9 +++++++++
eb5a2f
 1 file changed, 9 insertions(+)
eb5a2f
eb5a2f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
eb5a2f
---
eb5a2f
 hw/scsi/virtio-scsi.c |    9 +++++++++
eb5a2f
 1 files changed, 9 insertions(+), 0 deletions(-)
eb5a2f
eb5a2f
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
eb5a2f
index 57541b4..7cf3e4b 100644
eb5a2f
--- a/hw/scsi/virtio-scsi.c
eb5a2f
+++ b/hw/scsi/virtio-scsi.c
eb5a2f
@@ -145,6 +145,15 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
eb5a2f
     qemu_get_be32s(f, &n);
eb5a2f
     assert(n < vs->conf.num_queues);
eb5a2f
     qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
eb5a2f
+    /* TODO: add a way for SCSIBusInfo's load_request to fail,
eb5a2f
+     * and fail migration instead of asserting here.
eb5a2f
+     * When we do, we might be able to re-enable NDEBUG below.
eb5a2f
+     */
eb5a2f
+#ifdef NDEBUG
eb5a2f
+#error building with NDEBUG is not supported
eb5a2f
+#endif
eb5a2f
+    assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg));
eb5a2f
+    assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg));
eb5a2f
     virtio_scsi_parse_req(s, vs->cmd_vqs[n], req);
eb5a2f
 
eb5a2f
     scsi_req_ref(sreq);
eb5a2f
-- 
eb5a2f
1.7.1
eb5a2f