Skip to content

Commit 86c47b7

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal
Pull third pile of signal handling patches from Al Viro: "This time it's mostly helpers and conversions to them; there's a lot of stuff remaining in the tree, but that'll either go in -rc2 (isolated bug fixes, ideally via arch maintainers' trees) or will sit there until the next cycle." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal: x86: get rid of calling do_notify_resume() when returning to kernel mode blackfin: check __get_user() return value whack-a-mole with TIF_FREEZE FRV: Optimise the system call exit path in entry.S [ver #2] FRV: Shrink TIF_WORK_MASK [ver #2] FRV: Prevent syscall exit tracing and notify_resume at end of kernel exceptions new helper: signal_delivered() powerpc: get rid of restore_sigmask() most of set_current_blocked() callers want SIGKILL/SIGSTOP removed from set set_restore_sigmask() is never called without SIGPENDING (and never should be) TIF_RESTORE_SIGMASK can be set only when TIF_SIGPENDING is set don't call try_to_freeze() from do_signal() pull clearing RESTORE_SIGMASK into block_sigmask() sh64: failure to build sigframe != signal without handler openrisc: tracehook_signal_handler() is supposed to be called on success new helper: sigmask_to_save() new helper: restore_saved_sigmask() new helpers: {clear,test,test_and_clear}_restore_sigmask() HAVE_RESTORE_SIGMASK is defined on all architectures now
2 parents 1193755 + 44fbbb3 commit 86c47b7

File tree

68 files changed

+482
-1091
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+482
-1091
lines changed

arch/alpha/kernel/signal.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ do_sigreturn(struct sigcontext __user *sc, struct pt_regs *regs,
226226
if (__get_user(set.sig[0], &sc->sc_mask))
227227
goto give_sigsegv;
228228

229-
sigdelsetmask(&set, ~_BLOCKABLE);
230229
set_current_blocked(&set);
231230

232231
if (restore_sigcontext(sc, regs, sw))
@@ -261,7 +260,6 @@ do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs,
261260
if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
262261
goto give_sigsegv;
263262

264-
sigdelsetmask(&set, ~_BLOCKABLE);
265263
set_current_blocked(&set);
266264

267265
if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw))
@@ -468,12 +466,9 @@ static inline void
468466
handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
469467
struct pt_regs * regs, struct switch_stack *sw)
470468
{
471-
sigset_t *oldset = &current->blocked;
469+
sigset_t *oldset = sigmask_to_save();
472470
int ret;
473471

474-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
475-
oldset = &current->saved_sigmask;
476-
477472
if (ka->sa.sa_flags & SA_SIGINFO)
478473
ret = setup_rt_frame(sig, ka, info, oldset, regs, sw);
479474
else
@@ -483,12 +478,7 @@ handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
483478
force_sigsegv(sig, current);
484479
return;
485480
}
486-
block_sigmask(ka, sig);
487-
/* A signal was successfully delivered, and the
488-
saved sigmask was stored on the signal frame,
489-
and will be restored by sigreturn. So we can
490-
simply clear the restore sigmask flag. */
491-
clear_thread_flag(TIF_RESTORE_SIGMASK);
481+
signal_delivered(sig, info, ka, regs, 0);
492482
}
493483

494484
static inline void
@@ -572,9 +562,7 @@ do_signal(struct pt_regs * regs, struct switch_stack * sw,
572562
}
573563

574564
/* If there's no signal to deliver, we just restore the saved mask. */
575-
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
576-
set_current_blocked(&current->saved_sigmask);
577-
565+
restore_saved_sigmask();
578566
if (single_stepping)
579567
ptrace_set_bpt(current); /* re-set breakpoint */
580568
}

arch/arm/kernel/signal.c

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#include "signal.h"
2424

25-
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26-
2725
/*
2826
* For ARM syscalls, we encode the syscall number into the instruction.
2927
*/
@@ -210,10 +208,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
210208
int err;
211209

