From 07cb9ef7bc9d4a831d89e6497b44b7221b5f248f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 21 Mar 2023 14:01:54 +0100 Subject: [PATCH] src: don't reset embeder signal handlers 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 --- src/node.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/node.cc b/src/node.cc index 2aba7333d92513..5874494ba966cc 100644 --- a/src/node.cc +++ b/src/node.cc @@ -430,6 +430,18 @@ void ResetSignalHandlers() { if (nr == SIGKILL || nr == SIGSTOP) continue; act.sa_handler = (nr == SIGPIPE || nr == SIGXFSZ) ? SIG_IGN : SIG_DFL; + if (act.sa_handler == SIG_DFL) { + // 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, we want to keep it intact. + struct sigaction old; + CHECK_EQ(0, sigaction(nr, nullptr, &old)); + if ((old.sa_flags & SA_SIGINFO) || old.sa_handler != SIG_IGN) + continue; + } CHECK_EQ(0, sigaction(nr, &act, nullptr)); } #endif // __POSIX__