Skip to content

Fix PAL alternate signal stack leak after application reconfiguration - #136883

Open
jkotas with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-signal-stack-leak
Open

jkotas with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-signal-stack-leak

Conversation

Copilot AI commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Thread teardown leaks the PAL-allocated alternate signal stack when application code replaces or disables its registration.

  • Ownership: Save the allocation size alongside the PAL-owned pointer.
  • Cleanup: Unmap that allocation regardless of the current registration, without unmapping a foreign stack.

Fixes #136853

@azure-pipelines

azure-pipelines Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 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.

@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.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix alternate signal stack leak during thread shutdown Fix PAL alternate signal stack leak after application reconfiguration Nov 2, 2026
Copilot AI requested a review from jkotas November 2, 2026 23:25
@jkotas
jkotas marked this pull request as ready for review November 2, 2026 23:27
@jkotas
jkotas requested a review from janvorli November 2, 2026 23:27
Comment thread src/coreclr/pal/src/thread/thread.cpp Resolved
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@jkotas
jkotas requested review from janvorli and a balanced review from Copilot November 3, 2026 17:08

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.

🟡 Changes recommended

The cleanup change lacks Unix regression coverage with signal handling enabled to verify PAL mapping release and preservation of foreign mappings and registrations across unchanged, disabled, and replacement stack registrations.

1 open issue
What changed in this PR

Fixes the CoreCLR PAL alternate signal stack leak described in #136853 when application code replaces or disables the stack registration before thread teardown.

Changes:

  • Tracks the PAL-owned allocation size alongside its pointer.
  • Unmaps the owned allocation independently of the current registration.
  • Disables the registered stack only when it matches the PAL-owned stack, preserving foreign stacks.
File Description
src/​coreclr/​pal/​src/​thread/​thread.cpp Records allocation size and separates owned-memory cleanup from stack registration.
src/​coreclr/​pal/​src/​include/​pal/​thread.hpp Adds and initializes the alternate stack allocation-size field.

Review effort: Balanced

Comment thread src/coreclr/pal/src/thread/thread.cpp Resolved

@janvorli janvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

@jkotas
jkotas enabled auto-merge (squash) November 3, 2026 17:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alternate signal stack allocated during thread start is leaked if the signal stack is reconfigured by application code

5 participants