Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp987105imm; Wed, 11 Jul 2018 14:52:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcEemCk4DlYrMu7AqMkbV1b6OSA+UGpjgNKrChcDisG6OVQlz0FF3T6spi/+K3lKiWICef6 X-Received: by 2002:a63:4106:: with SMTP id o6-v6mr291092pga.453.1531345939268; Wed, 11 Jul 2018 14:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531345939; cv=none; d=google.com; s=arc-20160816; b=boYWPAcEbkBQejJtiweVDimrLdQyw/7XBW3+g1O4YcSwduX/7AFnOTjHPLV4+gQtOI 9b/uhrlZNLvFiXHYhtfs5p0uvz8dMTtKgvWzGa8BM4e7E5iPZL5PkmCPCxRCeERHfnz9 tGhMSzpb0dY9+OHFrVxIkSnwI1KHUFuh6VCSkfTqLFbUl6uSdca68QZ8tEwOEsclIR9k M3GRMUVCCM1oMDilJxPtJHfRyGQdxssIGwP0syAW2n42luWNZobRPWZOPaq8cHxtX48I O4Ye0L7UGZNrtrXcyY4YPCbVeIBqhS8gLjLa2iuEuOXomplHwq8IqRuBoEYyg68hT9z2 wjIw== 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=iojfs94nEUao5xblBL2rb9K2Iag58DnYrcLjLc7ca7A=; b=hZaKbwGyGk4pGHmXUTNdMmPc3VHAw3Mf1G5EU6zoWBAOQLCvpqpDL78HZKzCIFlFus 8NbrAWLd9b73B21mr8e0O9P3wLtz3He66hyv3tFkMloNe4GjzX/Sz5N8PKMKPeXVbUZM ixNSyoAA/vl1RbYO2kBdYMTAZTmsK/nuJOrJMR1lMxxbndlw9/TUaRESPgvJe/XpOOaT fMncnrSOq6M4zOf3k2OdioiHuuzUdtXon1/mAi5Nh7Gvu8REyyjCC58ffU1WAA/UfVBk OtMpVuPPqtpq7cFgN+zpJgjn4Gwx4iY275aVKZpJaGfkGy1Gl36QBNK2dbIJ1vt/0oAA PnLw== 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 n125-v6si19580833pga.376.2018.07.11.14.52.04; Wed, 11 Jul 2018 14:52:19 -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 S1733175AbeGKQHw (ORCPT + 99 others); Wed, 11 Jul 2018 12:07:52 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:57802 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726586AbeGKQHw (ORCPT ); Wed, 11 Jul 2018 12:07:52 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fdHZm-00024q-9p; Wed, 11 Jul 2018 10:02:49 -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 1fdHZY-0004DO-Tx; Wed, 11 Jul 2018 10:02:46 -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: <877em2jxyr.fsf_-_@xmission.com> <20180711024459.10654-11-ebiederm@xmission.com> <20180711141456.GA6636@redhat.com> Date: Wed, 11 Jul 2018 11:02:29 -0500 In-Reply-To: <20180711141456.GA6636@redhat.com> (Oleg Nesterov's message of "Wed, 11 Jul 2018 16:14:56 +0200") Message-ID: <87h8l5g3qi.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=1fdHZY-0004DO-Tx;;;mid=<87h8l5g3qi.fsf@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.119.167.31;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+VWnJJgPmrAD86VHWscAFru7CRdj/Vhds= 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 sa02.xmission.com X-Spam-Level: **** X-Spam-Status: No, score=4.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TR_Symld_Words,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_TooManySym_02,T_XMDrugObfuBody_04,XMNoVowels,XMSubLong 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.7 XMSubLong Long Subject * 1.5 TR_Symld_Words too many words that have symbols inside * 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 * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 1.0 T_XMDrugObfuBody_04 obfuscated drug references * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ****;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 10511 ms - load_scoreonly_sql: 0.09 (0.0%), signal_user_changed: 55 (0.5%), b_tie_ro: 49 (0.5%), parse: 1.58 (0.0%), extract_message_metadata: 86 (0.8%), get_uri_detail_list: 42 (0.4%), tests_pri_-1000: 92 (0.9%), tests_pri_-950: 43 (0.4%), tests_pri_-900: 42 (0.4%), tests_pri_-400: 363 (3.5%), check_bayes: 360 (3.4%), b_tokenize: 188 (1.8%), b_tok_get_all: 48 (0.5%), b_comp_prob: 38 (0.4%), b_tok_touch_all: 55 (0.5%), b_finish: 0.88 (0.0%), tests_pri_0: 9376 (89.2%), check_dkim_signature: 22 (0.2%), check_dkim_adsp: 80 (0.8%), tests_pri_500: 209 (2.0%), rewrite_mail: 0.00 (0.0%) Subject: Re: [RFC][PATCH 11/11] signal: Ignore all but multi-process signals that come in during fork. 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/10, Eric W. Biederman wrote: >> >> @@ -1602,6 +1603,20 @@ static __latent_entropy struct task_struct *copy_process( >> { >> int retval; >> struct task_struct *p; >> + unsigned seq; >> + >> + /* >> + * Signals that are delivered to multiple processes need to be >> + * delivered to just the parent before the fork or both the >> + * parent and the child after the fork. Cache the multiple >> + * process signal sequence number so we can detect any of >> + * these signals that happen during the fork. In the unlikely >> + * event a signal comes in while fork is starting and restart >> + * fork to handle the signal. >> + */ >> + seq = read_seqcount_begin(¤t->signal->multi_process_seq); >> + if (signal_pending(current)) >> + return ERR_PTR(-ERESTARTNOINTR); >> >> /* >> * Don't allow sharing the root directory with processes in a different >> @@ -1930,8 +1945,8 @@ static __latent_entropy struct task_struct *copy_process( >> * A fatal signal pending means that current will exit, so the new >> * thread can't slip out of an OOM kill (or normal SIGKILL). >> */ >> - recalc_sigpending(); >> - if (signal_pending(current)) { >> + if (read_seqcount_retry(¤t->signal->multi_process_seq, seq) || >> + fatal_signal_pending(current)) { >> retval = -ERESTARTNOINTR; >> goto bad_fork_cancel_cgroup; > > So once again, I think this is not right, see the discussion on > bugzilla. I am trying to dig through and understand your concerns. I am having difficulty understanding your concerns. Do the previous patches look good to you? Can we say that is a sufficient method to get the information about signals that are sent to multiple processes into __send_signal? > If signal_pending() == T we simply can't know if copy_process() can succeed or not. > I have already mentioned the races with stop/freeze, but I think there > are more. If I understand you correctly. Your concern is that since we added the: recalc_sigpending(); if (signal_pending(current)) return -ERESTARTNOINTR; Other (non-signal) code such as the freezer has come to depend upon that test. Changing the test in the proposed way will allow the new child to escape the freezer, as it is not guaranteed the new child will be frozen. It seems reasonable to look at other things that set TIF_SIGPENDING and see if any of them are broken by the fork changes. A quick look at exit_to_usermode_loop shows that TIF_SIGPENDING only triggers signal handling. In get_signal there is only task_work_run, try_to_freeze, and burried there is ptrace_stop. Plus there is restart_syscall() that sets TIF_SIGPENDING. Now that we aren't guaranteed that TIF_SIGPENDING is set before we restart, the code should be using "retval = restart_syscall();" I will fix that. I will dig in and see what attention those cases need in fork signal_pending behavior. I am hoping that it will be as simple as adding: /* Have the child return to userspace slowly * TIF_SIGPENDING was set during fork */ if (test_tsk_thread_flag(current, TIF_SIGPENDING)) set_tsk_thread_flag(p, TIF_SIGPENDING); > And in fact I think that the fact that signal_wake_up() helps to avoid the races > with fork() is useful. Say, we could add signal_wake_up() into syscall_regfunc() > and kill syscall_tracepoint_update(). Not that I think this particular change makes > any sense, but it can work. > > That is why I tried to sugest another approach. copy_process() should always fail > if signal_pending() == T, just the "real" signal should not disturb the forking > thread unless the signal is fatal or multi-process. So after seeing the report of periodic timers causing a 40ms fork to stretch into a 1000ms fork because of restarts, I am not a fan of cases where fork has to restart. 40ms is a lot of work to abandon. A practical (and fixable) problem with your patch was that you modified task->blocked which was then copied to the child. So all children now would start with all signals being blocked. > This also makes another difference in multi-threaded case, a signal with a handler > sent to a forking process will be re-targeted to another thread which can handle it; > with your patch this signal will be "blocked" until fork() finishes or until another > thread gets TIF_SIGPENDING. Not that I think this is that important, > but still. I would not object to wants_signal deciding that a task in the middle of copy_process does not want signals. Eric