diff mbox series

linux-user: fix guest/host address mixup in i386 setup_rt_frame()

Message ID 20210803171858.148394-1-iii@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series linux-user: fix guest/host address mixup in i386 setup_rt_frame() | expand

Commit Message

Ilya Leoshkevich Aug. 3, 2021, 5:18 p.m. UTC
setup_rt_frame() passes siginfo and ucontext host addresses to guest
signal handlers, causing problems when e.g. emulating x86_64 on s390x.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 linux-user/i386/signal.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Richard Henderson Aug. 3, 2021, 9:03 p.m. UTC | #1
On 8/3/21 7:18 AM, Ilya Leoshkevich wrote:
> setup_rt_frame() passes siginfo and ucontext host addresses to guest
> signal handlers, causing problems when e.g. emulating x86_64 on s390x.
> 
> Signed-off-by: Ilya Leoshkevich<iii@linux.ibm.com>
> ---
>   linux-user/i386/signal.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Laurent Vivier Aug. 5, 2021, 10:17 a.m. UTC | #2
Le 03/08/2021 à 19:18, Ilya Leoshkevich a écrit :
> setup_rt_frame() passes siginfo and ucontext host addresses to guest
> signal handlers, causing problems when e.g. emulating x86_64 on s390x.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  linux-user/i386/signal.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
> index 8701774e37..841cd19651 100644
> --- a/linux-user/i386/signal.c
> +++ b/linux-user/i386/signal.c
> @@ -436,13 +436,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
>  
>  #ifndef TARGET_X86_64
>      env->regs[R_EAX] = sig;
> -    env->regs[R_EDX] = (unsigned long)&frame->info;
> -    env->regs[R_ECX] = (unsigned long)&frame->uc;
> +    env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, info);
> +    env->regs[R_ECX] = frame_addr + offsetof(struct rt_sigframe, uc);
>  #else
>      env->regs[R_EAX] = 0;
>      env->regs[R_EDI] = sig;
> -    env->regs[R_ESI] = (unsigned long)&frame->info;
> -    env->regs[R_EDX] = (unsigned long)&frame->uc;
> +    env->regs[R_ESI] = frame_addr + offsetof(struct rt_sigframe, info);
> +    env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, uc);
>  #endif
>  
>      cpu_x86_load_seg(env, R_DS, __USER_DS);
> 

Applied to my linux-user-for-6.1 branch.

Thanks,
Laurent
diff mbox series

Patch

diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
index 8701774e37..841cd19651 100644
--- a/linux-user/i386/signal.c
+++ b/linux-user/i386/signal.c
@@ -436,13 +436,13 @@  void setup_rt_frame(int sig, struct target_sigaction *ka,
 
 #ifndef TARGET_X86_64
     env->regs[R_EAX] = sig;
-    env->regs[R_EDX] = (unsigned long)&frame->info;
-    env->regs[R_ECX] = (unsigned long)&frame->uc;
+    env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, info);
+    env->regs[R_ECX] = frame_addr + offsetof(struct rt_sigframe, uc);
 #else
     env->regs[R_EAX] = 0;
     env->regs[R_EDI] = sig;
-    env->regs[R_ESI] = (unsigned long)&frame->info;
-    env->regs[R_EDX] = (unsigned long)&frame->uc;
+    env->regs[R_ESI] = frame_addr + offsetof(struct rt_sigframe, info);
+    env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, uc);
 #endif
 
     cpu_x86_load_seg(env, R_DS, __USER_DS);