Skip to contentSkip to conversation

linux-user/s390x: Apply h2g to address of sigreturn stub

PATCH In review Andreas Krebbel 4 participants 11 messages Mar 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/s390x: Apply h2g to address of sigreturn stub

The sigreturn SVC is put onto the stack by the emulation code. Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/s390x/signal.c +2 -2
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
         env->regs[14] = (unsigned long)
                 ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                         | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn,
                    (uint16_t *)(frame->retcode));
@@ -213,7 +213,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (unsigned long) h2g(frame->retcode) | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 31 lines · Andreas Krebbel

The sigreturn SVC is put onto the stack by the emulation code. Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
          env->regs[14] = (unsigned long)
                  ka->sa_restorer | PSW_ADDR_AMODE;
      } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                          | PSW_ADDR_AMODE;
          __put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn,
                     (uint16_t *)(frame->retcode));

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

Quoted 8 lines
linux-user/s390x/signal.c +1 -1
@@ -213,7 +213,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
      if (ka->sa_flags & TARGET_SA_RESTORER) {
          env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
      } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (unsigned long) h2g(frame->retcode) | PSW_ADDR_AMODE;
          __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                     (uint16_t *)(frame->retcode));
      }

Sounds sane to me, although I am not an expert on that code :)

Signature · 3 lines
Thanks,

David / dhildenb
#2 lore raw

Le 24/03/2021 à 10:17, David Hildenbrand a écrit :

Quoted 17 lines · Andreas Krebbel
Quoted 16 lines

The sigreturn SVC is put onto the stack by the emulation code.  Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 11 lines

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

Quoted 11 lines
linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
           env->regs[14] = (unsigned long)
                   ka->sa_restorer | PSW_ADDR_AMODE;
       } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                           | PSW_ADDR_AMODE;

Well, it really doesn't sound good as frame_addr is a guest address (and sa_restorer is too)

Where is the code that does the g2h() you want to nullify?

Thanks,
Laurent

#3 lore raw
Quoted 18 lines · Laurent Vivier

Le 24/03/2021 à 10:17, David Hildenbrand a écrit :

Quoted 17 lines · Andreas Krebbel
Quoted 16 lines

The sigreturn SVC is put onto the stack by the emulation code.  Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
Quoted 11 lines

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

Quoted 11 lines
linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
           env->regs[14] = (unsigned long)
                   ka->sa_restorer | PSW_ADDR_AMODE;
       } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                           | PSW_ADDR_AMODE;

Well, it really doesn't sound good as frame_addr is a guest address (and sa_restorer is too)

I would expect the sa_restorer address to actually point into the guest code section.

Quoted 2 lines

Where is the code that does the g2h() you want to nullify?

That's on the code path which usually fetches instructions from memory. In cpu_lduw_code called via:

s390x_tr_translate_insn->translate_one->extract_insn->ld_code2->cpu_lduw_code

Btw. Power also uses h2g while setting up the trampoline address:

...

    save_user_regs(env, mctx);
    encode_trampoline(TARGET_NR_rt_sigreturn, trampptr);

    /* The kernel checks for the presence of a VDSO here.  We don't
       emulate a vdso, so use a sigreturn system call.  */
    env->lr = (target_ulong) h2g(trampptr);

...

Quoted 4 lines

Thanks,
Laurent

Andreas

#4 lore raw

Le 24/03/2021 à 12:26, Andreas Krebbel a écrit :

Quoted 33 lines · Laurent Vivier
Quoted 18 lines

Le 24/03/2021 à 10:17, David Hildenbrand a écrit :

Quoted 17 lines · Andreas Krebbel
Quoted 16 lines

The sigreturn SVC is put onto the stack by the emulation code.  Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
Quoted 11 lines

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

Quoted 11 lines
linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
           env->regs[14] = (unsigned long)
                   ka->sa_restorer | PSW_ADDR_AMODE;
       } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                           | PSW_ADDR_AMODE;

Well, it really doesn't sound good as frame_addr is a guest address (and sa_restorer is too)

Quoted 1 line

I would expect the sa_restorer address to actually point into the guest code section.

