From ae71ee68dee975fbb94cec450ca14a1caf421fc8 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <6542ba6203e55ba5fa5a30171f9fa0690468aa33.1419012926.git.jen@redhat.com> References: <6542ba6203e55ba5fa5a30171f9fa0690468aa33.1419012926.git.jen@redhat.com> From: Amos Kong Date: Mon, 8 Dec 2014 15:17:10 -0600 Subject: [CHANGE 6/6] migration: fix parameter validation on ram load (CVE-2014-7840) To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Amos Kong Message-id: <1418051830-16703-1-git-send-email-akong@redhat.com> Patchwork-id: 62763 O-Subject: [RHEL-6.7 qemu-kvm PATCH] migration: fix parameter validation on ram load (CVE-2014-7840) Bugzilla: 1163077 RH-Acked-by: Juan Quintela RH-Acked-by: Michael S. Tsirkin RH-Acked-by: Dr. David Alan Gilbert (git) From: Michael S. Tsirkin Bugzilla: 1163077 Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=8344082 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 Reviewed-by: Paolo Bonzini Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Amit Shah (backported from commit 0be839a2701369f669532ea5884c15bead1c6e08) Conflict was caused by that host_from_stream_offset() isn't separated from vl.c Signed-off-by: Amos Kong --- vl.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) Signed-off-by: Jeff E. Nelson --- vl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vl.c b/vl.c index 803cd0c..01a480a 100644 --- a/vl.c +++ b/vl.c @@ -2974,7 +2974,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; } @@ -2987,8 +2987,9 @@ static inline void *host_from_stream_offset(QEMUFile *f, id[len] = 0; QLIST_FOREACH(block, &ram_list.blocks, next) { - if (!strncmp(id, block->idstr, sizeof(id))) + if (!strncmp(id, block->idstr, sizeof(id)) && block->length > offset) { return block->host + offset; + } } fprintf(stderr, "Can't find block %s!\n", id); -- 2.1.0