This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] [GLIBC RFC] clone3: add CLONE3_RESET_SIGHAND



On 08/10/2019 10:44, 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 threads
> signal handler.
> 
> Questions for glibc before going to send this for review on lkml:
> - Is it sufficient for glibc to get EINVAL when CLONE3_RESET_SIGNALS is
>   passed to determine kernel support for it?

It makes the clone/clone3 call on posix_spawn somewhat more complex, something
like:

#ifdef __ASSUME_CLONE3
   /* This clone3 is modelled with glibc clone semantics where a function
      pointer is passed and executed in child process.  */
   new_pid = clone3 (__spawni_child, __spawni_args, 
		     &((struct clone_args) {CLONE3_RESET_SIGHAND, ... }), ...);
   if (new_pid == -1 && errno == EINVAL)
     {
       __spawni_args.xflags |= RESET_SIGNALS;
        new_pid = clone3 (__spawni_child, __spawni_args, 
		          &((struct clone_args) {0, ... }), ...);
     }
#else
   __spawni_args.xflags |= RESET_SIGNALS;
   new_pid = clone (__spawni_child, __spawni_args, ...);
#endif

We can add __ASSUME_CLONE3_RESET_SIGHAND which would allow to not require
check for EINVAL, but it would be another build permutation...

Is there a way to advertise it to *child* process somehow? Now that flags
is passed in a struct, maybe reset the flags that current kernel does not
accept so underlying process could act accordantly? 

> - Do you really want to have only those signals set to SIG_DFL which are
>   not SIG_IGN or do you want to enforce _all_ signals are set to
>   SIG_DFL even if they are SIG_IGN?

We only current support POSIX_SPAWN_SETSIGDEF, but Solaris 11, for instance,
also supports POSIX_SPAWN_SETSIGIGN_NP as an extension. I am not sure how
useful this would be, neither an I can think of an specific usercase where
it would be required.

> 
> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
> ---
>  include/uapi/linux/sched.h | 3 +++
>  kernel/fork.c              | 8 +++++++-
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
> index 99335e1f4a27..e3bc43efbbba 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_RESET_SIGHAND 0x100000000ULL /* Reset any signal handler which is not SIG_IGN or SIG_DFL 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..3bced4a2931e 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1516,6 +1516,9 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk)
>  	refcount_set(&sig->count, 1);
>  	spin_lock_irq(&current->sighand->siglock);
>  	memcpy(sig->action, current->sighand->action, sizeof(sig->action));
> +	/* Reset all signal handler not set to SIG_IGN to SIG_DFL. */
> +	if (clone_flags & CLONE3_RESET_SIGHAND)
> +		flush_signal_handlers(tsk, 0);
>  	spin_unlock_irq(&current->sighand->siglock);
>  	return 0;
>  }
> @@ -2567,7 +2570,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_RESET_SIGNALS))
>  		return false;
>  
>  	/*
> @@ -2577,6 +2580,9 @@ 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_RESET_SIGHAND))
> +		return false;
> +
>  	if ((kargs->flags & (CLONE_THREAD | CLONE_PARENT)) &&
>  	    kargs->exit_signal)
>  		return false;
> 

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]