qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
@ 2009-08-25 22:02 Jan-Simon Möller
  2009-08-25 23:37 ` Jan-Simon Möller
  0 siblings, 1 reply; 5+ messages in thread
From: Jan-Simon Möller @ 2009-08-25 22:02 UTC (permalink / raw)
  To: qemu-devel

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


Signed-off-by:  Jan-Simon Möller  <dl9pf@gmx.de>
---
 linux-user/syscall.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 673eed4..5b2ec4f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
  2009-08-25 22:02 [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer Jan-Simon Möller
@ 2009-08-25 23:37 ` Jan-Simon Möller
  2009-08-26 13:40   ` Riku Voipio
  0 siblings, 1 reply; 5+ messages in thread
From: Jan-Simon Möller @ 2009-08-25 23:37 UTC (permalink / raw)
  To: qemu-devel

Thinking a bit more about this, I wonder if g2h(x) shouldn't itself always 
return NULL on x = NULL ? 

Something like:

Signed-off-by:  Jan-Simon Möller  <dl9pf@gmx.de>

diff --git a/cpu-all.h b/cpu-all.h
index 1a6a812..631f678 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
  2009-08-25 23:37 ` Jan-Simon Möller
@ 2009-08-26 13:40   ` Riku Voipio
  2009-08-26 19:58     ` Jan-Simon Möller
  2009-08-28 13:20     ` Jan-Simon Möller
  0 siblings, 2 replies; 5+ messages in thread
From: Riku Voipio @ 2009-08-26 13:40 UTC (permalink / raw)
  To: Jan-Simon Möller; +Cc: qemu-devel

On Wed, Aug 26, 2009 at 01:37:48AM +0200, Jan-Simon Möller wrote:
> 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.

> Something like:
> 
> Signed-off-by:  Jan-Simon Möller  <dl9pf@gmx.de>
> 
> diff --git a/cpu-all.h b/cpu-all.h
> index 1a6a812..631f678 100644
> --- a/cpu-all.h
> +++ b/cpu-all.h
> @@ -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
> 
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
  2009-08-26 13:40   ` Riku Voipio
@ 2009-08-26 19:58     ` Jan-Simon Möller
  2009-08-28 13:20     ` Jan-Simon Möller
  1 sibling, 0 replies; 5+ messages in thread
From: Jan-Simon Möller @ 2009-08-26 19:58 UTC (permalink / raw)
  To: qemu-devel

Am Mittwoch 26 August 2009 15:40:43 schrieb Riku Voipio:
> On Wed, Aug 26, 2009 at 01:37:48AM +0200, Jan-Simon Möller wrote:
> > 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer
  2009-08-26 13:40   ` Riku Voipio
  2009-08-26 19:58     ` Jan-Simon Möller
@ 2009-08-28 13:20     ` Jan-Simon Möller
  1 sibling, 0 replies; 5+ messages in thread
From: Jan-Simon Möller @ 2009-08-28 13:20 UTC (permalink / raw)
  To: qemu-devel

Am Mittwoch 26 August 2009 15:40:43 schrieb Riku Voipio:
> On Wed, Aug 26, 2009 at 01:37:48AM +0200, Jan-Simon Möller wrote:
> > 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.
>
> > Something like:
> >
> > Signed-off-by:  Jan-Simon Möller  <dl9pf@gmx.de>
> >
> > diff --git a/cpu-all.h b/cpu-all.h
> > index 1a6a812..631f678 100644
> > --- a/cpu-all.h
> > +++ b/cpu-all.h
> > @@ -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 */ \
> >
> >

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-28 13:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-25 22:02 [Qemu-devel] [Patch] linux-user/syscall.c - don't add GUEST_BASE to NULL pointer Jan-Simon Möller
2009-08-25 23:37 ` Jan-Simon Möller
2009-08-26 13:40   ` Riku Voipio
2009-08-26 19:58     ` Jan-Simon Möller
2009-08-28 13:20     ` Jan-Simon Möller

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).