yes, it does. like frame_addr. The host address is frame, see:

    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
        goto give_sigsegv;
    }

So frame = g2h(frame_addr)

This line put the address of the next instruction to execute (guest address space):

env->regs[14] = (frame_addr + offsetof(sigframe, retcode))

                        | PSW_ADDR_AMODE;

This line put at this address the NR_sigreturn syscall (but __put_user() uses host address):

__put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn,
(uint16_t *)(frame->retcode));

In theory:

    frame_addr + offsetof(sigframe, retcode) == h2g(frame->retcode)

So the next instruction executed after this function is the sigreturn() syscall.

I think the problem is elsewhere.

But I don't see what is the problem you are trying to solve.

Quoted 7 lines
Quoted 3 lines

Where is the code that does the g2h() you want to nullify?

That's on the code path which usually fetches instructions from memory. In cpu_lduw_code called via:

s390x_tr_translate_insn->translate_one->extract_insn->ld_code2->cpu_lduw_code

cpu_lduw_code() takes a guest a address and needs to translate it to host address. We need the g2h() here because we have a guest address.

Quoted 4 lines

Btw. Power also uses h2g while setting up the trampoline address:

Quoted 8 lines

...

    save_user_regs(env, mctx);
    encode_trampoline(TARGET_NR_rt_sigreturn, trampptr);

    /* The kernel checks for the presence of a VDSO here.  We don't
       emulate a vdso, so use a sigreturn system call.  */
    env->lr = (target_ulong) h2g(trampptr);

...

But here, it's correct because trampptr is an host address:

    trampptr = &rt_sf->trampoline[0];

Thanks,
Laurent

#5 lore raw
Quoted 88 lines · Laurent Vivier

Le 24/03/2021 à 12:26, Andreas Krebbel a écrit :

Quoted 33 lines · Laurent Vivier
Quoted 18 lines

Le 24/03/2021 à 10:17, David Hildenbrand a écrit :

Quoted 17 lines · Andreas Krebbel
Quoted 16 lines

The sigreturn SVC is put onto the stack by the emulation code.  Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
Quoted 11 lines

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

Quoted 11 lines
linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
           env->regs[14] = (unsigned long)
                   ka->sa_restorer | PSW_ADDR_AMODE;
       } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                           | PSW_ADDR_AMODE;

Well, it really doesn't sound good as frame_addr is a guest address (and sa_restorer is too)

Quoted 1 line

I would expect the sa_restorer address to actually point into the guest code section.

yes, it does. like frame_addr. The host address is frame, see:

    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
        goto give_sigsegv;
    }

So frame = g2h(frame_addr)

This line put the address of the next instruction to execute (guest address space):

env->regs[14] = (frame_addr + offsetof(sigframe, retcode))

                        | PSW_ADDR_AMODE;

This line put at this address the NR_sigreturn syscall (but __put_user() uses host address):

__put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn,
(uint16_t *)(frame->retcode));

In theory:

    frame_addr + offsetof(sigframe, retcode) == h2g(frame->retcode)

So the next instruction executed after this function is the sigreturn() syscall.

I think the problem is elsewhere.

But I don't see what is the problem you are trying to solve.

Quoted 7 lines
Quoted 3 lines

Where is the code that does the g2h() you want to nullify?

That's on the code path which usually fetches instructions from memory. In cpu_lduw_code called via:

s390x_tr_translate_insn->translate_one->extract_insn->ld_code2->cpu_lduw_code

cpu_lduw_code() takes a guest a address and needs to translate it to host address. We need the g2h() here because we have a guest address.

Quoted 4 lines

Btw. Power also uses h2g while setting up the trampoline address:

Quoted 8 lines

...

    save_user_regs(env, mctx);
    encode_trampoline(TARGET_NR_rt_sigreturn, trampptr);

    /* The kernel checks for the presence of a VDSO here.  We don't
       emulate a vdso, so use a sigreturn system call.  */
    env->lr = (target_ulong) h2g(trampptr);

...

Quoted 7 lines

