Patchwork [2/2] posix: Correctly block/unblock all signals on Linux posix_spawn

login
register
mail settings
Submitter Adhemerval Zanella Netto
Date Sept. 14, 2016, 6:56 p.m.
Message ID <1473879370-6731-2-git-send-email-adhemerval.zanella@linaro.org>
Download mbox | patch
Permalink /patch/15639/
State New
Headers show

Comments

Adhemerval Zanella Netto - Sept. 14, 2016, 6:56 p.m.
This patch correctly block and unblocks all signals when executing
Linux posix_spawn by using the __libc_signal_{un}block_all functions
instead of default sigprocmask.  The latter might remove both
SIGCANCEL and SIGSETXID from the blocked signal list.

Checked on x86_64, i686, powerpc64le, and aarch64.

	* sysdeps/unix/sysv/linux/spawni.c (__spawnix): Correctly block and unblock
	all signals when executing the clone vfork child.
	(SIGALL_SET): Remove macro.
---
 ChangeLog                        | 4 ++++
 sysdeps/unix/sysv/linux/spawni.c | 8 ++------
 2 files changed, 6 insertions(+), 6 deletions(-)
Adhemerval Zanella Netto - Sept. 20, 2016, 6:41 p.m.
If no one opposes I will commit it shortly.

On 14/09/2016 15:56, Adhemerval Zanella wrote:
> This patch correctly block and unblocks all signals when executing
> Linux posix_spawn by using the __libc_signal_{un}block_all functions
> instead of default sigprocmask.  The latter might remove both
> SIGCANCEL and SIGSETXID from the blocked signal list.
> 
> Checked on x86_64, i686, powerpc64le, and aarch64.
> 
> 	* sysdeps/unix/sysv/linux/spawni.c (__spawnix): Correctly block and unblock
> 	all signals when executing the clone vfork child.
> 	(SIGALL_SET): Remove macro.
> ---
>  ChangeLog                        | 4 ++++
>  sysdeps/unix/sysv/linux/spawni.c | 8 ++------
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
> index f7cb96f..c34f8fd 100644
> --- a/sysdeps/unix/sysv/linux/spawni.c
> +++ b/sysdeps/unix/sysv/linux/spawni.c
> @@ -60,10 +60,6 @@
>     normal program exit with the exit code 127.  */
>  #define SPAWN_ERROR	127
>  
> -/* We need to block both SIGCANCEL and SIGSETXID.  */
> -#define SIGALL_SET \
> -  ((__sigset_t) { .__val = {[0 ...  _SIGSET_NWORDS-1 ] =  -1 } })
> -
>  #ifdef __ia64__
>  # define CLONE(__fn, __stack, __stacksize, __flags, __args) \
>    __clone2 (__fn, __stack, __stacksize, __flags, __args, 0, 0, 0)
> @@ -331,7 +327,7 @@ __spawnix (pid_t * pid, const char *file,
>    args.xflags = xflags;
>    args.err = 0;
>  
> -  __sigprocmask (SIG_BLOCK, &SIGALL_SET, &args.oldmask);
> +  __libc_signal_block_all (&args.oldmask);
>  
>    /* The clone flags used will create a new child that will run in the same
>       memory space (CLONE_VM) and the execution of calling thread will be
> @@ -357,7 +353,7 @@ __spawnix (pid_t * pid, const char *file,
>    if ((ec == 0) && (pid != NULL))
>      *pid = new_pid;
>  
> -  __sigprocmask (SIG_SETMASK, &args.oldmask, 0);
> +  __libc_signal_restore_set (&args.oldmask);
>  
>    __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
>  
>
Florian Weimer - Sept. 20, 2016, 8:03 p.m.
* Adhemerval Zanella:

> This patch correctly block and unblocks all signals when executing
> Linux posix_spawn by using the __libc_signal_{un}block_all functions
> instead of default sigprocmask.  The latter might remove both
> SIGCANCEL and SIGSETXID from the blocked signal list.
>
> Checked on x86_64, i686, powerpc64le, and aarch64.
>
> 	* sysdeps/unix/sysv/linux/spawni.c (__spawnix): Correctly block and unblock
> 	all signals when executing the clone vfork child.
> 	(SIGALL_SET): Remove macro.

Looks good to me.  Thanks.

Patch

diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c
index f7cb96f..c34f8fd 100644
--- a/sysdeps/unix/sysv/linux/spawni.c
+++ b/sysdeps/unix/sysv/linux/spawni.c
@@ -60,10 +60,6 @@ 
    normal program exit with the exit code 127.  */
 #define SPAWN_ERROR	127
 
-/* We need to block both SIGCANCEL and SIGSETXID.  */
-#define SIGALL_SET \
-  ((__sigset_t) { .__val = {[0 ...  _SIGSET_NWORDS-1 ] =  -1 } })
-
 #ifdef __ia64__
 # define CLONE(__fn, __stack, __stacksize, __flags, __args) \
   __clone2 (__fn, __stack, __stacksize, __flags, __args, 0, 0, 0)
@@ -331,7 +327,7 @@  __spawnix (pid_t * pid, const char *file,
   args.xflags = xflags;
   args.err = 0;
 
-  __sigprocmask (SIG_BLOCK, &SIGALL_SET, &args.oldmask);
+  __libc_signal_block_all (&args.oldmask);
 
   /* The clone flags used will create a new child that will run in the same
      memory space (CLONE_VM) and the execution of calling thread will be
@@ -357,7 +353,7 @@  __spawnix (pid_t * pid, const char *file,
   if ((ec == 0) && (pid != NULL))
     *pid = new_pid;
 
-  __sigprocmask (SIG_SETMASK, &args.oldmask, 0);
+  __libc_signal_restore_set (&args.oldmask);
 
   __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);