212210
err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
213-
if (err == 0) {
214-
sigdelsetmask(&set, ~_BLOCKABLE);
211+
if (err == 0)
215212
set_current_blocked(&set);
216-
}
217213

218214
__get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
219215
__get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
@@ -528,13 +524,13 @@ setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
528524
/*
529525
* OK, we're invoking a handler
530526
*/
531-
static int
527+
static void
532528
handle_signal(unsigned long sig, struct k_sigaction *ka,
533-
siginfo_t *info, sigset_t *oldset,
534-
struct pt_regs * regs)
529+
siginfo_t *info, struct pt_regs *regs)
535530
{
536531
struct thread_info *thread = current_thread_info();
537532
struct task_struct *tsk = current;
533+
sigset_t *oldset = sigmask_to_save();
538534
int usig = sig;
539535
int ret;
540536

@@ -559,17 +555,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka,
559555

560556
if (ret != 0) {
561557
force_sigsegv(sig, tsk);
562-
return ret;
558+
return;
563559
}
564-
565-
/*
566-
* Block the signal if we were successful.
567-
*/
568-
block_sigmask(ka, sig);
569-
570-
tracehook_signal_handler(sig, info, ka, regs, 0);
571-
572-
return 0;
560+
signal_delivered(sig, info, ka, regs, 0);
573561
}
574562

575563
/*
@@ -617,8 +605,6 @@ static void do_signal(struct pt_regs *regs, int syscall)
617605
*/
618606
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
619607
if (signr > 0) {
620-
sigset_t *oldset;
621-
622608
/*
623609
* Depending on the signal settings we may need to revert the
624610
* decision to restart the system call. But skip this if a
@@ -635,20 +621,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
635621
clear_thread_flag(TIF_SYSCALL_RESTARTSYS);
636622
}
637623

638-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
639-
oldset = &current->saved_sigmask;
640-
else
641-
oldset = &current->blocked;
642-
if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
643-
/*
644-
* A signal was successfully delivered; the saved
645-
* sigmask will have been stored in the signal frame,
646-
* and will be restored by sigreturn, so we can simply
647-
* clear the TIF_RESTORE_SIGMASK flag.
648-
*/
649-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
650-
clear_thread_flag(TIF_RESTORE_SIGMASK);
651-
}
624+
handle_signal(signr, &ka, &info, regs);
652625
return;
653626
}
654627

@@ -663,11 +636,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
663636
set_thread_flag(TIF_SYSCALL_RESTARTSYS);
664637
}
665638

666-
/* If there's no signal to deliver, we just put the saved sigmask
667-
* back.
668-
*/
669-
if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
670-
set_current_blocked(&current->saved_sigmask);
639+
restore_saved_sigmask();
671640
}
672641

673642
asmlinkage void

arch/avr32/kernel/entry-avr32b.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ syscall_exit_work:
281281
ld.w r1, r0[TI_flags]
282282
rjmp 1b
283283

284-
2: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NOTIFY_RESUME
284+
2: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
285285
tst r1, r2
286286
breq 3f
287287
unmask_interrupts
@@ -587,7 +587,7 @@ fault_exit_work:
587587
ld.w r1, r0[TI_flags]
588588
rjmp fault_exit_work
589589

590-
1: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NOTIFY_RESUME
590+
1: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
591591
tst r1, r2
592592
breq 2f
593593
unmask_interrupts

arch/avr32/kernel/signal.c

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <asm/ucontext.h>
2323
#include <asm/syscalls.h>
2424

