Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pidfd: block SIGCHLD during tmp process creation #2491

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions criu/pidfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ static int create_tmp_process(void)
static int free_dead_pidfd(struct dead_pidfd *dead)
{
int status;
sigset_t blockmask, oldmask;

/*
* Block SIGCHLD to prevent interfering from sigchld_handler()
* and to properly handle the tmp process termination without
* a race condition. A similar approach is used in cr_system().
*/
sigemptyset(&oldmask);
sigemptyset(&blockmask);
sigaddset(&blockmask, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &blockmask, &oldmask) == -1) {
pr_perror("Cannot set mask of blocked signals");
goto err;
}

if (kill(dead->pid, SIGKILL) < 0) {
pr_perror("Could not kill temporary process with pid: %d",
Expand All @@ -158,6 +172,12 @@ static int free_dead_pidfd(struct dead_pidfd *dead)
goto err;
}

/* Restore the original signal mask after tmp process has terminated */
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) == -1) {
pr_perror("Cannot clear blocked signals");
goto err;
}

if (!WIFSIGNALED(status)) {
pr_err("Expected temporary process to be terminated by a signal\n");
goto err;
Expand Down
Loading