Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp564095imm; Thu, 26 Jul 2018 08:14:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeEvQ9qm+nSVy+Z1zXgxDHTyeF1L/suzuSCHHDOypVHuFfTqznVNkOxw+gLowuPYM5rzKRl X-Received: by 2002:a63:d5b:: with SMTP id 27-v6mr2317858pgn.107.1532618080454; Thu, 26 Jul 2018 08:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532618080; cv=none; d=google.com; s=arc-20160816; b=cY2LEHKF0fwbbhs4c5GiMrGdPtry9rwh7aO5whxFUFqPqr/E4L2jQelZ0OrwRvnZ36 BCl4zPCUfZpbbfV9l5TfDiXI97oH6cr0SIVyRDySebfyoxeHsYnT+lDVz4jBrKWHuG6E 4D2XVcSY6sYZF/38liFLikMeEXVeHWroszm2TL7I9yG/V/SXnYzz0XMQ7p/ni3HUSNYC J1PJo5MVZFpjMhGUrF8vx7uOcd34UY+PuzzkXRltTbNtdVum11YyhXZ+GAzZB+t5v+gV I9soQ2x2eQPIQgGtXIe/ZtlOUx5VC0JYen+YGmR46iUgNL80fzVfNrEDg5NZliBjvzTp URlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from :arc-authentication-results; bh=/cajqdvdjOUHeUiQhLktShi7/klxBQVS+xvMqU2ZrNo=; b=PjBH9q3aN10zhC+UYlS/rcG8sQRCLfQyP31oUJkz8RZ6+t/qCgQGPI8nY4l6uu87lx 7KwCT5Kq7JNwNqBSEuAAQwSKDxieD4Rb4g8Yp5JHVnR0I/iRPfQvgTC/lBOa9GAsBl/w NPiFHxo07FQ6kup6FBRjVn2/xiPy9PROOnjxVCgzLZzHezADxQPYD6NfwJB7zlKVdPK5 Mxt3f1/hSJdHf4oINjAgAmbh0keIQmPp/DVBCRBsZLzdBECkBz37K64sKjNqcWM0TQCP ZpMe+K6fGrSXqy/Nfj5WZsfHMKpF4/LjlugzSaB+rsEibTNc3cAksolGfktuPuhUqwuA BQfg== 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 s12-v6si1345826plp.371.2018.07.26.08.14.25; Thu, 26 Jul 2018 08:14:40 -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 S1731696AbeGZQah (ORCPT + 99 others); Thu, 26 Jul 2018 12:30:37 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:42861 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729801AbeGZQah (ORCPT ); Thu, 26 Jul 2018 12:30:37 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fihx9-0002DJ-0r; Thu, 26 Jul 2018 09:13:19 -0600 Received: from [97.119.167.31] (helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fihx6-0004LP-N4; Thu, 26 Jul 2018 09:13:18 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Oleg Nesterov Cc: Linus Torvalds , Andrew Morton , linux-kernel@vger.kernel.org, Wen Yang , majiang References: <87efft5ncd.fsf_-_@xmission.com> <20180724032419.20231-18-ebiederm@xmission.com> <20180726132050.GA32718@redhat.com> Date: Thu, 26 Jul 2018 10:13:12 -0500 In-Reply-To: <20180726132050.GA32718@redhat.com> (Oleg Nesterov's message of "Thu, 26 Jul 2018 15:20:50 +0200") Message-ID: <87tvom58tz.fsf@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1fihx6-0004LP-N4;;;mid=<87tvom58tz.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.119.167.31;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18vq8n2SkROnH8GMyJYcQe3gHaVwE/Wdnc= X-SA-Exim-Connect-IP: 97.119.167.31 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on sa03.xmission.com X-Spam-Level: * X-Spam-Status: No, score=1.3 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01,T_TooManySym_02, T_TooManySym_03,XMNoVowels autolearn=disabled version=3.4.0 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa03 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 1935 ms - load_scoreonly_sql: 0.10 (0.0%), signal_user_changed: 3.8 (0.2%), b_tie_ro: 2.5 (0.1%), parse: 1.44 (0.1%), extract_message_metadata: 6 (0.3%), get_uri_detail_list: 2.5 (0.1%), tests_pri_-1000: 23 (1.2%), tests_pri_-950: 2.4 (0.1%), tests_pri_-900: 1.90 (0.1%), tests_pri_-400: 141 (7.3%), check_bayes: 136 (7.0%), b_tokenize: 39 (2.0%), b_tok_get_all: 30 (1.5%), b_comp_prob: 14 (0.7%), b_tok_touch_all: 25 (1.3%), b_finish: 1.65 (0.1%), tests_pri_0: 1637 (84.6%), check_dkim_signature: 1.44 (0.1%), check_dkim_adsp: 38 (2.0%), tests_pri_500: 46 (2.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 18/20] signal: Add calculate_sigpending() 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 in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Oleg Nesterov writes: > On 07/23, Eric W. Biederman wrote: >> >> --- a/kernel/fork.c >> +++ b/kernel/fork.c >> @@ -1988,6 +1988,7 @@ static __latent_entropy struct task_struct *copy_process( >> &p->signal->thread_head); >> } >> attach_pid(p, PIDTYPE_PID); >> + calculate_sigpending(p); > > In theory this looks racy if !CLONE_SIGHAND, please see below > >> +void calculate_sigpending(struct task_struct *new) >> +{ >> + /* Have any signals or users of TIF_SIGPENDING been delayed >> + * until after fork? >> + */ >> + bool pending = (new->jobctl & JOBCTL_PENDING_MASK) || >> + PENDING(&new->pending, &new->blocked) || >> + PENDING(&new->signal->shared_pending, &new->blocked) || >> + freezing(new) || klp_patch_pending(new); > > note that we do not hold new->sighand->siglock, but this "new" task is already > visible to find_task_by_vpid/etc; so a new signal can come right after > this check, Good point. The localtion of the call to calculate_sigpending is wrong. >> + update_tsk_thread_flag(new, TIF_SIGPENDING, pending); > > and then update_tsk_thread_flag() can wrongly clear TIF_SIGPENDING. > > Easy to fix, but perhaps we can simply add recalc_sigpending() into > schedule_tail() ? It already does more than just finish_task_switch/etc. > > This way we do not need the new helper (which btw can only be used by > copy_process). The problem I have with reusing recalc_sigpending is that it does not set TIF_SIGPENDING if (freezing || klp_patch_pending). There is obviously synergy between these two cases, I just have not figured out how to take advantage of it yet. > Note also that either way you can remove set_tsk_thread_flag(TIF_SIGPENDING) > from ptrace_init_task(). Interesting. Yes we can remove TIF_SIGPENDING from that case because ptrace_init_task sets jobctl or queues a pending signal. I like that synergy. I like not being able to miss setting TIF_SIGPENDING during fork. Eric