-
Notifications
You must be signed in to change notification settings - Fork 30k
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
PlatformInit resets signal handlers to SIG_DFL causing crashes #47013
Comments
I'm a bit torn on whether to add workarounds for dodgy LD_PRELOAD wrappers but philosophical objections aside, I don't think node can detect their presence in a race-free manner. If third-party code can run really early, then it can call sigaction() from a newly started thread. Meaning this won't work: sigaction(nr, nullptr, &old);
// <-- sigaction()-from-other-thread race window here
if (old.sa_handler == SIG_DFL) sigaction(nr, &act, nullptr); And neither will this: sigaction(nr, &act, &old);
// <-- signal delivery race window here
if (old.sa_handler != SIG_DFL) sigaction(nr, &old, nullptr); (And I'm skipping over the practical concern that reading |
Yes, this won't work and looks wild. I don't think we should be bothered with such possibilities. Signal handlers are inherently global and shouldn't be changed asynchronously. A normal sequential check for existing handlers sounds reasonable.
The code currently does:
so presumably at least this is working fine on all platforms. |
Yes, because The real logic should look something like this, and, caveat emptor, I'm not 100% sure this won't emit warnings or isn't UB according to POSIX: if ((old.sa_flags & SA_SIGINFO) && old.sa_sigaction == SIG_DFL || old.sa_handler == SIG_DFL) Well, pull request welcome, I suppose. |
@dvyukov are you interested in pursuing this? If not, all good, but then I'll go ahead and close this out. |
Yes, I am. I just somehow missed your previous reply. |
There's test/embedding/embedtest.cc and concomitant JS file but I wouldn't want to vouch it's the right place because it also doubles as an embedding example. I'd be okay with just an Obviously Correct Looking(TM) code change. |
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix nodejs#47013
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix nodejs#47013
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013 PR-URL: #47188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013 PR-URL: #47188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013 PR-URL: #47188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013 PR-URL: #47188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013 PR-URL: #47188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
The only bad handler value we can inhert from before exec is SIG_IGN (any actual function pointer is reset to SIG_DFL during exec). If that's the case, we want to reset it back to SIG_DFL. However, it's also possible that an embeder (or an LD_PRELOAD-ed library) has set up own signal handler for own purposes (e.g. profiling). If that's the case, keep it intact. Fix #47013 PR-URL: #47188 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
Version
0c46051
Platform
Linux 5.19.11-amd64 #1 SMP x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
LD_PRELOAD or link in any library that sets a signal handler and schedules signal delivery (e.g. a posix timer).
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
The library handles own signals.
What do you see instead?
The program crashes.
Additional information
#615 added this code that resets all signal handlers to SIG_DFL:
node/src/node.cc
Lines 426 to 434 in 0c46051
This causes crashes is there is a signal handler installed.
While SIG_IGN can indeed be inherited across execve, all actual handlers (not SIG_IGN/DFL) are reset to SIG_DFL.
So I think the startup code should reset to SIG_DFL iff the handler is set of SIG_IGN. Any real handlers should be left intact.
@bnoordhuis @sam-github @melver
The text was updated successfully, but these errors were encountered: