From patchwork Tue Nov 18 11:29:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 411988 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9CA79140179 for ; Tue, 18 Nov 2014 22:30:33 +1100 (AEDT) Received: from localhost ([::1]:52517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqgzP-0005Sb-KB for incoming@patchwork.ozlabs.org; Tue, 18 Nov 2014 06:30:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xqgyu-0004du-Hu for qemu-devel@nongnu.org; Tue, 18 Nov 2014 06:30:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xqgyo-0005Hf-EK for qemu-devel@nongnu.org; Tue, 18 Nov 2014 06:30:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xqgyo-0005HX-6P for qemu-devel@nongnu.org; Tue, 18 Nov 2014 06:29:54 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAIBTqhx015271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 18 Nov 2014 06:29:52 -0500 Received: from localhost (dhcp193-24.pnq.redhat.com [10.65.193.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAIBToJJ001767; Tue, 18 Nov 2014 06:29:51 -0500 From: Amit Shah To: qemu list Date: Tue, 18 Nov 2014 16:59:44 +0530 Message-Id: <0be839a2701369f669532ea5884c15bead1c6e08.1416310073.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Amit Shah , Peter Maydell , Juan Quintela , "Dr. David Alan Gilbert" , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH 1/1] migration: fix parameter validation on ram load X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Michael S. Tsirkin" 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 --- arch_init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch_init.c b/arch_init.c index 88a5ba0..593a990 100644 --- a/arch_init.c +++ b/arch_init.c @@ -1006,7 +1006,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) { error_report("Ack, bad migration stream!"); return NULL; } @@ -1019,8 +1019,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; + } } error_report("Can't find block %s!", id);