Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6505289imm; Mon, 23 Jul 2018 20:27:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcIkZgyvrfvetopex0xuzMwfO3z1rRUx4Yhu7c0VDYQQbTGnT81+zZysiq4na2VjuYEVhy3 X-Received: by 2002:a17:902:8207:: with SMTP id x7-v6mr15098209pln.57.1532402834700; Mon, 23 Jul 2018 20:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532402834; cv=none; d=google.com; s=arc-20160816; b=YiiDJMTHjkCFMGirkTNL1eYNMWZzKmFv3whfQrZh1BGpCJ2uV44qxFh6OG2xT2VDEk Fg2kbtCwVQTdBQgKNj77UBR98VsTgNOcW5yLtFZbYzoP+BHg1sI04ZnA0d0E9FkUU9ts wZzW//fffHkpZetnJY0kc4y+j8AoGgDj+r/YK72qxBgLgDvlx0LenE+uBIfhtbISUwT3 E8DRyqHf+fX9L5mDu+27nvJNcprogvJQkFD1XecdxmFtyF6yVeYX40aTDFofr5G+uNxD uoOJ5IZCUr3P7bHuonPhaRm7yGV7Gyg9RsY12ox+mx7n5KUF/jDVkXsgjA+De9DirjnG x19w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=sB9Uplv10OPQ7DWMN2I8DwypRGdHwW0xXkfzHS8/uBI=; b=LmYWzknNCLXsk9d4UFbhkWzCrgGNmHjRtARwo805kzdFn9Q/lZ2sHW33r9ted+LaMM uUDVKcHBN1uw1au5M0N8flGGrVXV44A9Clcnjai3kINsyytJRsX7sBj9umrhvWaFfzdu agjiSU5U5mUWEv2GAoXKC7UX2s6GQkj95N7oTkaVj1UYO+voqaYXm5mxsnjhOHBI6T85 Renzx2FXwdcU0RBiou7bkpeKXzP6DgeK1OBjWlLJgLBxfkugy2lhzuM4CYZqsWzB0gM+ CORbjBjiGrJqIWMp1NTrAn+g8aqGKqHYj+VRfqc5YQ8VeF/TRrptLhSh79nNCEDhxO7s cmYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15-v6si10660031pfk.146.2018.07.23.20.27.00; Mon, 23 Jul 2018 20:27:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388387AbeGXEaH (ORCPT + 99 others); Tue, 24 Jul 2018 00:30:07 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:51292 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388244AbeGXEaG (ORCPT ); Tue, 24 Jul 2018 00:30:06 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fhnxL-0007Vg-BA; Mon, 23 Jul 2018 21:25:47 -0600 Received: from [97.119.167.31] (helo=x220.int.ebiederm.org) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fhnxK-0008AK-Kx; Mon, 23 Jul 2018 21:25:47 -0600 From: "Eric W. Biederman" To: Linus Torvalds Cc: Oleg Nesterov , Andrew Morton , linux-kernel@vger.kernel.org, Wen Yang , majiang , "Eric W. Biederman" Date: Mon, 23 Jul 2018 22:24:08 -0500 Message-Id: <20180724032419.20231-9-ebiederm@xmission.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <87efft5ncd.fsf_-_@xmission.com> References: <87efft5ncd.fsf_-_@xmission.com> X-XM-SPF: eid=1fhnxK-0008AK-Kx;;;mid=<20180724032419.20231-9-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.119.167.31;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18rwbuEXsWmvXYWFIqV4fDdBB26B/fp+Kg= X-SA-Exim-Connect-IP: 97.119.167.31 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa05.xmission.com X-Spam-Level: *** X-Spam-Status: No, score=3.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01,T_XMDrugObfuBody_04,XMNoVowels,XMSubLong autolearn=disabled version=3.4.1 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 1.0 T_XMDrugObfuBody_04 obfuscated drug references * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 312 ms - load_scoreonly_sql: 0.07 (0.0%), signal_user_changed: 4.0 (1.3%), b_tie_ro: 2.6 (0.8%), parse: 1.34 (0.4%), extract_message_metadata: 18 (5.8%), get_uri_detail_list: 4.0 (1.3%), tests_pri_-1000: 8 (2.7%), tests_pri_-950: 1.65 (0.5%), tests_pri_-900: 1.38 (0.4%), tests_pri_-400: 29 (9.2%), check_bayes: 27 (8.8%), b_tokenize: 12 (3.9%), b_tok_get_all: 7 (2.3%), b_comp_prob: 2.6 (0.8%), b_tok_touch_all: 3.0 (1.0%), b_finish: 0.72 (0.2%), tests_pri_0: 238 (76.1%), check_dkim_signature: 0.60 (0.2%), check_dkim_adsp: 3.1 (1.0%), tests_pri_500: 6 (2.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 09/20] signal: Pass pid and pid type into send_sigqueue X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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" --- include/linux/sched/signal.h | 2 +- kernel/signal.c | 14 +++++++++----- kernel/time/posix-timers.c | 13 ++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index ee30a5ba475f..94558ffa82ab 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -330,7 +330,7 @@ extern int send_sig(int, struct task_struct *, int); extern int zap_other_threads(struct task_struct *p); extern struct sigqueue *sigqueue_alloc(void); extern void sigqueue_free(struct sigqueue *); -extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group); +extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type); extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); static inline int restart_syscall(void) diff --git a/kernel/signal.c b/kernel/signal.c index 8d8a940422a8..40feb14e276d 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1664,17 +1664,20 @@ void sigqueue_free(struct sigqueue *q) __sigqueue_free(q); } -int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group) +int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type) { int sig = q->info.si_signo; struct sigpending *pending; + struct task_struct *t; unsigned long flags; int ret, result; BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); ret = -1; - if (!likely(lock_task_sighand(t, &flags))) + rcu_read_lock(); + t = pid_task(pid, type); + if (!t || !likely(lock_task_sighand(t, &flags))) goto ret; ret = 1; /* the signal is ignored */ @@ -1696,15 +1699,16 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group) q->info.si_overrun = 0; signalfd_notify(t, sig); - pending = group ? &t->signal->shared_pending : &t->pending; + pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending; list_add_tail(&q->list, &pending->list); sigaddset(&pending->signal, sig); - complete_signal(sig, t, group); + complete_signal(sig, t, type != PIDTYPE_PID); result = TRACE_SIGNAL_DELIVERED; out: - trace_signal_generate(sig, &q->info, t, group, result); + trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result); unlock_task_sighand(t, &flags); ret: + rcu_read_unlock(); return ret; } diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 2bdf08a2bae9..2d2e739fbc57 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -332,8 +332,8 @@ void posixtimer_rearm(struct siginfo *info) int posix_timer_event(struct k_itimer *timr, int si_private) { - struct task_struct *task; - int shared, ret = -1; + enum pid_type type; + int ret = -1; /* * FIXME: if ->sigq is queued we can race with * dequeue_signal()->posixtimer_rearm(). @@ -347,13 +347,8 @@ int posix_timer_event(struct k_itimer *timr, int si_private) */ timr->sigq->info.si_sys_private = si_private; - rcu_read_lock(); - task = pid_task(timr->it_pid, PIDTYPE_PID); - if (task) { - shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID); - ret = send_sigqueue(timr->sigq, task, shared); - } - rcu_read_unlock(); + type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID; + ret = send_sigqueue(timr->sigq, timr->it_pid, type); /* If we failed to send the signal the timer stops. */ return ret > 0; } -- 2.17.1