mirror of https://github.com/containers/podman.git
rootless: block signals on re-exec
we are allowed to use only signal safe functions between a fork of a multithreaded application and the next execve. Since setenv(3) is not signal safe, block signals. We are already doing it for creating a new namespace. This is mostly a cleanup since reexec_in_user_namespace_wait is used only only to join existing namespaces when we have not a pause.pid file. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
176a41c355
commit
6b0e1a3091
|
@ -489,6 +489,7 @@ reexec_userns_join (int userns, int mountns, char *pause_pid_file_path)
|
|||
char **argv;
|
||||
int pid;
|
||||
char *cwd = getcwd (NULL, 0);
|
||||
sigset_t sigset, oldsigset;
|
||||
|
||||
if (cwd == NULL)
|
||||
{
|
||||
|
@ -522,6 +523,22 @@ reexec_userns_join (int userns, int mountns, char *pause_pid_file_path)
|
|||
return pid;
|
||||
}
|
||||
|
||||
if (sigfillset (&sigset) < 0)
|
||||
{
|
||||
fprintf (stderr, "cannot fill sigset: %s\n", strerror (errno));
|
||||
_exit (EXIT_FAILURE);
|
||||
}
|
||||
if (sigdelset (&sigset, SIGCHLD) < 0)
|
||||
{
|
||||
fprintf (stderr, "cannot sigdelset(SIGCHLD): %s\n", strerror (errno));
|
||||
_exit (EXIT_FAILURE);
|
||||
}
|
||||
if (sigprocmask (SIG_BLOCK, &sigset, &oldsigset) < 0)
|
||||
{
|
||||
fprintf (stderr, "cannot block signals: %s\n", strerror (errno));
|
||||
_exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
setenv ("_CONTAINERS_USERNS_CONFIGURED", "init", 1);
|
||||
setenv ("_CONTAINERS_ROOTLESS_UID", uid, 1);
|
||||
setenv ("_CONTAINERS_ROOTLESS_GID", gid, 1);
|
||||
|
@ -570,6 +587,11 @@ reexec_userns_join (int userns, int mountns, char *pause_pid_file_path)
|
|||
/* We ignore errors here as we didn't create the namespace anyway. */
|
||||
create_pause_process (pause_pid_file_path, argv);
|
||||
}
|
||||
if (sigprocmask (SIG_SETMASK, &oldsigset, NULL) < 0)
|
||||
{
|
||||
fprintf (stderr, "cannot block signals: %s\n", strerror (errno));
|
||||
_exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
execvp (argv[0], argv);
|
||||
|
||||
|
|
Loading…
Reference in New Issue