Skip to content

PlatformInit resets signal handlers to SIG_DFL causing crashes #47013

@dvyukov

Description

@dvyukov

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

// The hard-coded upper limit is because NSIG is not very reliable; on Linux,
// it evaluates to 32, 34 or 64, depending on whether RT signals are enabled.
// Counting up to SIGRTMIN doesn't work for the same reason.
for (unsigned nr = 1; nr < kMaxSignal; nr += 1) {
if (nr == SIGKILL || nr == SIGSTOP)
continue;
act.sa_handler = (nr == SIGPIPE || nr == SIGXFSZ) ? SIG_IGN : SIG_DFL;
CHECK_EQ(0, sigaction(nr, &act, nullptr));
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions