Skip to content

Commit 71fabd5

Browse files
George AnzingerLinus Torvalds
authored andcommitted
[PATCH] sigaction should clear all signals on SIG_IGN, not just < 32
While rooting aroung in the signal code trying to understand how to fix the SIG_IGN ploy (set sig handler to SIG_IGN and flood system with high speed repeating timers) I came across what, I think, is a problem in sigaction() in that when processing a SIG_IGN request it flushes signals from 1 to SIGRTMIN and leaves the rest. Attempt to fix this. Signed-off-by: George Anzinger <george@mvista.com> Cc: Roland McGrath <roland@redhat.com> Cc: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent b5f545c commit 71fabd5

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

‎include/linux/signal.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ static inline int sigfindinword(unsigned long word)
9494

9595
#endif /* __HAVE_ARCH_SIG_BITOPS */
9696

97+
static inline int sigisemptyset(sigset_t *set)
98+
{
99+
extern void _NSIG_WORDS_is_unsupported_size(void);
100+
switch (_NSIG_WORDS) {
101+
case 4:
102+
return (set->sig[3] | set->sig[2] |
103+
set->sig[1] | set->sig[0]) == 0;
104+
case 2:
105+
return (set->sig[1] | set->sig[0]) == 0;
106+
case 1:
107+
return set->sig[0] == 0;
108+
default:
109+
_NSIG_WORDS_is_unsupported_size();
110+
return 0;
111+
}
112+
}
113+
97114
#define sigmask(sig) (1UL << ((sig) - 1))
98115

99116
#ifndef __HAVE_ARCH_SIG_SETOPS

‎kernel/signal.c‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,33 @@ void signal_wake_up(struct task_struct *t, int resume)
620620
kick_process(t);
621621
}
622622

623+
/*
624+
* Remove signals in mask from the pending set and queue.
625+
* Returns 1 if any signals were found.
626+
*
627+
* All callers must be holding the siglock.
628+
*
629+
* This version takes a sigset mask and looks at all signals,
630+
* not just those in the first mask word.
631+
*/
632+
static int rm_from_queue_full(sigset_t *mask, struct sigpending *s)
633+
{
634+
struct sigqueue *q, *n;
635+
sigset_t m;
636+
637+
sigandsets(&m, mask, &s->signal);
638+
if (sigisemptyset(&m))
639+
return 0;
640+
641+
signandsets(&s->signal, &s->signal, mask);
642+
list_for_each_entry_safe(q, n, &s->list, list) {
643+
if (sigismember(mask, q->info.si_signo)) {
644+
list_del_init(&q->list);
645+
__sigqueue_free(q);
646+
}
647+
}
648+
return 1;
649+
}
623650
/*
624651
* Remove signals in mask from the pending set and queue.
625652
* Returns 1 if any signals were found.
@@ -2408,6 +2435,7 @@ int
24082435
do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact)
24092436
{
24102437
struct k_sigaction *k;
2438+
sigset_t mask;
24112439

24122440
if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
24132441
return -EINVAL;
@@ -2455,9 +2483,11 @@ do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact)
24552483
*k = *act;
24562484
sigdelsetmask(&k->sa.sa_mask,
24572485
sigmask(SIGKILL) | sigmask(SIGSTOP));
2458-
rm_from_queue(sigmask(sig), &t->signal->shared_pending);
2486+
sigemptyset(&mask);
2487+
sigaddset(&mask, sig);
2488+
rm_from_queue_full(&mask, &t->signal->shared_pending);
24592489
do {
2460-
rm_from_queue(sigmask(sig), &t->pending);
2490+
rm_from_queue_full(&mask, &t->pending);
24612491
recalc_sigpending_tsk(t);
24622492
t = next_thread(t);
24632493
} while (t != current);

0 commit comments

Comments
 (0)