From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45828 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7aMa-0003cX-4s for qemu-devel@nongnu.org; Sun, 17 Oct 2010 17:01:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7aMZ-0001fc-78 for qemu-devel@nongnu.org; Sun, 17 Oct 2010 17:01:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7aMZ-0001eW-0z for qemu-devel@nongnu.org; Sun, 17 Oct 2010 17:01:51 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9HL1kEV022786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 17 Oct 2010 17:01:46 -0400 From: Alex Williamson In-Reply-To: <20101017184340.GA12524@redhat.com> References: <20101017184340.GA12524@redhat.com> Content-Type: text/plain; charset="UTF-8" Date: Sun, 17 Oct 2010 15:01:45 -0600 Message-ID: <1287349305.21691.17.camel@x201> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] migration: don't segfault on invalid input List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org On Sun, 2010-10-17 at 20:43 +0200, Michael S. Tsirkin wrote: > host_from_stream_offset returns NULL on error, > return error instead of trying to use that address, > to avoid segfault on invalid stream. > > Signed-off-by: Michael S. Tsirkin > --- > arch_init.c | 5 +++++ > 1 files changed, 5 insertions(+), 0 deletions(-) > > diff --git a/arch_init.c b/arch_init.c > index e468c0c..bc7528d 100644 > --- a/arch_init.c > +++ b/arch_init.c > @@ -116,6 +116,8 @@ static int ram_save_block(QEMUFile *f) > > if (!block) > block = QLIST_FIRST(&ram_list.blocks); > + if (!last_block) > + last_block = block; > > current_addr = block->offset + offset; NAK, last_block == block will cause us to set the continue flag on the first block. I assume you're trying to prevent the last_block->offset segv in the while test, but that should never happen. The only time last_block is NULL is at the beginning of stage 1, where all pages are dirty. At that point we should always enter the if {} block at the beginning of the do {} while, which breaks out rather than hitting the segv. We'll then set last_block for the next pass. > @@ -390,6 +392,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) > host = qemu_get_ram_ptr(addr); > else > host = host_from_stream_offset(f, addr, flags); > + if (!host) { > + return -EINVAL; > + } > This should also never happen since we've synchronized ramblocks at the beginning of migration, but probably a good idea to return an error. Thanks, Alex