* [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va
@ 2023-06-29 8:08 Richard Henderson
2023-06-29 21:27 ` Michael Tokarev
2023-06-30 16:06 ` Michael Tokarev
0 siblings, 2 replies; 4+ messages in thread
From: Richard Henderson @ 2023-06-29 8:08 UTC (permalink / raw)
To: qemu-devel; +Cc: mjt, qemu-stable
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>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va
2023-06-29 8:08 [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va Richard Henderson
@ 2023-06-29 21:27 ` Michael Tokarev
2023-06-30 16:06 ` Michael Tokarev
1 sibling, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2023-06-29 21:27 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: qemu-stable
29.06.2023 11:08, Richard Henderson wrote:
> 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>
So, I pushed this to debian (where we've seen multiple failures),
let's see how it goes..
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va
2023-06-29 8:08 [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va Richard Henderson
2023-06-29 21:27 ` Michael Tokarev
@ 2023-06-30 16:06 ` Michael Tokarev
2023-07-01 6:59 ` Richard Henderson
1 sibling, 1 reply; 4+ messages in thread
From: Michael Tokarev @ 2023-06-30 16:06 UTC (permalink / raw)
To: Richard Henderson, qemu-devel; +Cc: qemu-stable
29.06.2023 11:08, Richard Henderson wrote:
> 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.
This hack appears to fix known issues and apparently does not
introduce regressions.
Can it be applied to master and picked up from there, since
master is also broken? You can revert it in the subsequent
patchset like the one you posted today.
You can add my:
Tested-by: Michael Tokarev <mjt@tls.msk.ru>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Thanks!
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va
2023-06-30 16:06 ` Michael Tokarev
@ 2023-07-01 6:59 ` Richard Henderson
0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-07-01 6:59 UTC (permalink / raw)
To: Michael Tokarev, qemu-devel; +Cc: qemu-stable
On 6/30/23 18:06, Michael Tokarev wrote:
> 29.06.2023 11:08, Richard Henderson wrote:
>> 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.
>
> This hack appears to fix known issues and apparently does not
> introduce regressions.
>
> Can it be applied to master and picked up from there, since
> master is also broken? You can revert it in the subsequent
> patchset like the one you posted today.
>
> You can add my:
>
> Tested-by: Michael Tokarev <mjt@tls.msk.ru>
> Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Yes, that's a good idea. Queued to tcg-next.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-01 6:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-29 8:08 [PATCH] linux-user: Avoid mmap of the last byte of the reserved_va Richard Henderson
2023-06-29 21:27 ` Michael Tokarev
2023-06-30 16:06 ` Michael Tokarev
2023-07-01 6:59 ` Richard Henderson
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).