Skip to content

Commit 24122c7

Browse files
committed
signal: Pass pid and pid type into send_sigqueue
Make the code more maintainable by performing more of the signal related work in send_sigqueue. A quick inspection of do_timer_create will show that this code path does not lookup a thread group by a thread's pid. Making it safe to find the task pointed to by it_pid with "pid_task(it_pid, type)"; This supports the changes needed in fork to tell if a signal was sent to a single process or a group of processes. Having the pid to task transition in signal.c will also make it easier to sort out races with de_thread and and the thread group leader exiting when it comes time to address that. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 2118e1f commit 24122c7

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

‎include/linux/sched/signal.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ extern int send_sig(int, struct task_struct *, int);
330330
extern int zap_other_threads(struct task_struct *p);
331331
extern struct sigqueue *sigqueue_alloc(void);
332332
extern void sigqueue_free(struct sigqueue *);
333-
extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
333+
extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type);
334334
extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
335335

336336
static inline int restart_syscall(void)

‎kernel/signal.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,17 +1664,20 @@ void sigqueue_free(struct sigqueue *q)
16641664
__sigqueue_free(q);
16651665
}
16661666

1667-
int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
1667+
int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type)
16681668
{
16691669
int sig = q->info.si_signo;
16701670
struct sigpending *pending;
1671+
struct task_struct *t;
16711672
unsigned long flags;
16721673
int ret, result;
16731674

16741675
BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
16751676

16761677
ret = -1;
1677-
if (!likely(lock_task_sighand(t, &flags)))
1678+
rcu_read_lock();
1679+
t = pid_task(pid, type);
1680+
if (!t || !likely(lock_task_sighand(t, &flags)))
16781681
goto ret;
16791682

16801683
ret = 1; /* the signal is ignored */
@@ -1696,15 +1699,16 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
16961699
q->info.si_overrun = 0;
16971700

16981701
signalfd_notify(t, sig);
1699-
pending = group ? &t->signal->shared_pending : &t->pending;
1702+
pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending;
17001703
list_add_tail(&q->list, &pending->list);
17011704
sigaddset(&pending->signal, sig);
1702-
complete_signal(sig, t, group);
1705+
complete_signal(sig, t, type != PIDTYPE_PID);
17031706
result = TRACE_SIGNAL_DELIVERED;
17041707
out:
1705-
trace_signal_generate(sig, &q->info, t, group, result);
1708+
trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result);
17061709
unlock_task_sighand(t, &flags);
17071710
ret:
1711+
rcu_read_unlock();
17081712
return ret;
17091713
}
17101714

‎kernel/time/posix-timers.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ void posixtimer_rearm(struct siginfo *info)
332332

333333
int posix_timer_event(struct k_itimer *timr, int si_private)
334334
{
335-
struct task_struct *task;
336-
int shared, ret = -1;
335+
enum pid_type type;
336+
int ret = -1;
337337
/*
338338
* FIXME: if ->sigq is queued we can race with
339339
* dequeue_signal()->posixtimer_rearm().
@@ -347,13 +347,8 @@ int posix_timer_event(struct k_itimer *timr, int si_private)
347347
*/
348348
timr->sigq->info.si_sys_private = si_private;
349349

350-
rcu_read_lock();
351-
task = pid_task(timr->it_pid, PIDTYPE_PID);
352-
if (task) {
353-
shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
354-
ret = send_sigqueue(timr->sigq, task, shared);
355-
}
356-
rcu_read_unlock();
350+
type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID;
351+
ret = send_sigqueue(timr->sigq, timr->it_pid, type);
357352
/* If we failed to send the signal the timer stops. */
358353
return ret > 0;
359354
}

0 commit comments

Comments
 (0)