Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1839668ybh; Sun, 8 Mar 2020 14:39:23 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuKPkEdFnvfoWpfSWu6rp39XuguH2B0qqa7ikuXGtJ8U1P4FLOtjdxNnhfW6RAEupw2sN3z X-Received: by 2002:a05:6808:8d0:: with SMTP id k16mr9484060oij.68.1583703563118; Sun, 08 Mar 2020 14:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583703563; cv=none; d=google.com; s=arc-20160816; b=pMFtbVM7CTDosysp9le1P60iNtn0Vc4wnjKWKXFLBcraA8mg9nAu0+4SDUQyx48rRs GeyXuygzOHwTJ/VqCJy80DlFXr6jwXzbr+DxLsCtzVld0AH1wH2gV8Gk1y7y/imwceKD uEdbDEK7Mu7mwhDvmCCt5pPjYItGieJ43WHGlNgpxPrCcwtDETi7PzNxsDZ4JaGISQcR P9PbjaSfI0+18Drm7PG9/i8hrY+YRiAtnW7gZgsU5Al1+l9ggqLXjCB4B12PPuTXWRH6 aNYOryMSsH4Yb4dRgcytXdcQTl/fUUOq5tdp7D0Y7sBX5WWczRTL8l4MibScVPksOunj xxYA== 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; bh=MgSgAhLX/aXOSzfm7/vIhI984ozfNL+bXQL0EoqRONw=; b=cwWk7A7r6htnC089GtSW6Fwa/hkqqYGRRP5oeaTbGtLtgmyFF/bIAG5XvcCxdFfI0L d9grNWmnwebz9DPbkjDbdFHMFM+p9Q0tFyyZjagIFScDSJh4d2/SxJD7Qrr2mffa2g0s 6VRYSJxdROUvCwnNGcV+gcNF1iVGZ+61ufo2kIJ3CxUz2f7M+DjiVGtfaYl3bQXQmBlO YNEl6y+G1KLkZMH3LAmTZW9pj/Vfz54Oa92r4A4lE2F7qd03bTSOmCRnLxP+t/XN03EP VHfvxsrD4YluR8Lg6BjQcBYm6Xmhg1LhydezBXNxHiz7KG4Q+drJIBUiSDQ8wXaxFUWt PkHA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si2676701ots.121.2020.03.08.14.39.11; Sun, 08 Mar 2020 14:39:23 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726449AbgCHVii (ORCPT + 99 others); Sun, 8 Mar 2020 17:38:38 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:45782 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726346AbgCHVih (ORCPT ); Sun, 8 Mar 2020 17:38:37 -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.90_1) (envelope-from ) id 1jB3d4-0007cP-VM; Sun, 08 Mar 2020 15:38:35 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jB3d3-0001ox-Uq; Sun, 08 Mar 2020 15:38:34 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Bernd Edlinger Cc: Christian Brauner , Kees Cook , Jann Horn , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra \(Intel\)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc\@vger.kernel.org" , "linux-kernel\@vger.kernel.org" , "linux-fsdevel\@vger.kernel.org" , "linux-mm\@kvack.org" , "stable\@vger.kernel.org" , "linux-api\@vger.kernel.org" References: <87k142lpfz.fsf@x220.int.ebiederm.org> <875zfmloir.fsf@x220.int.ebiederm.org> <87v9nmjulm.fsf@x220.int.ebiederm.org> <202003021531.C77EF10@keescook> <20200303085802.eqn6jbhwxtmz4j2x@wittgenstein> <87v9nlii0b.fsf@x220.int.ebiederm.org> <87a74xi4kz.fsf@x220.int.ebiederm.org> <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> Date: Sun, 08 Mar 2020 16:36:17 -0500 In-Reply-To: <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> (Eric W. Biederman's message of "Sun, 08 Mar 2020 16:34:37 -0500") Message-ID: <87k13u5y26.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1jB3d3-0001ox-Uq;;;mid=<87k13u5y26.fsf_-_@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX181hWQFhcXeH2DZ7lmXnC5JxL6rk00Uo9s= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa06.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.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4999] * 0.7 XMSubLong Long Subject * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Bernd Edlinger X-Spam-Relay-Country: X-Spam-Timing: total 592 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.0 (0.5%), b_tie_ro: 2.1 (0.3%), parse: 1.46 (0.2%), extract_message_metadata: 13 (2.2%), get_uri_detail_list: 1.98 (0.3%), tests_pri_-1000: 17 (2.8%), tests_pri_-950: 1.24 (0.2%), tests_pri_-900: 1.07 (0.2%), tests_pri_-90: 31 (5.2%), check_bayes: 30 (5.0%), b_tokenize: 12 (2.0%), b_tok_get_all: 9 (1.6%), b_comp_prob: 2.2 (0.4%), b_tok_touch_all: 4.0 (0.7%), b_finish: 0.61 (0.1%), tests_pri_0: 514 (86.8%), check_dkim_signature: 0.57 (0.1%), check_dkim_adsp: 2.6 (0.4%), poll_dns_idle: 1.00 (0.2%), tests_pri_10: 2.1 (0.4%), tests_pri_500: 6 (1.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v2 2/5] exec: Factor unshare_sighand out of de_thread and call it separately 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 This makes the code clearer and makes it easier to implement a mutex that is not taken over any locations that may block indefinitely waiting for userspace. Signed-off-by: "Eric W. Biederman" --- fs/exec.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index c3f34791f2f0..ff74b9a74d34 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1194,6 +1194,23 @@ static int de_thread(struct task_struct *tsk) flush_itimer_signals(); #endif + BUG_ON(!thread_group_leader(tsk)); + return 0; + +killed: + /* protects against exit_notify() and __exit_signal() */ + read_lock(&tasklist_lock); + sig->group_exit_task = NULL; + sig->notify_count = 0; + read_unlock(&tasklist_lock); + return -EAGAIN; +} + + +static int unshare_sighand(struct task_struct *me) +{ + struct sighand_struct *oldsighand = me->sighand; + if (refcount_read(&oldsighand->count) != 1) { struct sighand_struct *newsighand; /* @@ -1210,23 +1227,13 @@ static int de_thread(struct task_struct *tsk) write_lock_irq(&tasklist_lock); spin_lock(&oldsighand->siglock); - rcu_assign_pointer(tsk->sighand, newsighand); + rcu_assign_pointer(me->sighand, newsighand); spin_unlock(&oldsighand->siglock); write_unlock_irq(&tasklist_lock); __cleanup_sighand(oldsighand); } - - BUG_ON(!thread_group_leader(tsk)); return 0; - -killed: - /* protects against exit_notify() and __exit_signal() */ - read_lock(&tasklist_lock); - sig->group_exit_task = NULL; - sig->notify_count = 0; - read_unlock(&tasklist_lock); - return -EAGAIN; } char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) @@ -1264,13 +1271,19 @@ int flush_old_exec(struct linux_binprm * bprm) int retval; /* - * Make sure we have a private signal table and that - * we are unassociated from the previous thread group. + * Make this the only thread in the thread group. */ retval = de_thread(me); if (retval) goto out; + /* + * Make the signal table private. + */ + retval = unshare_sighand(me); + if (retval) + goto out; + /* * Must be called _before_ exec_mmap() as bprm->mm is * not visibile until then. This also enables the update -- 2.25.0