From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org, Michael Tokarev <mjt@tls.msk.ru>
Subject: [PULL 11/11] linux-user: Avoid mmap of the last byte of the reserved_va
Date: Sat, 1 Jul 2023 08:55:10 +0200 [thread overview]
Message-ID: <20230701065510.514743-12-richard.henderson@linaro.org> (raw)
In-Reply-To: <20230701065510.514743-1-richard.henderson@linaro.org>
There is an overflow problem in mmap_find_vma_reserved:
when reserved_va == UINT32_MAX, end may overflow to 0.
Rather than a larger rewrite at this time, simply avoid
the final byte of the VA, which avoids searching the
final page, which avoids the overflow.
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1741
Fixes: 95059f9c ("include/exec: Change reserved_va semantics to last byte")
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Message-Id: <20230629080835.71371-1-richard.henderson@linaro.org>
---
linux-user/mmap.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 0aa8ae7356..2692936773 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -281,9 +281,15 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size,
/* Note that start and size have already been aligned by mmap_find_vma. */
end_addr = start + size;
+ /*
+ * Start at the top of the address space, ignoring the last page.
+ * If reserved_va == UINT32_MAX, then end_addr wraps to 0,
+ * throwing the rest of the calculations off.
+ * TODO: rewrite using last_addr instead.
+ * TODO: use the interval tree instead of probing every page.
+ */
if (start > reserved_va - size) {
- /* Start at the top of the address space. */
- end_addr = ((reserved_va + 1 - size) & -align) + size;
+ end_addr = ((reserved_va - size) & -align) + size;
looped = true;
}
@@ -296,8 +302,8 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size,
/* Failure. The entire address space has been searched. */
return (abi_ulong)-1;
}
- /* Re-start at the top of the address space. */
- addr = end_addr = ((reserved_va + 1 - size) & -align) + size;
+ /* Re-start at the top of the address space (see above). */
+ addr = end_addr = ((reserved_va - size) & -align) + size;
looped = true;
} else {
prot = page_get_flags(addr);
--
2.34.1
next prev parent reply other threads:[~2023-07-01 6:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-01 6:54 [PULL 00/11] tcg and misc patch queue Richard Henderson
2023-07-01 6:55 ` [PULL 01/11] ui/dbus: fix build errors in dbus_update_gl_cb and dbus_call_update_gl Richard Henderson
2023-07-01 6:55 ` [PULL 02/11] audio: dbus requires pixman Richard Henderson
2023-07-01 6:55 ` [PULL 03/11] accel/tcg: Fix start page passed to tb_invalidate_phys_page_range__locked Richard Henderson
2023-07-01 6:55 ` [PULL 04/11] accel/tcg: Assert one page in tb_invalidate_phys_page_range__locked Richard Henderson
2023-07-01 6:55 ` [PULL 05/11] fpu: Add float64_to_int{32,64}_modulo Richard Henderson
2023-07-01 6:55 ` [PULL 06/11] tests/tcg/alpha: Add test for cvttq Richard Henderson
2023-07-01 6:55 ` [PULL 07/11] target/alpha: Use float64_to_int64_modulo for CVTTQ Richard Henderson
2023-07-01 6:55 ` [PULL 08/11] target/arm: Use float64_to_int32_modulo for FJCVTZS Richard Henderson
2023-07-01 6:55 ` [PULL 09/11] tcg: Reduce tcg_assert_listed_vecop() scope Richard Henderson
2023-07-01 6:55 ` [PULL 10/11] target/nios2 : Explicitly ask for target-endian loads and stores Richard Henderson
2023-07-01 6:55 ` Richard Henderson [this message]
2023-07-01 8:10 ` [PULL 00/11] tcg and misc patch queue Philippe Mathieu-Daudé
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=20230701065510.514743-12-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=mjt@tls.msk.ru \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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).