History

recalc_sigpending_tsk fixes

Steve Hawkes discovered a problem where recalc_sigpending_tsk was called in do_sigaction but no signal_wake_up call was made, preventing later signals from waking up blocked threads with TIF_SIGPENDING already set. In fact, the few other calls to recalc_sigpending_tsk outside the signals code are also subject to this problem in other race conditions. This change makes recalc_sigpending_tsk private to the signals code. It changes the outside calls, as well as do_sigaction, to use the new recalc_sigpending_and_wake instead.

Roland McGrath committed 19 years ago

Commit 7bb44ad1 parent 3c6df2a4 files · +28 −17Browse files

Unified · Split

4 files
  1. include/linux/sched.h +7 −5
  2. kernel/exit.c +2 −5
  3. kernel/power/process.c +1 −1
  4. kernel/signal.c +18 −6
include/linux/sched.h+7−5
@@ -1616,11 +1616,13 @@ static inline int lock_need_resched(spinlock_t *lock) · 1615 unmodified lines
16161616 return 0;
16171617 }
16181618
1619−/* Reevaluate whether the task has signals pending delivery.
1620− This is required every time the blocked sigset_t changes.
1621− callers must hold sighand->siglock. */
1622−
1623−extern FASTCALL(void recalc_sigpending_tsk(struct task_struct *t));
1619+/*
1620+ * Reevaluate whether the task has signals pending delivery.
1621+ * Wake the task if so.
1622+ * This is required every time the blocked sigset_t changes.
1623+ * callers must hold sighand->siglock.
1624+ */
1625+extern void recalc_sigpending_and_wake(struct task_struct *t);
16241626 extern void recalc_sigpending(void);
16251627
16261628 extern void signal_wake_up(struct task_struct *t, int resume_stopped);
kernel/exit.c+2−5
@@ -762,11 +762,8 @@ static void exit_notify(struct task_struct *tsk) · 761 unmodified lines
762762 read_lock(&tasklist_lock);
763763 spin_lock_irq(&tsk->sighand->siglock);
764764 for (t = next_thread(tsk); t != tsk; t = next_thread(t))
765− if (!signal_pending(t) && !(t->flags & PF_EXITING)) {
766− recalc_sigpending_tsk(t);
767− if (signal_pending(t))
768− signal_wake_up(t, 0);
769− }
765+ if (!signal_pending(t) && !(t->flags & PF_EXITING))
766+ recalc_sigpending_and_wake(t);
770767 spin_unlock_irq(&tsk->sighand->siglock);
771768 read_unlock(&tasklist_lock);
772769 }
kernel/power/process.c+1−1
@@ -101,7 +101,7 @@ static void cancel_freezing(struct task_struct *p) · 100 unmodified lines
101101 pr_debug(" clean up: %s\n", p->comm);
102102 do_not_freeze(p);
103103 spin_lock_irqsave(&p->sighand->siglock, flags);
104− recalc_sigpending_tsk(p);
104+ recalc_sigpending_and_wake(p);
105105 spin_unlock_irqrestore(&p->sighand->siglock, flags);
106106 }
107107 }
kernel/signal.c+18−6
@@ -96,15 +96,27 @@ static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked) · 95 unmodified lines
9696
9797 #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
9898
99−fastcall void recalc_sigpending_tsk(struct task_struct *t)
99+static int recalc_sigpending_tsk(struct task_struct *t)
100100 {
101101 if (t->signal->group_stop_count > 0 ||
102102 (freezing(t)) ||
103103 PENDING(&t->pending, &t->blocked) ||
104− PENDING(&t->signal->shared_pending, &t->blocked))
104+ PENDING(&t->signal->shared_pending, &t->blocked)) {
105105 set_tsk_thread_flag(t, TIF_SIGPENDING);
106− else
107− clear_tsk_thread_flag(t, TIF_SIGPENDING);
106+ return 1;
107+ }
108+ clear_tsk_thread_flag(t, TIF_SIGPENDING);
109+ return 0;
110+}
111+
112+/*
113+ * After recalculating TIF_SIGPENDING, we need to make sure the task wakes up.
114+ * This is superfluous when called on current, the wakeup is a harmless no-op.
115+ */
116+void recalc_sigpending_and_wake(struct task_struct *t)
117+{
118+ if (recalc_sigpending_tsk(t))
119+ signal_wake_up(t, 0);
108120 }
109121
110122 void recalc_sigpending(void)
@@ -744,7 +756,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t) · 633 unmodified lines
744756 action->sa.sa_handler = SIG_DFL;
745757 if (blocked) {
746758 sigdelset(&t->blocked, sig);
747− recalc_sigpending_tsk(t);
759+ recalc_sigpending_and_wake(t);
748760 }
749761 }
750762 ret = specific_send_sig_info(sig, info, t);
@@ -2273,7 +2285,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) · 1522 unmodified lines
22732285 rm_from_queue_full(&mask, &t->signal->shared_pending);
22742286 do {
22752287 rm_from_queue_full(&mask, &t->pending);
2276− recalc_sigpending_tsk(t);
2288+ recalc_sigpending_and_wake(t);
22772289 t = next_thread(t);
22782290 } while (t != current);
22792291 }