Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1086062ybh; Tue, 10 Mar 2020 14:22:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvHUkziUUKyuYyEeBKgXVJtxEiB7ITirZMF5I4zJpwufLvZYSWtv1W0XhqRHwG5p2s92ElW X-Received: by 2002:a05:6808:98e:: with SMTP id a14mr2593673oic.8.1583875367779; Tue, 10 Mar 2020 14:22:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583875367; cv=none; d=google.com; s=arc-20160816; b=BGKc27uMbAzP+fkcygn1eBwUAgr1wPDs1MdmzDzvPU4MKGyh3TQLKNQ6cYG8gkcJcF 3+IF7Glz87HtXlLlnSR+l3YyQm6lVkcHc/46yoh83SJ7TgnYD4xw+MUTk3cayZ39ZsgL M1yAUv0q+93ompK4OthGO3obZJV5wCdWY2EQunGVwMe9MMegoV+is6If3lrv061XEP9K EHAV965oE1N6mlRpggKqfg9aA2aPBLLHnJ92xjJb72Ala73IDg3wLfJvlaCo07tRUNNC wyw9azZcQyBYFu5BleWHj0iHiYUHPip2Edmse8qV6G5msm/EdFmiNsBXN+V1AMrIKok0 gxhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Z4p+xtFC9jJ4iyfaHzUpf2VQH/n1MXKAtQBOyLJQPHg=; b=iAI3h4uJsUIYo78Rw5T4DPrZS6Ej3hZaELEmV57lIFwwGm/amAMFBeJJAJ3jgb0ssP M3Adh6enOixA2y3zgUjKaFr1A0w3r+7V8HosASZQCl7gduo40wjoRS24D6mm9oDrMz65 lzhTNnaV+BmR4JHrIMxHwY+DhbO5zn7X1225kEfN4H6HKc053w+/8y1oLTkNqFNsnLul ZMq4fQkIRPKRVUUOVQrtbAEUdCgl+zNxZWFfUdrD6X6UO224d5hS5Wi1pBmppHQ/KjY7 uhuTodtfCx59hlJ8dTJyhLm/CWy2u3mMmZCItC4hcBZN/v031hhIS6MesW7Lj8xjDpSf ZimA== 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 e6si9110742oti.166.2020.03.10.14.22.35; Tue, 10 Mar 2020 14:22:47 -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 S1727635AbgCJVWE (ORCPT + 99 others); Tue, 10 Mar 2020 17:22:04 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58083 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727504AbgCJVWC (ORCPT ); Tue, 10 Mar 2020 17:22:02 -0400 Received: from ip5f5bf7ec.dynamic.kabel-deutschland.de ([95.91.247.236] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jBmJc-0000N4-9H; Tue, 10 Mar 2020 21:21:28 +0000 Date: Tue, 10 Mar 2020 22:21:24 +0100 From: Christian Brauner To: "Eric W. Biederman" Cc: Bernd Edlinger , 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" Subject: Re: [PATCH v2 2/5] exec: Factor unshare_sighand out of de_thread and call it separately Message-ID: <20200310212124.l6rajcjkitt65fxr@wittgenstein> References: <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> <87k13u5y26.fsf_-_@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87k13u5y26.fsf_-_@x220.int.ebiederm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 08, 2020 at 04:36:17PM -0500, Eric W. Biederman wrote: > > 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); > } This is fine for now but we share an aweful lot of code with copy_sighand(). We should earmark this to look into consolidating the core operations into a common helper called from both copy_sighand() and unshare_sighand() maybe even dumbing it down to one helper. But not needed for now. Otherwise: Acked-by: Christian Brauner