user_ns: Block SIGCHLD during namespaces generation

Submitted by Kirill Tkhai on April 1, 2017, 12:06 p.m.

Details

Message ID 149104836214.30848.9030322298402678758.stgit@localhost.localdomain
State New
Series "user_ns: Block SIGCHLD during namespaces generation"
Headers show

Commit Message

Kirill Tkhai April 1, 2017, 12:06 p.m.
We don't want asynchronous signal handler does wait()
as we do that synchronous. So block the signal.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/namespaces.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 6637abcb..2e8ad452 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -2257,7 +2257,26 @@  static int create_user_ns_hierarhy_fn(void *in_arg)
 static int create_user_ns_hierarhy(void)
 {
 	struct ns_arg arg = { .me = root_user_ns };
-	return create_user_ns_hierarhy_fn(&arg);
+	sigset_t blockmask, oldmask;
+	int ret;
+
+	sigemptyset(&blockmask);
+	sigaddset(&blockmask, SIGCHLD);
+
+	if (sigprocmask(SIG_BLOCK, &blockmask, &oldmask) == -1) {
+		pr_perror("Can not set mask of blocked signals");
+		return -1;
+	}
+
+	if (create_user_ns_hierarhy_fn(&arg))
+		ret = -1;
+
+	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) == -1) {
+		pr_perror("Can not unset mask of blocked signals");
+		ret = -1;
+	}
+
+	return ret;
 }
 
 int prepare_namespace(struct pstree_item *item, unsigned long clone_flags)

Comments

Kirill Tkhai April 1, 2017, 1:03 p.m.
Ignore this.

On 01.04.2017 15:06, Kirill Tkhai wrote:
> We don't want asynchronous signal handler does wait()
> as we do that synchronous. So block the signal.
> 
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>  criu/namespaces.c |   21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/namespaces.c b/criu/namespaces.c
> index 6637abcb..2e8ad452 100644
> --- a/criu/namespaces.c
> +++ b/criu/namespaces.c
> @@ -2257,7 +2257,26 @@ static int create_user_ns_hierarhy_fn(void *in_arg)
>  static int create_user_ns_hierarhy(void)
>  {
>  	struct ns_arg arg = { .me = root_user_ns };
> -	return create_user_ns_hierarhy_fn(&arg);
> +	sigset_t blockmask, oldmask;
> +	int ret;
> +
> +	sigemptyset(&blockmask);
> +	sigaddset(&blockmask, SIGCHLD);
> +
> +	if (sigprocmask(SIG_BLOCK, &blockmask, &oldmask) == -1) {
> +		pr_perror("Can not set mask of blocked signals");
> +		return -1;
> +	}
> +
> +	if (create_user_ns_hierarhy_fn(&arg))
> +		ret = -1;
> +
> +	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) == -1) {
> +		pr_perror("Can not unset mask of blocked signals");
> +		ret = -1;
> +	}
> +
> +	return ret;
>  }
>  
>  int prepare_namespace(struct pstree_item *item, unsigned long clone_flags)
>