From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Laurent Vivier" <laurent@vivier.eu>,
"Peter Maydell" <peter.maydell@linaro.org>
Subject: [PULL 18/27] linux-user/nios2: Fixes for signal frame setup
Date: Thu, 6 Jan 2022 11:41:28 +0100 [thread overview]
Message-ID: <20220106104137.732883-19-laurent@vivier.eu> (raw)
In-Reply-To: <20220106104137.732883-1-laurent@vivier.eu>
From: Richard Henderson <richard.henderson@linaro.org>
Do not confuse host and guest addresses. Lock and unlock
the target_rt_sigframe structure in setup_rt_sigframe.
Since rt_setup_ucontext always returns 0, drop the return
value entirely. This eliminates the only write to the err
variable in setup_rt_sigframe.
Always copy the siginfo structure.
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20211221025012.1057923-3-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/nios2/signal.c | 51 ++++++++++++++++-----------------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c
index a77e8a40f468..adbffe32e3c8 100644
--- a/linux-user/nios2/signal.c
+++ b/linux-user/nios2/signal.c
@@ -42,7 +42,7 @@ struct target_rt_sigframe {
struct target_ucontext uc;
};
-static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
+static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
{
unsigned long *gregs = uc->tuc_mcontext.gregs;
@@ -75,8 +75,6 @@ static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env)
__put_user(env->regs[R_GP], &gregs[25]);
__put_user(env->regs[R_EA], &gregs[27]);
__put_user(env->regs[R_SP], &gregs[28]);
-
- return 0;
}
static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc,
@@ -135,8 +133,8 @@ static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc,
return 0;
}
-static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
- size_t frame_size)
+static abi_ptr get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
+ size_t frame_size)
{
unsigned long usp;
@@ -144,7 +142,7 @@ static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env,
usp = target_sigsp(get_sp_from_cpustate(env), ka);
/* Verify, is it 32 or 64 bit aligned */
- return (void *)((usp - frame_size) & -8UL);
+ return (usp - frame_size) & -8;
}
void setup_rt_frame(int sig, struct target_sigaction *ka,
@@ -153,26 +151,25 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
CPUNios2State *env)
{
struct target_rt_sigframe *frame;
- int i, err = 0;
+ abi_ptr frame_addr;
+ int i;
- frame = get_sigframe(ka, env, sizeof(*frame));
-
- if (ka->sa_flags & SA_SIGINFO) {
- tswap_siginfo(&frame->info, info);
+ frame_addr = get_sigframe(ka, env, sizeof(*frame));
+ if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
+ force_sigsegv(sig);
+ return;
}
+ tswap_siginfo(&frame->info, info);
+
/* Create the ucontext. */
__put_user(0, &frame->uc.tuc_flags);
__put_user(0, &frame->uc.tuc_link);
target_save_altstack(&frame->uc.tuc_stack, env);
- err |= rt_setup_ucontext(&frame->uc, env);
+ rt_setup_ucontext(&frame->uc, env);
for (i = 0; i < TARGET_NSIG_WORDS; i++) {
__put_user((abi_ulong)set->sig[i],
- (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);
- }
-
- if (err) {
- goto give_sigsegv;
+ (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]);
}
/* Set up to return from userspace; jump to fixed address sigreturn
@@ -180,19 +177,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
env->regs[R_RA] = (unsigned long) (0x1044);
/* Set up registers for signal handler */
- env->regs[R_SP] = (unsigned long) frame;
- env->regs[4] = (unsigned long) sig;
- env->regs[5] = (unsigned long) &frame->info;
- env->regs[6] = (unsigned long) &frame->uc;
- env->regs[R_EA] = (unsigned long) ka->_sa_handler;
- return;
-
-give_sigsegv:
- if (sig == TARGET_SIGSEGV) {
- ka->_sa_handler = TARGET_SIG_DFL;
- }
- force_sigsegv(sig);
- return;
+ env->regs[R_SP] = frame_addr;
+ env->regs[4] = sig;
+ env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info);
+ env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc);
+ env->regs[R_EA] = ka->_sa_handler;
+
+ unlock_user_struct(frame, frame_addr, 1);
}
long do_sigreturn(CPUNios2State *env)
--
2.33.1
next prev parent reply other threads:[~2022-01-06 10:57 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 10:41 [PULL 00/27] Linux user for 7.0 patches Laurent Vivier
2022-01-06 10:41 ` [PULL 01/27] qemu-binfmt-conf.sh: fix -F option Laurent Vivier
2022-01-06 10:41 ` [PULL 02/27] linux-user/hexagon: Use generic target_stat64 structure Laurent Vivier
2022-01-06 10:41 ` [PULL 03/27] linux-user: Mark cpu_loop() with noreturn attribute Laurent Vivier
2022-01-06 10:41 ` [PULL 04/27] linux-user: Move target_signal.h generic definitions to generic/signal.h Laurent Vivier
2022-01-06 10:41 ` [PULL 05/27] linux-user: target_syscall.h remove definition TARGET_MINSIGSTKSZ Laurent Vivier
2022-01-06 10:41 ` [PULL 06/27] linux-user: Remove TARGET_SIGSTKSZ Laurent Vivier
2022-01-06 10:41 ` [PULL 07/27] linux-user: Split out do_prctl and subroutines Laurent Vivier
2022-01-06 10:41 ` [PULL 08/27] linux-user: Disable more prctl subcodes Laurent Vivier
2022-01-06 10:41 ` [PULL 09/27] linux-user: Add code for PR_GET/SET_UNALIGN Laurent Vivier
2022-01-06 10:41 ` [PULL 10/27] target/alpha: Implement prctl_unalign_sigbus Laurent Vivier
2022-01-06 10:41 ` [PULL 11/27] target/hppa: " Laurent Vivier
2022-01-06 10:41 ` [PULL 12/27] target/sh4: " Laurent Vivier
2022-01-06 10:41 ` [PULL 13/27] linux-user/signal: Map exit signals in SIGCHLD siginfo_t Laurent Vivier
2022-01-06 10:41 ` [PULL 14/27] linux-user: add sched_getattr support Laurent Vivier
2022-01-06 10:41 ` [PULL 15/27] linux-user: call set/getscheduler set/getparam directly Laurent Vivier
2022-01-06 10:41 ` [PULL 16/27] linux-user/syscall.c: fix missed flag for shared memory in open_self_maps Laurent Vivier
2022-01-06 10:41 ` [PULL 17/27] linux-user/nios2: Properly emulate EXCP_TRAP Laurent Vivier
2022-01-06 10:41 ` Laurent Vivier [this message]
2022-01-06 10:41 ` [PULL 19/27] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Laurent Vivier
2022-01-06 10:41 ` [PULL 20/27] linux-user/nios2: Map a real kuser page Laurent Vivier
2022-01-10 13:22 ` Peter Maydell
2022-01-06 10:41 ` [PULL 21/27] linux-user/nios2: Fix EA vs PC confusion Laurent Vivier
2022-01-06 10:41 ` [PULL 22/27] linux-user/nios2: Fix sigmask in setup_rt_frame Laurent Vivier
2022-01-06 10:41 ` [PULL 23/27] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Laurent Vivier
2022-01-06 10:41 ` [PULL 24/27] linux-user/syscall.c: malloc to g_try_malloc Laurent Vivier
2022-01-06 10:41 ` [PULL 25/27] linux-user: netlink: update IFLA entries Laurent Vivier
2022-01-06 10:41 ` [PULL 26/27] linux-user: netlink: Add IFLA_VFINFO_LIST Laurent Vivier
2022-01-06 10:41 ` [PULL 27/27] linux-user: netlink: update IFLA_BRPORT entries Laurent Vivier
2022-01-06 21:15 ` [PULL 00/27] Linux user for 7.0 patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220106104137.732883-19-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).