But here, it's correct because trampptr is an host address:

    trampptr = &rt_sf->trampoline[0];

Thanks,
Laurent

Unfortunately I've confused the two locations which do the trampoline setup in the discussion setup_frame vs setup_rt_frame.

The part I actually needed to fix was in setup_rt_frame and there the fix is correct I think since here we do use 'frame' which is the host address.

While doing that change I also stumbled upon the other location in setup_frame. There it is using frame_addr for doing the same thing. There as you say adding h2g is wrong.

Here just the change which I think is needed:

linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..7fba1c7999 100644
@@ -213,7 +213,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (unsigned long) h2g(frame->retcode) | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }

Andreas

#6 lore raw
Quoted 13 lines · Andreas Krebbel

The part I actually needed to fix was in setup_rt_frame and there the fix is correct I think since here we do use 'frame' which is the host address.

While doing that change I also stumbled upon the other location in setup_frame. There it is using frame_addr for doing the same thing. There as you say adding h2g is wrong.

Here just the change which I think is needed:

linux-user/s390x/signal.c +0 -0
index ecfa2a14a9..7fba1c7999 100644

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

Quoted 5 lines
linux-user/s390x/signal.c +1 -1
@@ -213,7 +213,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
      if (ka->sa_flags & TARGET_SA_RESTORER) {
          env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
      } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (unsigned long) h2g(frame->retcode) | PSW_ADDR_AMODE;

Correct, though I think the formulation using frame_addr is more obvious.

Unrelated, but all the uses of "unsigned long" are wrong -- they should be target_ulong.

r~

#7 lore raw
In reply to Andreas Krebbel

Le 24/03/2021 à 15:14, Andreas Krebbel a écrit :

Quoted 114 lines · Laurent Vivier
Quoted 88 lines

Le 24/03/2021 à 12:26, Andreas Krebbel a écrit :

Quoted 33 lines · Laurent Vivier
Quoted 18 lines

Le 24/03/2021 à 10:17, David Hildenbrand a écrit :

Quoted 17 lines · Andreas Krebbel
Quoted 16 lines

The sigreturn SVC is put onto the stack by the emulation code.  Hence the address of it should not be subject to guest_base transformation when fetching it.

The fix applies h2g to the address when writing it into the return address register to nullify the transformation applied to it later.

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 | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines
Quoted 11 lines

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

Quoted 11 lines
linux-user/s390x/signal.c +1 -1
index ecfa2a14a9..1412376958 100644
@@ -152,7 +152,7 @@ void setup_frame(int sig, struct target_sigaction *ka,
           env->regs[14] = (unsigned long)
                   ka->sa_restorer | PSW_ADDR_AMODE;
       } else {
-        env->regs[14] = (frame_addr + offsetof(sigframe, retcode))
+        env->regs[14] = h2g(frame_addr + offsetof(sigframe, retcode))
                           | PSW_ADDR_AMODE;

Well, it really doesn't sound good as frame_addr is a guest address (and sa_restorer is too)

Quoted 1 line

I would expect the sa_restorer address to actually point into the guest code section.

yes, it does. like frame_addr. The host address is frame, see:

    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
        goto give_sigsegv;
    }

So frame = g2h(frame_addr)

This line put the address of the next instruction to execute (guest address space):

env->regs[14] = (frame_addr + offsetof(sigframe, retcode))

                        | PSW_ADDR_AMODE;

This line put at this address the NR_sigreturn syscall (but __put_user() uses host address):

__put_user(S390_SYSCALL_OPCODE | TARGET_NR_sigreturn,
(uint16_t *)(frame->retcode));

In theory:

    frame_addr + offsetof(sigframe, retcode) == h2g(frame->retcode)

So the next instruction executed after this function is the sigreturn() syscall.

I think the problem is elsewhere.

But I don't see what is the problem you are trying to solve.

Quoted 7 lines
Quoted 3 lines

Where is the code that does the g2h() you want to nullify?

That's on the code path which usually fetches instructions from memory. In cpu_lduw_code called via:

s390x_tr_translate_insn->translate_one->extract_insn->ld_code2->cpu_lduw_code

