From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRCmo-0004GJ-KY for qemu-devel@nongnu.org; Fri, 08 Jun 2018 04:30:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRCmj-0003dP-3f for qemu-devel@nongnu.org; Fri, 08 Jun 2018 04:30:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56284 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRCmi-0003ch-Vm for qemu-devel@nongnu.org; Fri, 08 Jun 2018 04:30:13 -0400 Date: Fri, 8 Jun 2018 10:30:09 +0200 From: Igor Mammedov Message-ID: <20180608103009.2b43dbd9@redhat.com> In-Reply-To: <20180607154705.6316-3-david@redhat.com> References: <20180607154705.6316-1-david@redhat.com> <20180607154705.6316-3-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1 2/2] exec: check that alignment is a power of two List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Hildenbrand Cc: qemu-devel@nongnu.org, Paolo Bonzini , Peter Crosthwaite , Richard Henderson , "Michael S . Tsirkin" On Thu, 7 Jun 2018 17:47:05 +0200 David Hildenbrand wrote: > Right now we can crash QEMU using e.g. > > qemu-system-x86_64 -m 256M,maxmem=20G,slots=2 \ > -object memory-backend-file,id=mem0,size=12288,mem-path=/dev/zero,align=12288 \ > -device pc-dimm,id=dimm1,memdev=mem0 > > qemu-system-x86_64: util/mmap-alloc.c:115: > qemu_ram_mmap: Assertion `is_power_of_2(align)' failed > > Fix this by adding a proper check. > > Signed-off-by: David Hildenbrand Reviewed-by: Igor Mammedov > --- > exec.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/exec.c b/exec.c > index f6645ede0c..f54c83ac61 100644 > --- a/exec.c > +++ b/exec.c > @@ -1681,6 +1681,10 @@ static void *file_ram_alloc(RAMBlock *block, > " must be multiples of page size 0x%zx", > block->mr->align, block->page_size); > return NULL; > + } else if (block->mr->align && !is_power_of_2(block->mr->align)) { > + error_setg(errp, "alignment 0x%" PRIx64 > + " must be a power of two", block->mr->align); > + return NULL; > } > block->mr->align = MAX(block->page_size, block->mr->align); > #if defined(__s390x__)