Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp617406ybp; Fri, 11 Oct 2019 01:22:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzwFrn/aenFd+PY5v78XNmdEWt22Y1810VLrNNcel4aXIcnzkTT33/27SK2KrjepXkKRfb X-Received: by 2002:a05:6402:323:: with SMTP id q3mr12504874edw.166.1570782161343; Fri, 11 Oct 2019 01:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570782161; cv=none; d=google.com; s=arc-20160816; b=XA7J7uaXvAbDcFzt0oEpq0kWrk2srRG6wFhCXb/x+qFTdI07zJHp5xmJDUV4/JePhG mHQqRgbHanFIA7MXclPkUAFKNnF66Slb+nlU15MVYQG2dlVsSynNRThg4zlDWPoTeENe 9nfbriDlzOxlSszCzUntlaKQDBZFK8CZLyc0cb8E0+eF2GYhMzj2a2jjmvnGZJbdXKyA zv1Gqz/uua6m/mkTO0b73NNJ0qLhpxox0VBCpjqddjr5j1RpcmbRwQinj1dNYc1BwHno qC4KDJwlV0VhsncWwSJkD3PkQnXsEbHXNYxtut1AzV1HkhRnIugMvXSvf1CJbzsPoakc fwPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=5invt6u0w2WdAJjaPTSAC6bTf4kBRkqavMIdT42JQAE=; b=LGfkNWxXSnDVpTHEIHhdhMKeupL3u2DaDnKyabCoAky+yUoToleB1YC15AH6RqYajj azf6kgxMm0FsnCJkuNO5oBYb6YPuRGvkZlaQm3fTeEKxWgiMHZIzq+PR4nQEJLCupT3b zbc8Q4EBEnVoNwaKxt/BG4IVQTyRZyRCx/tiRGOHyGGeLW7iSINVRE8CptetZVZw6ZEh BF+uVKGH89uyUIpAvug3edZwP6RiOY6F/Qc7GkfJ8UtHNAPxw5CLoyxOGjVnZuIvTIEt lheP/q5OJTUjlnHXl8CgHEPY81cZF1LCaVGggD4OkzuGGmxtphRcWMT66wIP5DrNn8Jb CBBg== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si4880645edq.430.2019.10.11.01.22.17; Fri, 11 Oct 2019 01:22:41 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbfJKIVY (ORCPT + 99 others); Fri, 11 Oct 2019 04:21:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:36342 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726885AbfJKIVY (ORCPT ); Fri, 11 Oct 2019 04:21:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5E9C6B124; Fri, 11 Oct 2019 08:21:21 +0000 (UTC) Date: Fri, 11 Oct 2019 10:21:18 +0200 From: Michal Hocko To: Christian Brauner Cc: linux-kernel@vger.kernel.org, Oleg Nesterov , Florian Weimer , libc-alpha@sourceware.org, Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Shuah Khan , Andrew Morton , Elena Reshetova , Thomas Gleixner , Roman Gushchin , Andrea Arcangeli , Al Viro , Aleksa Sarai , "Dmitry V. Levin" , linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org Subject: Re: [PATCH 1/2] clone3: add CLONE3_CLEAR_SIGHAND Message-ID: <20191011082118.GA26368@dhcp22.suse.cz> References: <20191010133518.5420-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191010133518.5420-1-christian.brauner@ubuntu.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [Cc linux-api] On Thu 10-10-19 15:35:17, Christian Brauner wrote: > Reset all signal handlers of the child not set to SIG_IGN to SIG_DFL. > Mutually exclusive with CLONE_SIGHAND to not disturb other thread's > signal handler. > > In the spirit of closer cooperation between glibc developers and kernel > developers (cf. [2]) this patchset came out of a discussion on the glibc > mailing list for improving posix_spawn() (cf. [1], [3], [4]). Kernel > support for this feature has been explicitly requested by glibc and I > see no reason not to help them with this. > > The child helper process on Linux posix_spawn must ensure that no signal > handlers are enabled, so the signal disposition must be either SIG_DFL > or SIG_IGN. However, it requires a sigprocmask to obtain the current > signal mask and at least _NSIG sigaction calls to reset the signal > handlers for each posix_spawn call or complex state tracking that might > lead to data corruption in glibc. Adding this flags lets glibc avoid > these problems. > > [1]: https://www.sourceware.org/ml/libc-alpha/2019-10/msg00149.html > [3]: https://www.sourceware.org/ml/libc-alpha/2019-10/msg00158.html > [4]: https://www.sourceware.org/ml/libc-alpha/2019-10/msg00160.html > [2]: https://lwn.net/Articles/799331/ > '[...] by asking for better cooperation with the C-library projects > in general. They should be copied on patches containing ABI > changes, for example. I noted that there are often times where > C-library developers wish the kernel community had done things > differently; how could those be avoided in the future? Members of > the audience suggested that more glibc developers should perhaps > join the linux-api list. The other suggestion was to "copy Florian > on everything".' > Cc: Oleg Nesterov > Cc: Florian Weimer > Cc: libc-alpha@sourceware.org > Signed-off-by: Christian Brauner > --- > include/uapi/linux/sched.h | 3 +++ > kernel/fork.c | 11 ++++++++++- > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h > index 99335e1f4a27..c583720f689f 100644 > --- a/include/uapi/linux/sched.h > +++ b/include/uapi/linux/sched.h > @@ -33,6 +33,9 @@ > #define CLONE_NEWNET 0x40000000 /* New network namespace */ > #define CLONE_IO 0x80000000 /* Clone io context */ > > +/* Flags for the clone3() syscall */ > +#define CLONE3_CLEAR_SIGHAND 0x100000000ULL /* Clear any signal handler and reset to SIG_DFL. */ > + > #ifndef __ASSEMBLY__ > /** > * struct clone_args - arguments for the clone3 syscall > diff --git a/kernel/fork.c b/kernel/fork.c > index 1f6c45f6a734..661f8d1f3881 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1517,6 +1517,11 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) > spin_lock_irq(¤t->sighand->siglock); > memcpy(sig->action, current->sighand->action, sizeof(sig->action)); > spin_unlock_irq(¤t->sighand->siglock); > + > + /* Reset all signal handler not set to SIG_IGN to SIG_DFL. */ > + if (clone_flags & CLONE3_CLEAR_SIGHAND) > + flush_signal_handlers(tsk, 0); > + > return 0; > } > > @@ -2567,7 +2572,7 @@ static bool clone3_args_valid(const struct kernel_clone_args *kargs) > * All lower bits of the flag word are taken. > * Verify that no other unknown flags are passed along. > */ > - if (kargs->flags & ~CLONE_LEGACY_FLAGS) > + if (kargs->flags & ~(CLONE_LEGACY_FLAGS | CLONE3_CLEAR_SIGHAND)) > return false; > > /* > @@ -2577,6 +2582,10 @@ static bool clone3_args_valid(const struct kernel_clone_args *kargs) > if (kargs->flags & (CLONE_DETACHED | CSIGNAL)) > return false; > > + if ((kargs->flags & (CLONE_SIGHAND | CLONE3_CLEAR_SIGHAND)) == > + (CLONE_SIGHAND | CLONE3_CLEAR_SIGHAND)) > + return false; > + > if ((kargs->flags & (CLONE_THREAD | CLONE_PARENT)) && > kargs->exit_signal) > return false; > -- > 2.23.0 -- Michal Hocko SUSE Labs