Эх сурвалжийг харах

Make sure SIGKILL gets proper respect

Bhavesh P. Davda <bhavesh@avaya.com> noticed that SIGKILL wouldn't
properly kill a process under just the right cicumstances: a stopped
task that already had another signal queued would get the SIGKILL
queued onto the shared queue, and there it would remain until SIGCONT.

This simplifies the signal acceptance logic, and fixes the bug in the
process.

Losely based on an earlier patch by Bhavesh.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Linus Torvalds 20 жил өмнө
parent
commit
188a1eafa0
1 өөрчлөгдсөн 14 нэмэгдсэн , 17 устгасан
  1. 14 17
      kernel/signal.c

+ 14 - 17
kernel/signal.c

@@ -936,34 +936,31 @@ force_sig_specific(int sig, struct task_struct *t)
  * as soon as they're available, so putting the signal on the shared queue
  * as soon as they're available, so putting the signal on the shared queue
  * will be equivalent to sending it to one such thread.
  * will be equivalent to sending it to one such thread.
  */
  */
-#define wants_signal(sig, p, mask) 			\
-	(!sigismember(&(p)->blocked, sig)		\
-	 && !((p)->state & mask)			\
-	 && !((p)->flags & PF_EXITING)			\
-	 && (task_curr(p) || !signal_pending(p)))
-
+static inline int wants_signal(int sig, struct task_struct *p)
+{
+	if (sigismember(&p->blocked, sig))
+		return 0;
+	if (p->flags & PF_EXITING)
+		return 0;
+	if (sig == SIGKILL)
+		return 1;
+	if (p->state & (TASK_STOPPED | TASK_TRACED))
+		return 0;
+	return task_curr(p) || !signal_pending(p);
+}
 
 
 static void
 static void
 __group_complete_signal(int sig, struct task_struct *p)
 __group_complete_signal(int sig, struct task_struct *p)
 {
 {
-	unsigned int mask;
 	struct task_struct *t;
 	struct task_struct *t;
 
 
-	/*
-	 * Don't bother traced and stopped tasks (but
-	 * SIGKILL will punch through that).
-	 */
-	mask = TASK_STOPPED | TASK_TRACED;
-	if (sig == SIGKILL)
-		mask = 0;
-
 	/*
 	/*
 	 * Now find a thread we can wake up to take the signal off the queue.
 	 * Now find a thread we can wake up to take the signal off the queue.
 	 *
 	 *
 	 * If the main thread wants the signal, it gets first crack.
 	 * If the main thread wants the signal, it gets first crack.
 	 * Probably the least surprising to the average bear.
 	 * Probably the least surprising to the average bear.
 	 */
 	 */
-	if (wants_signal(sig, p, mask))
+	if (wants_signal(sig, p))
 		t = p;
 		t = p;
 	else if (thread_group_empty(p))
 	else if (thread_group_empty(p))
 		/*
 		/*
@@ -981,7 +978,7 @@ __group_complete_signal(int sig, struct task_struct *p)
 			t = p->signal->curr_target = p;
 			t = p->signal->curr_target = p;
 		BUG_ON(t->tgid != p->tgid);
 		BUG_ON(t->tgid != p->tgid);
 
 
-		while (!wants_signal(sig, t, mask)) {
+		while (!wants_signal(sig, t)) {
 			t = next_thread(t);
 			t = next_thread(t);
 			if (t == p->signal->curr_target)
 			if (t == p->signal->curr_target)
 				/*
 				/*