cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
Blob Blame History Raw
From 6986f7c62b38d90992bd8f7c178325fc1e31d7fe Mon Sep 17 00:00:00 2001
Message-Id: <6986f7c62b38d90992bd8f7c178325fc1e31d7fe.1418766606.git.jen@redhat.com>
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
From: Amos Kong <akong@redhat.com>
Date: Mon, 8 Dec 2014 14:53:34 -0600
Subject: [CHANGE 31/31] migration: fix parameter validation on ram load
 (CVE-2014-7840)
To: rhvirt-patches@redhat.com,
    jen@redhat.com

RH-Author: Amos Kong <akong@redhat.com>
Message-id: <1418050414-25145-1-git-send-email-akong@redhat.com>
Patchwork-id: 62762
O-Subject: [RHEL-7.1 qemu-kvm PATCH] migration: fix parameter validation on ram load (CVE-2014-7840)
Bugzilla: 1163078
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>

From: Michael S. Tsirkin <mst@redhat.com>

During migration, the values read from migration stream during ram load
are not validated. Especially offset in host_from_stream_offset() and
also the length of the writes in the callers of said function.

To fix this, we need to make sure that the [offset, offset + length]
range fits into one of the allocated memory regions.

Validating addr < len should be sufficient since data seems to always be
managed in TARGET_PAGE_SIZE chunks.

Fixes: CVE-2014-7840

Note: follow-up patches add extra checks on each block->host access.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
(backported from commit 0be839a2701369f669532ea5884c15bead1c6e08)
Conflict was caused by different error reporting.

Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
---
 arch_init.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 0c2bde9..4c3d3b5 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -979,7 +979,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
     uint8_t len;
 
     if (flags & RAM_SAVE_FLAG_CONTINUE) {
-        if (!block) {
+        if (!block || block->length <= offset) {
             fprintf(stderr, "Ack, bad migration stream!\n");
             return NULL;
         }
@@ -992,8 +992,9 @@ static inline void *host_from_stream_offset(QEMUFile *f,
     id[len] = 0;
 
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
-        if (!strncmp(id, block->idstr, sizeof(id)))
+        if (!strncmp(id, block->idstr, sizeof(id)) && block->length > offset) {
             return memory_region_get_ram_ptr(block->mr) + offset;
+        }
     }
 
     fprintf(stderr, "Can't find block %s!\n", id);
-- 
2.1.0