diff --git a/fs/exec.c b/fs/exec.c index 007d0d814bf01953d5b780a35056f571ceb568dc..2c942e2d14ea2b3ebf2fb51bcf692e3a37565ae5 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -841,8 +841,8 @@ static int de_thread(struct task_struct *tsk) */ tsk->start_time = leader->start_time; - BUG_ON(leader->tgid != tsk->tgid); - BUG_ON(tsk->pid == tsk->tgid); + BUG_ON(!same_thread_group(leader, tsk)); + BUG_ON(has_group_leader_pid(tsk)); /* * An exec() starts a new thread group with the * TGID of the previous thread group. Rehash the diff --git a/fs/proc/base.c b/fs/proc/base.c index db7636041c107bd787ac281416c013abf0f85f53..991482811f1e7ecd8b9bc91abc4eace6fc2491d6 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2553,7 +2553,7 @@ static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry rcu_read_unlock(); if (!task) goto out; - if (leader->tgid != task->tgid) + if (!same_thread_group(leader, task)) goto out_drop_task; result = proc_task_instantiate(dir, dentry, task, NULL); diff --git a/include/linux/sched.h b/include/linux/sched.h index f4d969e85612e16307c95bc93f7cb148e8144b5d..eb2ae68804aad750afdbd02d787ea87c6a1b1ca9 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1725,6 +1725,12 @@ static inline int has_group_leader_pid(struct task_struct *p) return p->pid == p->tgid; } +static inline +int same_thread_group(struct task_struct *p1, struct task_struct *p2) +{ + return p1->tgid == p2->tgid; +} + static inline struct task_struct *next_thread(const struct task_struct *p) { return list_entry(rcu_dereference(p->thread_group.next), diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index b53c8fcd9d82d25044867c9529a17f9b1fdb00f8..68c96376e84a6078da9c07d6ebfc2b1c64a3e2a7 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c @@ -21,8 +21,8 @@ static int check_clock(const clockid_t which_clock) read_lock(&tasklist_lock); p = find_task_by_pid(pid); - if (!p || (CPUCLOCK_PERTHREAD(which_clock) ? - p->tgid != current->tgid : p->tgid != pid)) { + if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ? + same_thread_group(p, current) : thread_group_leader(p))) { error = -EINVAL; } read_unlock(&tasklist_lock); @@ -308,13 +308,13 @@ int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp) p = find_task_by_pid(pid); if (p) { if (CPUCLOCK_PERTHREAD(which_clock)) { - if (p->tgid == current->tgid) { + if (same_thread_group(p, current)) { error = cpu_clock_sample(which_clock, p, &rtn); } } else { read_lock(&tasklist_lock); - if (p->tgid == pid && p->signal) { + if (thread_group_leader(p) && p->signal) { error = cpu_clock_sample_group(which_clock, p, &rtn); @@ -355,7 +355,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer) p = current; } else { p = find_task_by_pid(pid); - if (p && p->tgid != current->tgid) + if (p && !same_thread_group(p, current)) p = NULL; } } else { @@ -363,7 +363,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer) p = current->group_leader; } else { p = find_task_by_pid(pid); - if (p && p->tgid != pid) + if (p && !thread_group_leader(p)) p = NULL; } } diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c index d11f579d189a1b75f753addcdfba961f7561b74b..35b4bbfc78ff6ee7d3f389baf0430231ed09af7b 100644 --- a/kernel/posix-timers.c +++ b/kernel/posix-timers.c @@ -404,7 +404,7 @@ static struct task_struct * good_sigevent(sigevent_t * event) if ((event->sigev_notify & SIGEV_THREAD_ID ) && (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) || - rtn->tgid != current->tgid || + !same_thread_group(rtn, current) || (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL)) return NULL; @@ -608,7 +608,7 @@ static struct k_itimer * lock_timer(timer_t timer_id, unsigned long *flags) spin_lock(&timr->it_lock); if ((timr->it_id != timer_id) || !(timr->it_process) || - timr->it_process->tgid != current->tgid) { + !same_thread_group(timr->it_process, current)) { spin_unlock(&timr->it_lock); spin_unlock_irqrestore(&idr_lock, *flags); timr = NULL; diff --git a/kernel/ptrace.c b/kernel/ptrace.c index b0ace60ce596c9b41ed3e397de35b05fd6b535e7..7c76f2ffaeaad78060cfb3223857a89c7a4ccb8f 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -169,7 +169,7 @@ int ptrace_attach(struct task_struct *task) retval = -EPERM; if (task->pid <= 1) goto out; - if (task->tgid == current->tgid) + if (same_thread_group(task, current)) goto out; repeat: diff --git a/kernel/signal.c b/kernel/signal.c index 783b33a0af06d43cb7f27bafb39cee66c5d2fb87..08364e75bb589534e86b041887fd1832c70b4a36 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1150,7 +1150,7 @@ static int kill_something_info(int sig, struct siginfo *info, int pid) read_lock(&tasklist_lock); for_each_process(p) { - if (p->pid > 1 && p->tgid != current->tgid) { + if (p->pid > 1 && !same_thread_group(p, current)) { int err = group_send_sig_info(sig, info, p); ++count; if (err != -EPERM) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index a7cb4c43fd11dd33e03cf3c0e9dcf778811d3df9..e3778f1215c085e68d985858701b83acdb725b86 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -326,7 +326,7 @@ static int oom_kill_task(struct task_struct *p) * to memory reserves though, otherwise we might deplete all memory. */ do_each_thread(g, q) { - if (q->mm == mm && q->tgid != p->tgid) + if (q->mm == mm && !same_thread_group(q, p)) force_sig(SIGKILL, q); } while_each_thread(g, q);