Skip to contentSkip to conversation

linux-user: check valid address in access_ok()

PATCH In review Rémi Denis-Courmont 3 participants 4 messages Feb 8, 2019 – Feb 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: check valid address in access_ok()

This works around the LTP crash, but there are problably better ways to go about it.

---
 linux-user/qemu.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/qemu.h +2 -1
index ef400cb78a..1d222a0cce 100644
@@ -457,7 +457,8 @@ extern unsigned long guest_stack_size;
 
 static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 {
-    return page_check_range((target_ulong)addr, size,
+    return guest_addr_valid(addr) && guest_addr_valid(addr + size) &&
+           page_check_range((target_ulong)addr, size,
                             (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0;
 }
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 14 lines · Rémi Denis-Courmont

This works around the LTP crash, but there are problably better ways to go about it.

---
 linux-user/qemu.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/qemu.h +0 -0
index ef400cb78a..1d222a0cce 100644

linux-user/qemu.h extern unsigned long guest_stack_size; · line 460

Quoted 5 lines
linux-user/qemu.h +1 -1
@@ -457,7 +457,8 @@ extern unsigned long guest_stack_size;
 
 static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 {
-    return page_check_range((target_ulong)addr, size,
+    return guest_addr_valid(addr) && guest_addr_valid(addr + size) &&

I think it should be guest_addr_valid(addr + size - 1).

Except that, it looks good.

Thanks,
Laurent

#2 lore raw
Quoted 16 lines · Laurent Vivier
Quoted 15 lines · Rémi Denis-Courmont

This works around the LTP crash, but there are problably better ways to go about it.

---
 linux-user/qemu.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/qemu.h +0 -0
index ef400cb78a..1d222a0cce 100644
@@ -457,7 +457,8 @@ extern unsigned long guest_stack_size;
 
Quoted 6 lines

linux-user/qemu.h extern unsigned long guest_stack_size; · line 460

Quoted 4 lines
linux-user/qemu.h +1 -1
 static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 {
-    return page_check_range((target_ulong)addr, size,
+    return guest_addr_valid(addr) && guest_addr_valid(addr + size) &&

I think it should be guest_addr_valid(addr + size - 1).

In fact (len == 0 || guest_addr_valid(addr + size - 1)).

Could you send a new version of your patch?

I've received several mail delivery system errors regarding your email address [email protected].

Thanks,
Laurent

#3 lore raw

Hi,

I don't think that len == 0 is a sufficient condition to eliminate integer overflow. It only ensures that size - 1 is a positive quantity.

________________________________________
De : Laurent Vivier [[email protected]]
Envoyé : jeudi 14 février 2019 11:22
À : Rémi Denis-Courmont; [email protected]
Cc : Remi Denis Courmont
Objet : Re: [Qemu-devel] [PATCH] linux-user: check valid address in access_ok()

Quoted 16 lines · Laurent Vivier
Quoted 15 lines · Rémi Denis-Courmont

This works around the LTP crash, but there are problably better ways to go about it.

---
 linux-user/qemu.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/qemu.h +0 -0
index ef400cb78a..1d222a0cce 100644
@@ -457,7 +457,8 @@ extern unsigned long guest_stack_size;
 
Quoted 6 lines

linux-user/qemu.h extern unsigned long guest_stack_size; · line 460

Quoted 4 lines
linux-user/qemu.h +1 -1
 static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
 {
-    return page_check_range((target_ulong)addr, size,
+    return guest_addr_valid(addr) && guest_addr_valid(addr + size) &&

I think it should be guest_addr_valid(addr + size - 1).

In fact (len == 0 || guest_addr_valid(addr + size - 1)).

Could you send a new version of your patch?

I've received several mail delivery system errors regarding your email address [email protected].

Thanks,
Laurent