Blame SOURCES/kvm-migration-fix-parameter-validation-on-ram-load-CVE-2.patch

9ae3a8
From 6986f7c62b38d90992bd8f7c178325fc1e31d7fe Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <6986f7c62b38d90992bd8f7c178325fc1e31d7fe.1418766606.git.jen@redhat.com>
9ae3a8
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
9ae3a8
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
9ae3a8
From: Amos Kong <akong@redhat.com>
9ae3a8
Date: Mon, 8 Dec 2014 14:53:34 -0600
9ae3a8
Subject: [CHANGE 31/31] migration: fix parameter validation on ram load
9ae3a8
 (CVE-2014-7840)
9ae3a8
To: rhvirt-patches@redhat.com,
9ae3a8
    jen@redhat.com
9ae3a8
9ae3a8
RH-Author: Amos Kong <akong@redhat.com>
9ae3a8
Message-id: <1418050414-25145-1-git-send-email-akong@redhat.com>
9ae3a8
Patchwork-id: 62762
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH] migration: fix parameter validation on ram load (CVE-2014-7840)
9ae3a8
Bugzilla: 1163078
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
9ae3a8
From: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
9ae3a8
During migration, the values read from migration stream during ram load
9ae3a8
are not validated. Especially offset in host_from_stream_offset() and
9ae3a8
also the length of the writes in the callers of said function.
9ae3a8
9ae3a8
To fix this, we need to make sure that the [offset, offset + length]
9ae3a8
range fits into one of the allocated memory regions.
9ae3a8
9ae3a8
Validating addr < len should be sufficient since data seems to always be
9ae3a8
managed in TARGET_PAGE_SIZE chunks.
9ae3a8
9ae3a8
Fixes: CVE-2014-7840
9ae3a8
9ae3a8
Note: follow-up patches add extra checks on each block->host access.
9ae3a8
9ae3a8
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
Signed-off-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
(backported from commit 0be839a2701369f669532ea5884c15bead1c6e08)
9ae3a8
Conflict was caused by different error reporting.
9ae3a8
9ae3a8
Signed-off-by: Amos Kong <akong@redhat.com>
9ae3a8
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
9ae3a8
---
9ae3a8
 arch_init.c | 5 +++--
9ae3a8
 1 file changed, 3 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/arch_init.c b/arch_init.c
9ae3a8
index 0c2bde9..4c3d3b5 100644
9ae3a8
--- a/arch_init.c
9ae3a8
+++ b/arch_init.c
9ae3a8
@@ -979,7 +979,7 @@ static inline void *host_from_stream_offset(QEMUFile *f,
9ae3a8
     uint8_t len;
9ae3a8
 
9ae3a8
     if (flags & RAM_SAVE_FLAG_CONTINUE) {
9ae3a8
-        if (!block) {
9ae3a8
+        if (!block || block->length <= offset) {
9ae3a8
             fprintf(stderr, "Ack, bad migration stream!\n");
9ae3a8
             return NULL;
9ae3a8
         }
9ae3a8
@@ -992,8 +992,9 @@ static inline void *host_from_stream_offset(QEMUFile *f,
9ae3a8
     id[len] = 0;
9ae3a8
 
9ae3a8
     QTAILQ_FOREACH(block, &ram_list.blocks, next) {
9ae3a8
-        if (!strncmp(id, block->idstr, sizeof(id)))
9ae3a8
+        if (!strncmp(id, block->idstr, sizeof(id)) && block->length > offset) {
9ae3a8
             return memory_region_get_ram_ptr(block->mr) + offset;
9ae3a8
+        }
9ae3a8
     }
9ae3a8
 
9ae3a8
     fprintf(stderr, "Can't find block %s!\n", id);
9ae3a8
-- 
9ae3a8
2.1.0
9ae3a8