qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Peter Crosthwaite <crosthwaite.peter@gmail.com>,
	Richard Henderson <rth@twiddle.net>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	david@redhat.com
Subject: [Qemu-devel] [PATCH v1 2/2] exec: check that alignment is a power of two
Date: Thu,  7 Jun 2018 17:47:05 +0200	[thread overview]
Message-ID: <20180607154705.6316-3-david@redhat.com> (raw)
In-Reply-To: <20180607154705.6316-1-david@redhat.com>

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 <david@redhat.com>
---
 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__)
-- 
2.17.0

  parent reply	other threads:[~2018-06-07 15:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07 15:47 [Qemu-devel] [PATCH v1 0/2] memory: fix alignment checks/asserts David Hildenbrand
2018-06-07 15:47 ` [Qemu-devel] [PATCH v1 1/2] memory-device: turn alignment assert into check David Hildenbrand
2018-06-08  8:28   ` Igor Mammedov
2018-06-07 15:47 ` David Hildenbrand [this message]
2018-06-08  8:30   ` [Qemu-devel] [PATCH v1 2/2] exec: check that alignment is a power of two Igor Mammedov
2018-06-07 22:01 ` [Qemu-devel] [PATCH v1 0/2] memory: fix alignment checks/asserts Michael S. Tsirkin
2018-06-11 13:30 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180607154705.6316-3-david@redhat.com \
    --to=david@redhat.com \
    --cc=crosthwaite.peter@gmail.com \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).