Skip to contentSkip to conversation

linux-user/s390x: Use the guest pointer for the sigreturn stub

PATCH Applied Andreas Krebbel 3 participants 5 messages Mar 24, 2021 – Mar 26, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 linux-user/s390x: Use the guest pointer for the sigreturn stub

When setting up the pointer for the sigreturn stub in the return address register (r14) we currently use the host frame address instead of the guest frame address.

Note: This only caused problems if Qemu has been built with --disable-pie (as it is in distros nowadays). Otherwise guest_base defaults to 0 hiding the actual problem.

---
 linux-user/s390x/signal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
linux-user/s390x/signal.c +3 -2
index ecfa2a14a9..7107c5fb53 100644
@@ -211,9 +211,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */
     if (ka->sa_flags & TARGET_SA_RESTORER) {
-        env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
+        env->regs[14] = ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (frame_addr + offsetof(typeof(*frame), retcode))
+                        | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }
Signature · 1 line
2.30.2
Reviewed-by on v3 1/1
#1 lore raw

Le 24/03/2021 à 19:51, Andreas Krebbel a écrit :

Quoted 21 lines

When setting up the pointer for the sigreturn stub in the return address register (r14) we currently use the host frame address instead of the guest frame address.

Note: This only caused problems if Qemu has been built with --disable-pie (as it is in distros nowadays). Otherwise guest_base defaults to 0 hiding the actual problem.

---
 linux-user/s390x/signal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
linux-user/s390x/signal.c +0 -0
index ecfa2a14a9..7107c5fb53 100644
@@ -211,9 +211,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */

linux-user/s390x/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 220

Quoted 10 lines
linux-user/s390x/signal.c +3 -2
     if (ka->sa_flags & TARGET_SA_RESTORER) {
-        env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
+        env->regs[14] = ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (frame_addr + offsetof(typeof(*frame), retcode))
+                        | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }
Reviewed-by on v3 1/1
#2 lore raw
In reply to Andreas Krebbel
Quoted 4 lines · Andreas Krebbel

When setting up the pointer for the sigreturn stub in the return address register (r14) we currently use the host frame address instead of the guest frame address.

Quoted 8 lines

Note: This only caused problems if Qemu has been built with --disable-pie (as it is in distros nowadays). Otherwise guest_base defaults to 0 hiding the actual problem.

---
  linux-user/s390x/signal.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

r~

#3 lore raw
In reply to Andreas Krebbel

Le 24/03/2021 à 19:51, Andreas Krebbel a écrit :

Quoted 21 lines

When setting up the pointer for the sigreturn stub in the return address register (r14) we currently use the host frame address instead of the guest frame address.

Note: This only caused problems if Qemu has been built with --disable-pie (as it is in distros nowadays). Otherwise guest_base defaults to 0 hiding the actual problem.

---
 linux-user/s390x/signal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
linux-user/s390x/signal.c +0 -0
index ecfa2a14a9..7107c5fb53 100644
@@ -211,9 +211,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */

linux-user/s390x/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 220

Quoted 10 lines
linux-user/s390x/signal.c +3 -2
     if (ka->sa_flags & TARGET_SA_RESTORER) {
-        env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
+        env->regs[14] = ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (frame_addr + offsetof(typeof(*frame), retcode))
+                        | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }

Applied to my linux-user-for-6.0 branch

Thanks,
Laurent

#4 lore raw
Quoted 26 lines · Laurent Vivier

Le 24/03/2021 à 19:51, Andreas Krebbel a écrit :

Quoted 25 lines

When setting up the pointer for the sigreturn stub in the return address register (r14) we currently use the host frame address instead of the guest frame address.

Note: This only caused problems if Qemu has been built with --disable-pie (as it is in distros nowadays). Otherwise guest_base defaults to 0 hiding the actual problem.

---
 linux-user/s390x/signal.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
linux-user/s390x/signal.c +1 -2
index ecfa2a14a9..7107c5fb53 100644
@@ -211,9 +211,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     /* Set up to return from userspace.  If provided, use a stub
        already in userspace.  */
     if (ka->sa_flags & TARGET_SA_RESTORER) {
-        env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
+        env->regs[14] = ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
Quoted 8 lines

linux-user/s390x/signal.c void setup_rt_frame(int sig, struct target_sigaction *ka, · line 220

Quoted 6 lines
linux-user/s390x/signal.c +2 -0
+        env->regs[14] = (frame_addr + offsetof(typeof(*frame), retcode))
+                        | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }

Applied to my linux-user-for-6.0 branch

Thanks! Since this fixes a problem which prevents important applications (e.g. golang) to run properly under Qemu for IBM Z right now I think it qualifies for stable branch.

The patch applies cleanly on 5.0 branch. Testsuite is clean and I've verfified that it fixes the actual problem there as well.

Please consider inclusion into stable branch.

Andreas

Quoted 4 lines

Thanks,
Laurent