2009-03-29 11:54:20

by Mikael Pettersson

[permalink] [raw]
Subject: can get_signal_to_deliver() clobber current's _RESTORE_SIGMASK flag?

In all archs that support _RESTORE_SIGMASK do_signal() queries the
thread flags and sets up oldset before calling get_signal_to_deliver(),
but oldset is then only used in the "if (signr > 0)" block.

Would it be safe to move the threads flags query past the
get_signal_to_deliver() call into the "if (signr > 0)" block?
To illustrate, here's how it would look on x86:

--- linux-2.6.29/arch/x86/kernel/signal.c.~1~ 2009-03-24 18:00:34.000000000 +0100
+++ linux-2.6.29/arch/x86/kernel/signal.c 2009-03-29 10:36:02.000000000 +0200
@@ -802,7 +802,6 @@ static void do_signal(struct pt_regs *re
struct k_sigaction ka;
siginfo_t info;
int signr;
- sigset_t *oldset;

/*
* We want the common case to go fast, which is why we may in certain
@@ -814,13 +813,15 @@ static void do_signal(struct pt_regs *re
if (!user_mode(regs))
return;

- if (current_thread_info()->status & TS_RESTORE_SIGMASK)
- oldset = &current->saved_sigmask;
- else
- oldset = &current->blocked;
-
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
if (signr > 0) {
+ sigset_t *oldset;
+
+ if (current_thread_info()->status & TS_RESTORE_SIGMASK)
+ oldset = &current->saved_sigmask;
+ else
+ oldset = &current->blocked;
+
/*
* Re-enable any watchpoints before delivering the
* signal to user space. The processor register will


The background is that I've been working on _RESTORE_SIGMASK
support for ARM in order to enable pselect6/ppoll/epoll_pwait.
It's working but as a cleanup rmk wanted the oldset setup code to
be moved into the "if (signr > 0)" block. But that's only safe if
get_signal_to_deliver() cannot clobber current's _RESTORE_SIGMASK.

/Mikael