From: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Jeff Dike <jdike@addtoit.com>, Andrew Morton <akpm@osdl.org>,
blaisorblade_spam@yahoo.it, linux-arch@vger.kernel.org,
jdike@ccure.user-mode-linux.org
Subject: Re: [PATCH 9/11] - UML - fix signal mask on delivery error
Date: Thu, 02 Dec 2004 10:55:45 +0100 [thread overview]
Message-ID: <41AEE6A1.4020200@fujitsu-siemens.com> (raw)
In-Reply-To: <1101826791.26071.108.camel@hades.cambridge.redhat.com>
David Woodhouse wrote:
> On Sun, 2004-11-14 at 17:13 -0500, Jeff Dike wrote:
>
>> sigmasking.c - Makes sure that when a signal is (not) delivered to
>>a bogus stack, that a segfault is delivered then, and not after returning
>>to userspace. This is the test relevant to the patch that Andrew replied
>>to.
I don't know much about ppc64 and also don't have a machine to test.
So, I'm commenting the code only. If I've missed something, sorry for that.
The changes we did in UML, fiy two major issues:
1) they correct the sigmask after a segfault that happened in signal-delivery
2) they immediately deliver that SIGSEGV, before returning to user.
AFAICS, the patch seems to cover the first, but not the second.
If a SIGSEGV is forced since the stackframe/sigcontext for a signal-handler
could not be created, this SIGSEGV is queued only. To deliver it, do_signal()
must be called again, which normally won't happen (with the exception of
sys_sigretrun/sys_rt_sigreturn). Thus, SIGSEGV stays in the queue until the
next interrupt or syscall happens. IMHO this behavior is bad.
So, in UML we changed (kern_)do_signal, to loop over get_signal_to_deliver
and handle_signal, until a signal is delivered correctly or the task exits.
Bodo
>
>
> Corresponding patch for ppc64. Are we actually going to fix this for all
> architectures?
>
>
>
> ------------------------------------------------------------------------
>
> ===== arch/ppc64/kernel/signal.c 1.44 vs edited =====
> --- 1.44/arch/ppc64/kernel/signal.c 2004-10-28 08:39:49 +01:00
> +++ edited/arch/ppc64/kernel/signal.c 2004-11-26 14:13:18 +00:00
> @@ -387,7 +387,7 @@
> return 0;
> }
>
> -static void setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
> +static int setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
> sigset_t *set, struct pt_regs *regs)
> {
> /* Handler is *really* a pointer to the function descriptor for
> @@ -452,7 +452,7 @@
> if (err)
> goto badframe;
>
> - return;
> + return 0;
>
> badframe:
> #if DEBUG_SIG
> @@ -460,17 +460,19 @@
> regs, frame, newsp);
> #endif
> force_sigsegv(signr, current);
> + return -1;
> }
>
>
> /*
> * OK, we're invoking a handler
> */
> -static void handle_signal(unsigned long sig, struct k_sigaction *ka,
> - siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
> +static int handle_signal(unsigned long sig, struct k_sigaction *ka,
> + siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
> {
> /* Set up Signal Frame */
> - setup_rt_frame(sig, ka, info, oldset, regs);
> + if (setup_rt_frame(sig, ka, info, oldset, regs))
> + return 0;
>
> if (!(ka->sa.sa_flags & SA_NODEFER)) {
> spin_lock_irq(¤t->sighand->siglock);
> @@ -479,6 +481,8 @@
> recalc_sigpending();
> spin_unlock_irq(¤t->sighand->siglock);
> }
> +
> + return 1;
> }
>
> static inline void syscall_restart(struct pt_regs *regs, struct k_sigaction *ka)
> @@ -538,8 +542,7 @@
> /* Whee! Actually deliver the signal. */
> if (TRAP(regs) == 0x0C00)
> syscall_restart(regs, &ka);
> - handle_signal(signr, &ka, &info, oldset, regs);
> - return 1;
> + return handle_signal(signr, &ka, &info, oldset, regs);
> }
>
> if (TRAP(regs) == 0x0C00) { /* System Call! */
> ===== arch/ppc64/kernel/signal32.c 1.61 vs edited =====
> --- 1.61/arch/ppc64/kernel/signal32.c 2004-10-28 08:39:49 +01:00
> +++ edited/arch/ppc64/kernel/signal32.c 2004-11-26 14:13:18 +00:00
> @@ -653,9 +653,9 @@
> * Set up a signal frame for a "real-time" signal handler
> * (one which gets siginfo).
> */
> -static void handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
> - siginfo_t *info, sigset_t *oldset,
> - struct pt_regs * regs, unsigned long newsp)
> +static int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
> + siginfo_t *info, sigset_t *oldset,
> + struct pt_regs * regs, unsigned long newsp)
> {
> struct rt_sigframe32 __user *rt_sf;
> struct mcontext32 __user *frame;
> @@ -704,14 +704,14 @@
> regs->trap = 0;
> regs->result = 0;
>
> - return;
> + return 1;
>
> badframe:
> #if DEBUG_SIG
> printk("badframe in handle_rt_signal, regs=%p frame=%p newsp=%lx\n",
> regs, frame, newsp);
> #endif
> - force_sigsegv(sig, current);
> + return 0;
> }
>
> static long do_setcontext32(struct ucontext32 __user *ucp, struct pt_regs *regs, int sig)
> @@ -822,7 +822,7 @@
> /*
> * OK, we're invoking a handler
> */
> -static void handle_signal32(unsigned long sig, struct k_sigaction *ka,
> +static int handle_signal32(unsigned long sig, struct k_sigaction *ka,
> siginfo_t *info, sigset_t *oldset,
> struct pt_regs * regs, unsigned long newsp)
> {
> @@ -867,14 +867,14 @@
> regs->trap = 0;
> regs->result = 0;
>
> - return;
> + return 1;
>
> badframe:
> #if DEBUG_SIG
> printk("badframe in handle_signal, regs=%p frame=%x newsp=%x\n",
> regs, frame, *newspp);
> #endif
> - force_sigsegv(sig, current);
> + return 0;
> }
>
> /*
> @@ -984,11 +984,20 @@
>
> /* Whee! Actually deliver the signal. */
> if (ka.sa.sa_flags & SA_SIGINFO)
> - handle_rt_signal32(signr, &ka, &info, oldset, regs, newsp);
> + ret = handle_rt_signal32(signr, &ka, &info, oldset, regs, newsp);
> else
> - handle_signal32(signr, &ka, &info, oldset, regs, newsp);
> + ret = handle_signal32(signr, &ka, &info, oldset, regs, newsp);
>
> - if (!(ka.sa.sa_flags & SA_NODEFER)) {
> + if (!ret) {
> + /* Setting up the stack frame failed, but if we came here
> + from sigsuspend we may already have masked signals.
> + Put back the old sigmask before forcing SEGV. */
> + spin_lock_irq(¤t->sighand->siglock);
> + current->blocked = *oldset;
> + recalc_sigpending();
> + spin_unlock_irq(¤t->sighand->siglock);
> + force_sigsegv(signr, current);
> + } else if (!(ka.sa.sa_flags & SA_NODEFER)) {
> spin_lock_irq(¤t->sighand->siglock);
> sigorsets(¤t->blocked, ¤t->blocked,
> &ka.sa.sa_mask);
next prev parent reply other threads:[~2004-12-02 9:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200411130201.iAD210pT005889@ccure.user-mode-linux.org>
2004-11-13 0:34 ` [PATCH 9/11] - UML - fix signal mask on delivery error Andrew Morton
2004-11-14 22:13 ` Jeff Dike
2004-11-15 8:35 ` David Woodhouse
2004-11-22 15:30 ` David Woodhouse
2004-11-15 11:40 ` Bodo Stroesser
2004-11-15 17:18 ` Jeff Dike
2004-11-16 9:39 ` Bodo Stroesser
2004-11-30 14:59 ` David Woodhouse
2004-12-02 9:55 ` Bodo Stroesser [this message]
2004-12-02 11:25 ` Paul Mackerras
2004-12-02 11:40 ` Bodo Stroesser
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=41AEE6A1.4020200@fujitsu-siemens.com \
--to=bstroesser@fujitsu-siemens.com \
--cc=akpm@osdl.org \
--cc=blaisorblade_spam@yahoo.it \
--cc=dwmw2@infradead.org \
--cc=jdike@addtoit.com \
--cc=jdike@ccure.user-mode-linux.org \
--cc=linux-arch@vger.kernel.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