Skip to content

Check for SIG_IGN and SIG_DFL before calling previous signal handler - #132900

Merged
jtschuster merged 3 commits into
dotnet:mainfrom
jtschuster:runtime-repro-mac-execve-issue
Sep 3, 2026
Merged

Check for SIG_IGN and SIG_DFL before calling previous signal handler#132900
jtschuster merged 3 commits into
dotnet:mainfrom
jtschuster:runtime-repro-mac-execve-issue

Conversation

@jtschuster

Copy link
Copy Markdown
Member

macOS doesn't clear sa_flags when calling execve. When dotnet is started from a process that sets a signal handler, the handler is cleared, but not the sa_flags. When the runtime gets a signal from an external source, it sees a stale SA_SIGINGO and tries to call the previous signal handler, but the pointer is set to SIG_IGN or SIG_DFL, which causes a crash. This change checks for those values before calling the previous signal handler. Also adds a regression test for the issue.

Fixes #132581

macOS doesn't clear sa_flags when calling execve. When dotnet is started from a
process that sets a signal handler, the handler is cleared, but not the
sa_flags. When the runtime gets a signal from an external source, it sees a
stale SA_SIGINGO and tries to call the previous signal handler, but the pointer
is set to SIG_IGN or SIG_DFL, which causes a crash. This change checks for those
values before calling the previous signal handler.
Add a regression test for the issue.
@jtschuster jtschuster added this to the 11.0.0 milestone Aug 28, 2026
@jtschuster jtschuster self-assigned this Aug 28, 2026
Copilot AI lite review requested due to automatic review settings August 28, 2026 18:00
@jtschuster jtschuster added the os-mac-os-x macOS aka OSX label Aug 28, 2026
@jtschuster
jtschuster requested review from agocke and janvorli August 28, 2026 18:01
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@jtschuster
jtschuster requested a review from a team August 28, 2026 18:01
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens CoreCLR and NativeAOT activation-signal chaining by ensuring the runtime does not attempt to call a previous signal “handler” when the saved disposition is actually SIG_DFL or SIG_IGN, even if SA_SIGINFO is set (a state observed on macOS across execve). It also adds a macOS-only regression test that reproduces the inherited SA_SIGINFO + default/ignored disposition scenario and validates the runtime remains stable when an external SIGUSR1 arrives.

Changes:

  • CoreCLR: gate chaining to the saved activation signal disposition behind IsSigDfl/IsSigIgn checks before calling either sa_sigaction or sa_handler.
  • NativeAOT: apply the same SIG_DFL / SIG_IGN guard to activation handler chaining when SA_SIGINFO is set.
  • Tests: add a macOS-only regression test that installs an SA_SIGINFO handler, execvs into the .NET process, then triggers an external SIGUSR1 to exercise the chaining path.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/pal/src/exception/signal.cpp Prevents calling the previous activation handler when it’s SIG_DFL/SIG_IGN, regardless of stale SA_SIGINFO.
src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp Mirrors the same SIG_DFL/SIG_IGN guard for NativeAOT’s activation handler chaining.
src/tests/Regressions/coreclr/GitHub_132581/test132581.csproj Adds a macOS-only, process-isolated regression test project with a native CMake dependency.
src/tests/Regressions/coreclr/GitHub_132581/test132581.cs Managed test that execvs after installing the signal handler and then triggers an external SIGUSR1.
src/tests/Regressions/coreclr/GitHub_132581/nativetest132581.cpp Native helper to install the SA_SIGINFO handler + execv, and to send SIGUSR1 from a forked child.
src/tests/Regressions/coreclr/GitHub_132581/CMakeLists.txt Builds/installs the native helper library on macOS only.

Comment thread src/tests/Regressions/coreclr/GitHub_132581/test132581.csproj Outdated
Comment thread src/tests/Regressions/coreclr/GitHub_132581/test132581.csproj
Comment thread src/tests/Regressions/coreclr/GitHub_132581/test132581.csproj
Clarify why the test is RequiresProcessIsolation.
Add more descriptive method / class names to test code.
Copilot AI review requested due to automatic review settings August 31, 2026 16:54
@jtschuster

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Comment thread src/tests/Regressions/coreclr/GitHub_132581/test132581.csproj Outdated
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copilot AI review requested due to automatic review settings September 1, 2026 19:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@jtschuster
jtschuster enabled auto-merge (squash) September 3, 2026 16:01
@jtschuster

Copy link
Copy Markdown
Member Author

/ba-g Failures are an unrelated QUIC failure and #132947

@jtschuster
jtschuster disabled auto-merge September 3, 2026 16:03
@jtschuster
jtschuster merged commit 685a287 into dotnet:main Sep 3, 2026
112 of 115 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Sep 3, 2026
@jtschuster

Copy link
Copy Markdown
Member Author

/backport to release/11.0-rc1

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-rc1 (link to workflow run)

@jtschuster

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

JulieLeeMSFT pushed a commit that referenced this pull request Sep 4, 2026
…signal handler (#133177)

Backport of #132900 to release/10.0

/cc @jtschuster

## Customer Impact

- [X] Customer reported
- [ ] Found internally

macOS doesn't clear sa_flags when calling execve. When dotnet is started
from a process that sets a signal handler, the handler is cleared, but
not the sa_flags. When the runtime gets a signal from an external
source, it sees a stale SA_SIGINGO and tries to call the previous signal
handler, but the pointer is set to SIG_IGN or SIG_DFL, which causes a
segmentation fault and crashes the process. This change checks for those
values before calling the previous signal handler. Also adds a
regression test for the issue.

## Regression

- [ ] Yes
- [X] No

## Testing

The issue was reproduced in a regression test that was added to coreclr
tests. The test fails without the fix and passes with it.

## Risk

Low. The actual source change is small and targeted.

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

macOS: activation signal handler calls through a NULL pointer when SIGUSR1 is inherited with SA_SIGINFO + SIG_DFL

5 participants