qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrzej Zaborowski <balrogg@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [4255] Teach mmap to not overwrite reserved pages and fix brk return value (Richard Purdie).
Date: Sat, 26 Apr 2008 12:17:36 +0000	[thread overview]
Message-ID: <E1JpjLU-0007IX-OB@cvs.savannah.gnu.org> (raw)

Revision: 4255
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4255
Author:   balrog
Date:     2008-04-26 12:17:34 +0000 (Sat, 26 Apr 2008)

Log Message:
-----------
Teach mmap to not overwrite reserved pages and fix brk return value (Richard Purdie).

Modified Paths:
--------------
    trunk/linux-user/mmap.c
    trunk/linux-user/syscall.c

Modified: trunk/linux-user/mmap.c
===================================================================
--- trunk/linux-user/mmap.c	2008-04-26 12:00:18 UTC (rev 4254)
+++ trunk/linux-user/mmap.c	2008-04-26 12:17:34 UTC (rev 4255)
@@ -259,13 +259,24 @@
             host_start += offset - host_offset;
         start = h2g(host_start);
     } else {
+        int flg;
+        target_ulong addr;
+
         if (start & ~TARGET_PAGE_MASK) {
             errno = EINVAL;
             return -1;
         }
         end = start + len;
         real_end = HOST_PAGE_ALIGN(end);
-        
+
+        for(addr = real_start; addr < real_end; addr += TARGET_PAGE_SIZE) {
+            flg = page_get_flags(addr);
+            if (flg & PAGE_RESERVED) {
+                errno = ENXIO;
+                return -1;
+            }
+        }
+
         /* worst case: we cannot map the file because the offset is not
            aligned, so we read it */
         if (!(flags & MAP_ANONYMOUS) &&

Modified: trunk/linux-user/syscall.c
===================================================================
--- trunk/linux-user/syscall.c	2008-04-26 12:00:18 UTC (rev 4254)
+++ trunk/linux-user/syscall.c	2008-04-26 12:17:34 UTC (rev 4255)
@@ -420,7 +420,7 @@
     if (!new_brk)
         return target_brk;
     if (new_brk < target_original_brk)
-        return -TARGET_ENOMEM;
+        return target_brk;
 
     brk_page = HOST_PAGE_ALIGN(target_brk);
 
@@ -435,12 +435,11 @@
     mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size,
                                         PROT_READ|PROT_WRITE,
                                         MAP_ANON|MAP_FIXED|MAP_PRIVATE, 0, 0));
-    if (is_error(mapped_addr)) {
-	return mapped_addr;
-    } else {
+
+    if (!is_error(mapped_addr))
 	target_brk = new_brk;
-    	return target_brk;
-    }
+    
+    return target_brk;
 }
 
 static inline abi_long copy_from_user_fdset(fd_set *fds,

                 reply	other threads:[~2008-04-26 12:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=E1JpjLU-0007IX-OB@cvs.savannah.gnu.org \
    --to=balrogg@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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).