25-
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26-
2725
asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
2826
struct pt_regs *regs)
2927
{
@@ -89,7 +87,6 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
8987
if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
9088
goto badframe;
9189

92-
sigdelsetmask(&set, ~_BLOCKABLE);
9390
set_current_blocked(&set);
9491

9592
if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -224,38 +221,35 @@ static inline void setup_syscall_restart(struct pt_regs *regs)
224221

225222
static inline void
226223
handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
227-
sigset_t *oldset, struct pt_regs *regs, int syscall)
224+
struct pt_regs *regs, int syscall)
228225
{
229226
int ret;
230227

231228
/*
232229
* Set up the stack frame
233230
*/
234-
ret = setup_rt_frame(sig, ka, info, oldset, regs);
231+
ret = setup_rt_frame(sig, ka, info, sigmask_to_save(), regs);
235232

236233
/*
237234
* Check that the resulting registers are sane
238235
*/
239236
ret |= !valid_user_regs(regs);
240237

241-
if (ret != 0) {
242-
force_sigsegv(sig, current);
243-
return;
244-
}
245-
246238
/*
247239
* Block the signal if we were successful.
248240
*/
249-
block_sigmask(ka, sig);
250-
clear_thread_flag(TIF_RESTORE_SIGMASK);
241+
if (ret != 0)
242+
force_sigsegv(sig, current);
243+
else
244+
signal_delivered(sig, info, ka, regs, 0);
251245
}
252246

253247
/*
254248
* Note that 'init' is a special process: it doesn't get signals it
255249
* doesn't want to handle. Thus you cannot kill init even with a
256250
* SIGKILL even by mistake.
257251
*/
258-
int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
252+
static void do_signal(struct pt_regs *regs, int syscall)
259253
{
260254
siginfo_t info;
261255
int signr;
@@ -267,12 +261,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
267261
* without doing anything if so.
268262
*/
269263
if (!user_mode(regs))
270-
return 0;
271-
272-
if (test_thread_flag(TIF_RESTORE_SIGMASK))
273-
oldset = &current->saved_sigmask;
274-
else if (!oldset)
275-
oldset = &current->blocked;
264+
return;
276265

277266
signr = get_signal_to_deliver(&info, &ka, regs, NULL);
278267
if (syscall) {
@@ -297,15 +286,11 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
297286

298287
if (signr == 0) {
299288
/* No signal to deliver -- put the saved sigmask back */
300-
if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
301-
clear_thread_flag(TIF_RESTORE_SIGMASK);
302-
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
303-
}
304-
return 0;
289+
restore_saved_sigmask();
290+
return;
305291
}
306292

307-
handle_signal(signr, &ka, &info, oldset, regs, syscall);
308-
return 1;
293+
handle_signal(signr, &ka, &info, regs, syscall);
309294
}
310295

311296
asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti)
@@ -315,8 +300,8 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti)
315300
if ((sysreg_read(SR) & MODE_MASK) == MODE_SUPERVISOR)
316301
syscall = 1;
317302

318-
if (ti->flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
319-
do_signal(regs, &current->blocked, syscall);
303+
if (ti->flags & _TIF_SIGPENDING))
304+
do_signal(regs, syscall);
320305

321306
if (ti->flags & _TIF_NOTIFY_RESUME) {
322307
clear_thread_flag(TIF_NOTIFY_RESUME);

arch/blackfin/include/asm/thread_info.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static inline struct thread_info *current_thread_info(void)
100100
TIF_NEED_RESCHED */
101101
#define TIF_MEMDIE 4 /* is terminating due to OOM killer */
102102
#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
103-
#define TIF_FREEZE 6 /* is freezing for suspend */
104103
#define TIF_IRQ_SYNC 7 /* sync pipeline stage */
105104
#define TIF_NOTIFY_RESUME 8 /* callback before returning to user */
106105
#define TIF_SINGLESTEP 9
@@ -111,7 +110,6 @@ static inline struct thread_info *current_thread_info(void)
111110
#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
112111
#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
113112
#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
114-
#define _TIF_FREEZE (1<<TIF_FREEZE)
115113
#define _TIF_IRQ_SYNC (1<<TIF_IRQ_SYNC)
116114
#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
117115
#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)

0 commit comments

Comments
 (0)