qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: "Riku Voipio" <riku.voipio@iki.fi>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Laurent Vivier" <laurent@vivier.eu>,
	umarcor <1783362@bugs.launchpad.net>
Subject: [Qemu-devel] [PULL 1/3] linux-user/mmap.c: handle invalid len maps correctly
Date: Tue, 31 Jul 2018 10:42:01 +0200	[thread overview]
Message-ID: <20180731084203.29959-2-laurent@vivier.eu> (raw)
In-Reply-To: <20180731084203.29959-1-laurent@vivier.eu>

From: Alex Bennée <alex.bennee@linaro.org>

I've slightly re-organised the check to more closely match the
sequence that the kernel uses in do_mmap(). We check for both the zero
case (EINVAL) and the overflow length case (ENOMEM).

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: umarcor <1783362@bugs.launchpad.net>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20180730134321.19898-2-alex.bennee@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/mmap.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index d0c50e4888..41e0983ce8 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -391,14 +391,23 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
     }
 #endif
 
-    if (offset & ~TARGET_PAGE_MASK) {
+    if (!len) {
         errno = EINVAL;
         goto fail;
     }
 
+    /* Also check for overflows... */
     len = TARGET_PAGE_ALIGN(len);
-    if (len == 0)
-        goto the_end;
+    if (!len) {
+        errno = ENOMEM;
+        goto fail;
+    }
+
+    if (offset & ~TARGET_PAGE_MASK) {
+        errno = EINVAL;
+        goto fail;
+    }
+
     real_start = start & qemu_host_page_mask;
     host_offset = offset & qemu_host_page_mask;
 
-- 
2.17.1

  reply	other threads:[~2018-07-31  8:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31  8:42 [Qemu-devel] [PULL 0/3] Linux user for 3.0 patches Laurent Vivier
2018-07-31  8:42 ` Laurent Vivier [this message]
2018-07-31  8:42 ` [Qemu-devel] [PULL 2/3] tests: add check_invalid_maps to test-mmap Laurent Vivier
2018-07-31  8:42 ` [Qemu-devel] [PULL 3/3] linux-user: ppc64: don't use volatile register during safe_syscall Laurent Vivier
2018-07-31 12:24 ` [Qemu-devel] [PULL 0/3] Linux user for 3.0 patches no-reply
2018-07-31 12:40   ` Laurent Vivier
2018-07-31 12:44     ` Laurent Vivier
2018-07-31 13:27     ` Alex Bennée
2018-07-31 14:01 ` Peter Maydell

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=20180731084203.29959-2-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=1783362@bugs.launchpad.net \
    --cc=alex.bennee@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).