linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
PATCH 1/1 linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
This patch fixes the mount call. GUEST_BASE shouldn't be added to a NULL pointer on arg5 . failing call:mount("rootfs", "/", 0x47a78, MS_MGC_VAL|MS_REMOUNT, 0x10000) = -1 EFAULT (Bad address)
correct call:mount("rootfs", "/", 0x37ab0, MS_MGC_VAL|MS_REMOUNT, NULL) = 0
--- linux-user/syscall.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
linux-user/syscall.c +6 -2
@@ -4445,12 +4445,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, p3 =lock_user_string (arg3);if (!p || !p2 || !p3) ret = -TARGET_EFAULT ; -else +else {/* FIXME - arg5 should be locked, but it isn't clear how to * do that since it's not guaranteed to be a NULL-terminated * string. */ - ret =get_errno (mount (p, p2, p3, (unsigned long )arg4,g2h (arg5))); +if ( ! arg5 ) + ret =get_errno (mount (p, p2, p3, (unsigned long )arg4,NULL )); +else + ret =get_errno (mount (p, p2, p3, (unsigned long )arg4,g2h (arg5))); + }unlock_user (p, arg1,0 );unlock_user (p2, arg2,0 );unlock_user (p3, arg3,0 );
Thinking a bit more about this, I wonder if g2h(x) shouldn't itself always return NULL on x = NULL ?
Something like:
cpu-all.h +1 -1
@@ -633,7 +633,7 @@ extern int have_guest_base;#endif /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h (x) ((void *)((unsigned long)(x) + GUEST_BASE)) +#define g2h (x) ( !x ? NULL:((void *)((unsigned long)(x) + GUEST_BASE)))#define h2g (x) ({ \ unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \/* Check if given address fits target address space */ \
I read the comment above, but before replacing it in user-mode (if possible), we should fix it ;) .
Best,
Jan-Simon
Quoted 2 lines · Jan-Simon Möller
Thinking a bit more about this, I wonder if g2h(x) shouldn't itself always return NULL on x = NULL ?
I agree this seems like a a better idea than modifying the users of g2h.
Quoted 28 lines
Something like:
Signed-off-by Jan-Simon Möller <[email protected]>cpu-all.h +1
-1@@ -633,7 +633,7 @@ extern int have_guest_base;#endif /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h (x) ((void *)((unsigned long)(x) + GUEST_BASE)) +#define g2h (x) ( !x ? NULL:((void *)((unsigned long)(x) + GUEST_BASE)))#define h2g (x) ({ \ unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \/* Check if given address fits target address space */ \I read the comment above, but before replacing it in user-mode (if possible), we should fix it ;) .
Best,
Jan-Simon
Am Mittwoch 26 August 2009 15:40:43 schrieb Riku Voipio:
Quoted 6 lines · Jan-Simon Möller
Quoted 2 lines
Thinking a bit more about this, I wonder if g2h(x) shouldn't itself always return NULL on x = NULL ?
I agree this seems like a a better idea than modifying the users of g2h.
Ok, then please apply to master.
Best,
Jan-Simon
Am Mittwoch 26 August 2009 15:40:43 schrieb Riku Voipio:
Quoted 17 lines · Jan-Simon Möller
Quoted 2 lines
Thinking a bit more about this, I wonder if g2h(x) shouldn't itself always return NULL on x = NULL ?
I agree this seems like a a better idea than modifying the users of g2h.
Quoted 11 lines
Something like:
Signed-off-by Jan-Simon Möller <[email protected]>cpu-all.h +0
-0@@ -633,7 +633,7 @@ extern int have_guest_base;#endif
Quoted 8 lines
cpu-all.h extern int have_guest_base; · line 639
Quoted 8 lines
cpu-all.h +1
-0/* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE)) +#define g2h (x) ( !x ? NULL:((void *)((unsigned long)(x) + GUEST_BASE)))#define h2g (x) ({ \ unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \/* Check if given address fits target address space */ \
Take the first patch for syscall.c / mount .
Unfortunately, the above one has side-effects where functions rely on a shifted NULL pointer ...
Best,
Jan-Simon