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

unix: reset signal disposition before execve() #1376

Merged
merged 2 commits into from Jun 30, 2017

Conversation

bnoordhuis
Copy link
Member

@bnoordhuis bnoordhuis commented Jun 14, 2017

Signal dispositions are inherited by child processes. Libuv itself
does not touch them (if you don't use uv_signal_start(), that is)
but the embedder might and probably does in the case of SIGPIPE.

Reset the disposition for signals 1-31 to their defaults right before
execve'ing into the new process.

But caveat emptor:

This does open a race window where blocked signals can get delivered
in the interval between the pthread_sigmask() call and the execve() call
(and may end up terminating the process)

Fixes: nodejs/node#13662

CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/294/

@santigimeno
Copy link
Member

santigimeno commented Jun 15, 2017

Would it make sense adding an option so the user can decide what behavior it prefers (just in case there are people relying in the current behavior)?

@bnoordhuis
Copy link
Member Author

Yes. I was going to propose that if people weren't on board with this.

@vtjnash
Copy link
Member

vtjnash commented Jun 23, 2017

+1. We've been carrying a similar patch in Julia for years.

@bnoordhuis
Copy link
Member Author

@libuv/collaborators Can I get a review? Your opinion on whether or not to add a flag is welcome too.

(I'm currently leaning towards not adding a flag but happy to do it if everyone feels it's a good idea.)

Copy link
Member

@santigimeno santigimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. No strong opinion about doing this optional or not.

}

/* Reset signal mask. */
sigemptyset(&set);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check for sigemptyset() return value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wups, sorry Santi, missed your comment. I don't mind adding that but it's probably academic, I'm not aware of any platforms where sigemptyset() can actually fail. What would it even mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I was also surprised when looking at the manual that it could fail

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as-is.

Copy link
Member

@indutny indutny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signal dispositions are inherited by child processes.  Libuv itself
does not touch them (if you don't use uv_signal_start(), that is)
but the embedder might and probably does in the case of SIGPIPE.

Reset the disposition for signals 1-31 to their defaults right before
execve'ing into the new process.

Fixes: nodejs/node#13662
PR-URL: libuv#1376
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Like the previous commit, except now the signal mask is reset instead
of the signal disposition.  This does open a race window where blocked
signals can get delivered in the interval between the pthread_sigmask()
call and the execve() call (and may end up terminating the process) but
that cannot be helped; the same caveat applies to the previous commit.

Fixes: nodejs/node#13662
PR-URL: libuv#1376
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
@bnoordhuis bnoordhuis closed this Jun 30, 2017
@bnoordhuis bnoordhuis deleted the fix13662 branch June 30, 2017 22:48
@bnoordhuis bnoordhuis merged commit 11563e1 into libuv:v1.x Jun 30, 2017
@bnoordhuis
Copy link
Member Author

Rebase + new CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/308/ - all green and landed in d0a27ba...11563e1. Just to be on the safe side I did a local integration test with node.js and all was green there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants