qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user/mmap.c: fix integer underflow in target_mremap
@ 2020-05-02 16:12 Jonathan Marler
  2020-05-02 23:43 ` Jonathan Marler
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jonathan Marler @ 2020-05-02 16:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jonathan Marler

Fixes: https://bugs.launchpad.net/bugs/1876373

This code path in mmap occurs when a page size is decreased with mremap.  When a section of pages is shrunk, qemu calls mmap_reserve on the pages that were released.  However, it has the diff operation reversed, subtracting the larger old_size from the smaller new_size.  Instead, it should be subtracting the smaller new_size from the larger old_size.  You can also see in the previous line of the change that this mmap_reserve call only occurs when old_size > new_size.

Signed-off-by: Jonathan Marler <johnnymarler@gmail.com>
---
 linux-user/mmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index e378033797..caab62909e 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -708,7 +708,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
         if (prot == 0) {
             host_addr = mremap(g2h(old_addr), old_size, new_size, flags);
             if (host_addr != MAP_FAILED && reserved_va && old_size > new_size) {
-                mmap_reserve(old_addr + old_size, new_size - old_size);
+                mmap_reserve(old_addr + old_size, old_size - new_size);
             }
         } else {
             errno = ENOMEM;
-- 
2.23.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread
[parent not found: <20200502074901.30784-1-johnnymarler@gmail.com>]

end of thread, other threads:[~2020-05-28  9:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-02 16:12 [PATCH] linux-user/mmap.c: fix integer underflow in target_mremap Jonathan Marler
2020-05-02 23:43 ` Jonathan Marler
2020-05-15 13:36   ` Jonathan Marler
2020-05-18 18:13     ` Jonathan Marler
2020-05-19  8:11       ` Stefano Garzarella
2020-05-19 12:17         ` Philippe Mathieu-Daudé
2020-05-28  9:34 ` Laurent Vivier
2020-05-28  9:35 ` Laurent Vivier
     [not found] <20200502074901.30784-1-johnnymarler@gmail.com>
2020-05-02  8:38 ` Laurent Vivier
2020-05-02 16:13   ` Jonathan Marler

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).