Blame 0018-virtio-scsi-fix-buffer-overrun-on-invalid-state-load.patch

70114f
From 579bb2000dbcd8a415660e76d31f521d87ac1302 Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:52:17 +0300
70114f
Subject: [PATCH] virtio-scsi: fix buffer overrun on invalid state load
70114f
MIME-Version: 1.0
70114f
Content-Type: text/plain; charset=UTF-8
70114f
Content-Transfer-Encoding: 8bit
70114f
70114f
CVE-2013-4542
70114f
70114f
hw/scsi/scsi-bus.c invokes load_request.
70114f
70114f
 virtio_scsi_load_request does:
70114f
    qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
70114f
70114f
this probably can make elem invalid, for example,
70114f
make in_num or out_num huge, then:
70114f
70114f
    virtio_scsi_parse_req(s, vs->cmd_vqs[n], req);
70114f
70114f
will do:
70114f
70114f
    if (req->elem.out_num > 1) {
70114f
        qemu_sgl_init_external(req, &req->elem.out_sg[1],
70114f
                               &req->elem.out_addr[1],
70114f
                               req->elem.out_num - 1);
70114f
    } else {
70114f
        qemu_sgl_init_external(req, &req->elem.in_sg[1],
70114f
                               &req->elem.in_addr[1],
70114f
                               req->elem.in_num - 1);
70114f
    }
70114f
70114f
and this will access out of array bounds.
70114f
70114f
Note: this adds security checks within assert calls since
70114f
SCSIBusInfo's load_request cannot fail.
70114f
For now simply disable builds with NDEBUG - there seems
70114f
to be little value in supporting these.
70114f
70114f
Cc: Andreas Färber <afaerber@suse.de>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit 3c3ce981423e0d6c18af82ee62f1850c2cda5976)
70114f
---
70114f
 hw/scsi/virtio-scsi.c | 9 +++++++++
70114f
 1 file changed, 9 insertions(+)
70114f
70114f
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
70114f
index b0d7517..1752193 100644
70114f
--- a/hw/scsi/virtio-scsi.c
70114f
+++ b/hw/scsi/virtio-scsi.c
70114f
@@ -147,6 +147,15 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
70114f
     qemu_get_be32s(f, &n);
70114f
     assert(n < vs->conf.num_queues);
70114f
     qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
70114f
+    /* TODO: add a way for SCSIBusInfo's load_request to fail,
70114f
+     * and fail migration instead of asserting here.
70114f
+     * When we do, we might be able to re-enable NDEBUG below.
70114f
+     */
70114f
+#ifdef NDEBUG
70114f
+#error building with NDEBUG is not supported
70114f
+#endif
70114f
+    assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg));
70114f
+    assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg));
70114f
     virtio_scsi_parse_req(s, vs->cmd_vqs[n], req);
70114f
 
70114f
     scsi_req_ref(sreq);