From 23fff7a17f47420797ac6480147941612152a9ad Mon Sep 17 00:00:00 2001 From: Andreas Krebbel Date: Wed, 24 Mar 2021 19:51:28 +0100 Subject: [PATCH 1/2] 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. Signed-off-by: Andreas Krebbel Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson Message-Id: <20210324185128.63971-1-krebbel@linux.ibm.com> Signed-off-by: Laurent Vivier --- linux-user/s390x/signal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c index ecfa2a14a9..7107c5fb53 100644 --- a/linux-user/s390x/signal.c +++ b/linux-user/s390x/signal.c @@ -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)); } From 4a1e6bce2308b720d79d5ea0a3d24501c89bd80c Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Fri, 26 Mar 2021 22:11:16 -0400 Subject: [PATCH 2/2] linux-user: allow NULL msg in recvfrom The kernel allows a NULL msg in recvfrom so that he size of the next message may be queried before allocating a correctly sized buffer. This change allows the syscall translator to pass along the NULL msg pointer instead of returning early with EFAULT. Signed-off-by: Zach Reizner Reviewed-by: Laurent Vivier Message-Id: Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1e508576c7..294779c86f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3679,9 +3679,14 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, void *host_msg; abi_long ret; - host_msg = lock_user(VERIFY_WRITE, msg, len, 0); - if (!host_msg) - return -TARGET_EFAULT; + if (!msg) { + host_msg = NULL; + } else { + host_msg = lock_user(VERIFY_WRITE, msg, len, 0); + if (!host_msg) { + return -TARGET_EFAULT; + } + } if (target_addr) { if (get_user_u32(addrlen, target_addrlen)) { ret = -TARGET_EFAULT;