]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
linux-user: fix mremap unmapping adjacent region
authorMatthew Lugg <mlugg@mlugg.co.uk>
Mon, 17 Nov 2025 17:09:51 +0000 (17:09 +0000)
committerRichard Henderson <richard.henderson@linaro.org>
Sun, 11 Jan 2026 21:49:33 +0000 (08:49 +1100)
This typo meant that calls to `mremap` which shrink a mapping by some N
bytes would, when the virtual address space was pre-reserved (e.g.
32-bit guest on 64-bit host), unmap the N bytes following the *original*
mapping.

Signed-off-by: Matthew Lugg <mlugg@mlugg.co.uk>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20251117170954.31451-2-mlugg@mlugg.co.uk>

linux-user/mmap.c

index 423c77856a3aa8caeccfa2c0bcf26364d6c04d1d..ef3833a2bbc6522919877378c4b3f6dc924cdaf3 100644 (file)
@@ -1171,7 +1171,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
                     errno = ENOMEM;
                     host_addr = MAP_FAILED;
                 } else if (reserved_va && old_size > new_size) {
-                    mmap_reserve_or_unmap(old_addr + old_size,
+                    /* Re-reserve pages we just shrunk out of the mapping */
+                    mmap_reserve_or_unmap(old_addr + new_size,
                                           old_size - new_size);
                 }
             }