cpu_lduw_code() takes a guest a address and needs to translate it to host address. We need the g2h() here because we have a guest address.

Quoted 4 lines

Btw. Power also uses h2g while setting up the trampoline address:

Quoted 8 lines

...

    save_user_regs(env, mctx);
    encode_trampoline(TARGET_NR_rt_sigreturn, trampptr);

    /* The kernel checks for the presence of a VDSO here.  We don't
       emulate a vdso, so use a sigreturn system call.  */
    env->lr = (target_ulong) h2g(trampptr);

...

Quoted 7 lines

But here, it's correct because trampptr is an host address:

    trampptr = &rt_sf->trampoline[0];

Thanks,
Laurent

Unfortunately I've confused the two locations which do the trampoline setup in the discussion setup_frame vs setup_rt_frame.

The part I actually needed to fix was in setup_rt_frame and there the fix is correct I think since here we do use 'frame' which is the host address.

While doing that change I also stumbled upon the other location in setup_frame. There it is using frame_addr for doing the same thing. There as you say adding h2g is wrong.

Here just the change which I think is needed:

linux-user/s390x/signal.c +0 -0
index ecfa2a14a9..7fba1c7999 100644

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

Quoted 8 lines
linux-user/s390x/signal.c +1 -1
@@ -213,7 +213,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (unsigned long) h2g(frame->retcode) | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }

This is correct, but as we have frame_addr, it's better to have the same code as in setup_frame() (frame_addr + offsetof(sigframe, retcode))

Thanks,
Laurent

#8 lore raw

PATCH v2 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 have to use the guest frame pointer instead of the host frame pointer.

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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/s390x/signal.c +2 -1
index ecfa2a14a9..e9bf865074 100644
@@ -213,7 +213,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (target_ulong) (frame_addr + offsetof(rt_sigframe, 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 v2 1/1
#9 lore raw

Re: [PATCH v2] linux-user/s390x: Use the guest pointer for the sigreturn stub

Le 24/03/2021 à 16:55, Andreas Krebbel a écrit :

Quoted 19 lines

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

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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/s390x/signal.c +0 -0
index ecfa2a14a9..e9bf865074 100644

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

Quoted 9 lines
linux-user/s390x/signal.c +2 -1
@@ -213,7 +213,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (target_ulong) (frame_addr + offsetof(rt_sigframe, retcode))
+                        | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }

but if you want to send a v3:
- to be consistent with lines below, use "offsetof(typeof(*frame), ..."
- in the line above, you can remove the (unsigned long) of the sa_restorer as it is an abi_ulong,
- don't send the "v2" as a reply to the v1 as it can be hidden in the mail thread and missed by the maintainer :)

Thanks,
Laurent

#10 lore raw

Re: [PATCH v2] linux-user/s390x: Use the guest pointer for the sigreturn stub

Quoted 32 lines · Laurent Vivier

Le 24/03/2021 à 16:55, Andreas Krebbel a écrit :

Quoted 19 lines

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

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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/s390x/signal.c +0 -0
index ecfa2a14a9..e9bf865074 100644

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

Quoted 9 lines
linux-user/s390x/signal.c +2 -1
@@ -213,7 +213,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
     if (ka->sa_flags & TARGET_SA_RESTORER) {
         env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
     } else {
-        env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
+        env->regs[14] = (target_ulong) (frame_addr + offsetof(rt_sigframe, retcode))
+                        | PSW_ADDR_AMODE;
         __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
                    (uint16_t *)(frame->retcode));
     }
Quoted 1 line

but if you want to send a v3:

Sure, will do.

Quoted 2 lines

- to be consistent with lines below, use "offsetof(typeof(*frame), ..."
- in the line above, you can remove the (unsigned long) of the sa_restorer as it is an abi_ulong,

The (target_ulong) cast could probably go away as well since frame_addr is also abi_ulong.

Quoted 2 lines

- don't send the "v2" as a reply to the v1 as it can be hidden in the mail thread and missed by the maintainer :)

Ok.

Andreas

Quoted 4 lines

Thanks,
Laurent