[PATCH v5 14/31] linux-user: Use guest_range_valid in access_ok

Richard Henderson posted 31 patches 5 years ago
There is a newer version of this series
[PATCH v5 14/31] linux-user: Use guest_range_valid in access_ok
Posted by Richard Henderson 5 years ago
We're currently open-coding the range check in access_ok;
use guest_range_valid when size != 0.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/qemu.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 9fbc5edc4b..ba122a7903 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -493,12 +493,9 @@ extern unsigned long guest_stack_size;
 
 static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
 {
-    if (!guest_addr_valid(addr)) {
-        return false;
-    }
-    if (size != 0 &&
-        (addr + size - 1 < addr ||
-         !guest_addr_valid(addr + size - 1))) {
+    if (size == 0
+        ? !guest_addr_valid(addr)
+        : !guest_range_valid(addr, size)) {
         return false;
     }
     return page_check_range((target_ulong)addr, size, type) == 0;
-- 
2.25.1


Re: [PATCH v5 14/31] linux-user: Use guest_range_valid in access_ok
Posted by Peter Maydell 5 years ago
On Wed, 3 Feb 2021 at 19:00, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> We're currently open-coding the range check in access_ok;
> use guest_range_valid when size != 0.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/qemu.h | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 9fbc5edc4b..ba122a7903 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -493,12 +493,9 @@ extern unsigned long guest_stack_size;
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM