Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7261407imm; Tue, 24 Jul 2018 11:00:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdD3aooLsUxHe4ANNkXMJghIbP0+5otqjWa7nAPFU/fc7K2otl1z2LlpIILasIuz1ebTzpb X-Received: by 2002:a63:d10c:: with SMTP id k12-v6mr17652977pgg.49.1532455229101; Tue, 24 Jul 2018 11:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532455229; cv=none; d=google.com; s=arc-20160816; b=PlIYWGnnz3QjE0oywKCgBx5ZSB+CcNqqUEzvG3HN466AQuX4K7HSwYMUQMLzFTkdet 4GnVaCNZ8ZMX3f977VLHM1e13u2rqcqNHH2KGDkngSzA8cTsS9KtmVGsfPalVbAw4tSM SPnUprD+3pcatFSR4nzLU6z4DQ/pLJA84XuzpdxxN387ihxkegR4DyPIMyLm8VKYqhvS 22t0jORXaohllC37cUXq6XuSREvJuvkUyWyI4dw7BEWBQCR6Ps+VQEF2TMw6ap4902yo mNZJUJcEm3Ae11ZfYwZSmWwrcq4GQ//lvJZIdVzzF0KlESa1SB3cFgqKy1WzOC+8Q03J nKAg== 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=ExJLYttVpvS5q27b/9EV4b0RQFWcW7prkHfex002Svk=; b=IXj8g7KAvC6eYJcz14I2EGUBXLijumWXMuxQiHzNVqXEg0d21cCtLvsR2/pjJHMevm LFS0ipSdYjwRWYPx/se1/VCWPBB+inVA/ouePR8VWGm+5EUNtjnCqkvHCnXcpm6KQDSv OsbSfs2ED1OF2XQpTf0rYZYwQJCshkD1henwOK15wFxnFEILIPUyPRSULazrVKYFoRYL 8aAJ9GHHYxgEIKN+OWXcKZqEwYEXALBscpzI6YU3uDsn+suboEtSdIbY1tW3IUddiSs/ hgCZejg5bu+gKVcmNB5y5n5WrgXAfoU5i1sDYcAmhNYEpWarh0u3iXmg6XyhmT61C93V 1V6Q== 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 v12-v6si10306190plz.105.2018.07.24.11.00.14; Tue, 24 Jul 2018 11:00:29 -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 S2388475AbeGXTG2 (ORCPT + 99 others); Tue, 24 Jul 2018 15:06:28 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:33863 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388414AbeGXTG1 (ORCPT ); Tue, 24 Jul 2018 15:06:27 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fi1aC-0004qq-Vt; Tue, 24 Jul 2018 11:58:49 -0600 Received: from [97.119.167.31] (helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1fi1aC-0001XC-5K; Tue, 24 Jul 2018 11:58:48 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Oleg Nesterov , Andrew Morton , Linux Kernel Mailing List , Wen Yang , majiang References: <87efft5ncd.fsf_-_@xmission.com> <20180724032419.20231-20-ebiederm@xmission.com> Date: Tue, 24 Jul 2018 12:58:35 -0500 In-Reply-To: (Linus Torvalds's message of "Tue, 24 Jul 2018 10:27:58 -0700") Message-ID: <874lgo5xdg.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=1fi1aC-0001XC-5K;;;mid=<874lgo5xdg.fsf@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=97.119.167.31;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18DUmslOieX6tURFBDmHOwEhv8ashzDt9k= 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 sa04.xmission.com X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01,T_TooManySym_02, XMNoVowels,XMSubLong autolearn=disabled version=3.4.1 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 * 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.4995] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 180 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 2.7 (1.5%), b_tie_ro: 1.87 (1.0%), parse: 0.78 (0.4%), extract_message_metadata: 12 (6.7%), get_uri_detail_list: 1.39 (0.8%), tests_pri_-1000: 7 (4.1%), tests_pri_-950: 1.14 (0.6%), tests_pri_-900: 0.94 (0.5%), tests_pri_-400: 19 (10.8%), check_bayes: 18 (10.2%), b_tokenize: 6 (3.4%), b_tok_get_all: 6 (3.4%), b_comp_prob: 2.0 (1.1%), b_tok_touch_all: 2.4 (1.4%), b_finish: 0.57 (0.3%), tests_pri_0: 130 (72.1%), check_dkim_signature: 0.63 (0.4%), check_dkim_adsp: 2.7 (1.5%), tests_pri_500: 3.4 (1.9%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 20/20] signal: Don't restart fork when signals come in. 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 Linus Torvalds writes: > This is completely broken. > > On Mon, Jul 23, 2018 at 8:27 PM Eric W. Biederman wrote: >> >> diff --git a/kernel/fork.c b/kernel/fork.c >> index 6c358846a8b8..6ee5822f0085 100644 >> --- a/kernel/fork.c >> +++ b/kernel/fork.c >> @@ -1602,6 +1603,24 @@ static __latent_entropy struct task_struct *copy_process( >> { >> int retval; >> struct task_struct *p; >> + struct multiprocess_signals delayed; >> + >> + /* >> + * Force any signals received before this point to be delivered >> + * before the fork happens. Collect up signals sent to multiple >> + * processes that happen during the fork and delay them so that >> + * they appear to happen after the fork. >> + */ >> + sigemptyset(&delayed.signal); >> + INIT_HLIST_NODE(&delayed.node); >> + >> + spin_lock_irq(¤t->sighand->siglock); >> + if (!(clone_flags & CLONE_THREAD)) >> + hlist_add_head(&delayed.node, ¤t->signal->multiprocess); > > Here you add the entry to the multiprocess list. > >> + recalc_sigpending(); >> + spin_unlock_irq(¤t->sighand->siglock); >> + if (signal_pending(current)) >> + return ERR_PTR(restart_syscall()); > > .. and here you return with the list entry still there, pointing to > the stack that you now no longer use. > > The same is true of *all* the error cases, because the only point you > remove it is for the success case: Yes you are quite right. Easy enough to fix, but it definitely needs to be fixed. I will respin. Eric >> @@ -1979,6 +1982,8 @@ static __latent_entropy struct task_struct *copy_process( >> attach_pid(p, PIDTYPE_TGID); >> attach_pid(p, PIDTYPE_PGID); >> attach_pid(p, PIDTYPE_SID); >> + p->signal->shared_pending.signal = delayed.signal; >> + hlist_del(&delayed.node); > > So for all the error cases, you leave a dangling pointer to the > current stack in that signal handler, and then return an error. > > Guaranteed stack and list corruption. > > Linus