user-exec.c: Don't assert on segfaults for non-valid addresses
PATCH 1/1 user-exec.c: Don't assert on segfaults for non-valid addresses
h2g() will assert if passed an address that's not a valid guest address, so handle_cpu_signal() needs to check before passing "data address which caused a segfault" to it, since for a misbehaving guest that could be anything. If the address isn't a valid guest address then we can simply skip the attempt to unprotect a guest page which was made read-only to catch self-modifying code.
This assertion probably fires more readily now than it used to do because of recent changes to default to reserving guest address space.
---
I've tentatively marked this as for-1.1 as it's pretty safe, although it doesn't buy you a great deal: misbehaving guest binaries will die cleanly with a segfault rather than qemu asserting and then locking up (assert() in qemu's linux-user code doesn't really behave very nicely...)
user-exec.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
user-exec.c +2 -1
@@ -97,7 +97,8 @@ static inline int handle_cpu_signal(uintptr_t pc, unsigned long address, pc, address, is_write, *(unsigned long *)old_set);#endif /* XXX: locking issue */ -if (is_write &&page_unprotect (h2g (address), pc, puc)) { +if (is_write &&h2g_valid (address) + &&page_unprotect (h2g (address), pc, puc)) {return 1 ; }
Signature · 1 line
1.7.1
Quoted 7 lines · Peter Maydell
h2g()will assert if passed an address that's not a valid guest address, sohandle_cpu_signal()needs to check before passing "data address which caused a segfault" to it, since for a misbehaving guest that could be anything. If the address isn't a valid guest address then we can simply skip the attempt to unprotect a guest page which was made read-only to catch self-modifying code.
Quoted 5 lines
This assertion probably fires more readily now than it used to do because of recent changes to default to reserving guest address space.
Signed-off-by Peter Maydell <[email protected]>
Yup, just wrote the same thing a few hours ago.
Quoted 6 lines
---
I've tentatively marked this as for-1.1 as it's pretty safe, although it doesn't buy you a great deal: misbehaving guest binaries will die cleanly with a segfault rather than qemu asserting and then locking up (assert()in qemu's linux-user code doesn't really behave very nicely...)
It's definitely 1.1 material.
Alex
Anthony Liguori
AppliedQuoted 7 lines · Peter Maydell
h2g()will assert if passed an address that's not a valid guest address, sohandle_cpu_signal()needs to check before passing "data address which caused a segfault" to it, since for a misbehaving guest that could be anything. If the address isn't a valid guest address then we can simply skip the attempt to unprotect a guest page which was made read-only to catch self-modifying code.
Quoted 5 lines
This assertion probably fires more readily now than it used to do because of recent changes to default to reserving guest address space.
Signed-off-by Peter Maydell<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 24 lines
---
I've tentatively marked this as for-1.1 as it's pretty safe, although it doesn't buy you a great deal: misbehaving guest binaries will die cleanly with a segfault rather than qemu asserting and then locking up (assert()in qemu's linux-user code doesn't really behave very nicely...)user-exec.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)user-exec.c +2
-1@@ -97,7 +97,8 @@ static inline int handle_cpu_signal(uintptr_t pc, unsigned long address, pc, address, is_write, *(unsigned long *)old_set);#endif /* XXX: locking issue */ -if (is_write&&page_unprotect (h2g (address), pc, puc)) { +if (is_write&&h2g_valid (address) +&&page_unprotect (h2g (address), pc, puc)) {return 1 ; }