Commit 71fabd5e authored by George Anzinger's avatar George Anzinger Committed by Linus Torvalds

[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: default avatarGeorge Anzinger <george@mvista.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: default avatarAdrian Bunk <bunk@stusta.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b5f545c8
...@@ -94,6 +94,23 @@ static inline int sigfindinword(unsigned long word) ...@@ -94,6 +94,23 @@ static inline int sigfindinword(unsigned long word)
#endif /* __HAVE_ARCH_SIG_BITOPS */ #endif /* __HAVE_ARCH_SIG_BITOPS */
static inline int sigisemptyset(sigset_t *set)
{
extern void _NSIG_WORDS_is_unsupported_size(void);
switch (_NSIG_WORDS) {
case 4:
return (set->sig[3] | set->sig[2] |
set->sig[1] | set->sig[0]) == 0;
case 2:
return (set->sig[1] | set->sig[0]) == 0;
case 1:
return set->sig[0] == 0;
default:
_NSIG_WORDS_is_unsupported_size();
return 0;
}
}
#define sigmask(sig) (1UL << ((sig) - 1)) #define sigmask(sig) (1UL << ((sig) - 1))
#ifndef __HAVE_ARCH_SIG_SETOPS #ifndef __HAVE_ARCH_SIG_SETOPS
......
...@@ -620,6 +620,33 @@ void signal_wake_up(struct task_struct *t, int resume) ...@@ -620,6 +620,33 @@ void signal_wake_up(struct task_struct *t, int resume)
kick_process(t); kick_process(t);
} }
/*
* Remove signals in mask from the pending set and queue.
* Returns 1 if any signals were found.
*
* All callers must be holding the siglock.
*
* This version takes a sigset mask and looks at all signals,
* not just those in the first mask word.
*/
static int rm_from_queue_full(sigset_t *mask, struct sigpending *s)
{
struct sigqueue *q, *n;
sigset_t m;
sigandsets(&m, mask, &s->signal);
if (sigisemptyset(&m))
return 0;
signandsets(&s->signal, &s->signal, mask);
list_for_each_entry_safe(q, n, &s->list, list) {
if (sigismember(mask, q->info.si_signo)) {
list_del_init(&q->list);
__sigqueue_free(q);
}
}
return 1;
}
/* /*
* Remove signals in mask from the pending set and queue. * Remove signals in mask from the pending set and queue.
* Returns 1 if any signals were found. * Returns 1 if any signals were found.
...@@ -2408,6 +2435,7 @@ int ...@@ -2408,6 +2435,7 @@ int
do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact) do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact)
{ {
struct k_sigaction *k; struct k_sigaction *k;
sigset_t mask;
if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig))) if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
return -EINVAL; return -EINVAL;
...@@ -2455,9 +2483,11 @@ do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact) ...@@ -2455,9 +2483,11 @@ do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact)
*k = *act; *k = *act;
sigdelsetmask(&k->sa.sa_mask, sigdelsetmask(&k->sa.sa_mask,
sigmask(SIGKILL) | sigmask(SIGSTOP)); sigmask(SIGKILL) | sigmask(SIGSTOP));
rm_from_queue(sigmask(sig), &t->signal->shared_pending); sigemptyset(&mask);
sigaddset(&mask, sig);
rm_from_queue_full(&mask, &t->signal->shared_pending);
do { do {
rm_from_queue(sigmask(sig), &t->pending); rm_from_queue_full(&mask, &t->pending);
recalc_sigpending_tsk(t); recalc_sigpending_tsk(t);
t = next_thread(t); t = next_thread(t);
} while (t != current); } while (t != current);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment