Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1696252imm; Wed, 8 Aug 2018 23:58:15 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyb7JArBEZMggnDrZ1Wk++juyVnDQ75AyOgoSFdG+FfugTFByk+BDhBBXwiHTcFA7B+JrlP X-Received: by 2002:a65:62cd:: with SMTP id m13-v6mr920703pgv.280.1533797895713; Wed, 08 Aug 2018 23:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533797895; cv=none; d=google.com; s=arc-20160816; b=k870VgQSA435j4uDgNe3VSb8g4R3vM+6LM8BLCNX2VQWGQb4+0TfrrKtRFLdyXduNS c5UwNbYG3yaadL+YstdFImfpovS0azF3PTasbC0Ob/dzRHOw69AdlicJ5C5VcGXvafxU NFs0xkxE2CZtHOl51FmSZ1cRcNx72NBzIVXSkpoh+3QQ69NlRLGbue49lwLiTyPXxNYs 54MqUk3rqfOssykbgQg/cOgWSPMQrTk03Y3OdBPaawOJOAYfgGmfsfWAHR3gcLuNm1n4 W1cBUvsDBIZJX69KTrwNFNXTvA+60t52m/34r++Dhg4WajEv4q1yP1nIB/tctDat0fZX 245g== 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=QIIWjc+Aq2AjCDE0VvRDGZInwb2StaAfQGvN4jmaFW4=; b=GvTKYhACQMJGPw/KBxgKfVQY8TjIswP8KcB5qHoQsQ0yvQUJUPIXXeRfuQZ3CF4np3 ZT2f77GKxqdQUDe31xquS21Gh+YVxg9JOM7wtCBTgBbQ4IUahvBPdJ9zEe7+FsqT1+DL aDMTh3hS19FTpyYmeIWNbKAWzmTKOnGdx0eT4oKMGXuzvoyIEKq+KbNRswMbZ1+ZuGt/ scyyMFwLVGyucC2r4NlVLxE7QrbFG/Zko2A0RRzcC9vCagzJnonYZCxRytDRhTQ4jHPU oNZCm+e7dHMHvnVCDL9tW5rXSUe3cEGeOIy7ds2mleyxywRdJt0M1xt8ZUR+IybmfZCD 0XMg== 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 s29-v6si7024693pfj.43.2018.08.08.23.58.00; Wed, 08 Aug 2018 23:58:15 -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 S1727704AbeHIJUh (ORCPT + 99 others); Thu, 9 Aug 2018 05:20:37 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:43243 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbeHIJUg (ORCPT ); Thu, 9 Aug 2018 05:20:36 -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 1fnesh-0000qr-8m; Thu, 09 Aug 2018 00:57:11 -0600 Received: from [97.119.167.31] (helo=x220.int.ebiederm.org) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.87) (envelope-from ) id 1fnesR-00054s-TX; Thu, 09 Aug 2018 00:57:11 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , linux-kernel@vger.kernel.org, Wen Yang , majiang , Linus Torvalds , "Eric W. Biederman" Date: Thu, 9 Aug 2018 01:56:00 -0500 Message-Id: <20180809065605.32345-1-ebiederm@xmission.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <87wot0yqsx.fsf_-_@xmission.com> References: <87wot0yqsx.fsf_-_@xmission.com> X-XM-SPF: eid=1fnesR-00054s-TX;;;mid=<20180809065605.32345-1-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.119.167.31;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18pFr8yR3CgqsLeYlpMOtUQdqNJtGfNYDg= 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 sa07.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01,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 * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4951] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=38] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=38 X-Spam-Combo: ;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 15024 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 2.8 (0.0%), b_tie_ro: 1.95 (0.0%), parse: 0.84 (0.0%), extract_message_metadata: 11 (0.1%), get_uri_detail_list: 1.26 (0.0%), tests_pri_-1000: 2.7 (0.0%), tests_pri_-950: 1.14 (0.0%), tests_pri_-900: 0.95 (0.0%), tests_pri_-400: 17 (0.1%), check_bayes: 16 (0.1%), b_tokenize: 4.9 (0.0%), b_tok_get_all: 5 (0.0%), b_comp_prob: 1.61 (0.0%), b_tok_touch_all: 2.3 (0.0%), b_finish: 0.62 (0.0%), tests_pri_0: 131 (0.9%), check_dkim_signature: 0.44 (0.0%), check_dkim_adsp: 2.8 (0.0%), tests_pri_500: 14854 (98.9%), poll_dns_idle: 14845 (98.8%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v5 1/6] fork: Move and describe why the code examines PIDNS_ADDING 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 Normally this would be something that would be handled by handling signals that are sent to a group of processes but in this case the forking process is not a member of the group being signaled. Thus special code is needed to prevent a race with pid namespaces exiting, and fork adding new processes within them. Move this test up before the signal restart just in case signals are also pending. Fatal conditions should take presedence over restarts. Signed-off-by: "Eric W. Biederman" --- kernel/fork.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index cc5be0d01ce6..b9c54318a292 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1922,6 +1922,12 @@ static __latent_entropy struct task_struct *copy_process( rseq_fork(p, clone_flags); + /* Don't start children in a dying pid namespace */ + if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) { + retval = -ENOMEM; + goto bad_fork_cancel_cgroup; + } + /* * Process group and session signals need to be delivered to just the * parent before the fork or both the parent and the child after the @@ -1935,10 +1941,7 @@ static __latent_entropy struct task_struct *copy_process( retval = -ERESTARTNOINTR; goto bad_fork_cancel_cgroup; } - if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) { - retval = -ENOMEM; - goto bad_fork_cancel_cgroup; - } + init_task_pid_links(p); if (likely(p->pid)) { -- 2.17.1