[Profiler] workaround for stack overflow during nested signal handling (#177)#8162
Open
korniltsev-grafanista wants to merge 1 commit intoDataDog:masterfrom
Open
[Profiler] workaround for stack overflow during nested signal handling (#177)#8162korniltsev-grafanista wants to merge 1 commit intoDataDog:masterfrom
korniltsev-grafanista wants to merge 1 commit intoDataDog:masterfrom
Conversation
) There is a stack buffer overflow on the altstack when coreclr's SIGSEGV handler is interrupted by SIGPROF signal. Here is the trace from kernel (obtained with this tracer https://github.com/korniltsev-grafanista/signalsnoop ): rsp: 0x00007ee895e36b30 get_sigframe for tgid=974490 tid=974548 (.NET TP Worker), ret=0x7ee895e35f38 x64_setup_rt_frame failed for tgid=974490 tid=974548 (.NET TP Worker), sig=27, ret=-14 7ee895e36000-7ee895e39000 rw-p 00000000 00:00 0 // altstack This PR adds wrappers to sigaction and pthread_sigmask. sigaction masks SIGPROF if the signal is SIGSEGV - to prevent SIGSEGV stack overflow during signal delivering. pthread_sigmask unblocks SIGPROF if we are unblocking SIGSEGV - the runtime unblocks SIGSEGV, and we should unblock SIGPROF as well to allow the profiler continue working and delivering SIGPROF signals. Added an NPE class to Rideshare app for easier problem reproducing. // Copilot ignore this code, review the wrapper
Collaborator
|
👋 @korniltsev-grafanista , thanks for your contribution. |
Author
|
please do it, I don't really have capacity at the moment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a stack overflow on the altstack when coreclr's
SIGSEGVhandler is interrupted bySIGPROFsignal.Here is the trace from kernel (obtained with this vibecoded ebpf tracer https://github.com/korniltsev-grafanista/signalsnoop ):
Details
This PR adds wrappers to
sigactionandpthread_sigmask.sigactionmasksSIGPROFif the signal isSIGSEGV- to prevent SIGSEGV stack overflow during signal delivering.pthread_sigmaskunblocksSIGPROFif we are unblockingSIGSEGV- the runtime unblocks SIGSEGV, and we should unblockSIGPROFas well to allow the profiler continue working and deliveringSIGPROFsignals.This is the code I used to simplify reproducing - triggering null deref in managed code in a busy loop. https://github.com/grafana/pyroscope-dotnet/pull/177/files#diff-75c68efd0775648bc723a9557e3cc83a294c79852dc5dc2c733e8bb80e15a9fcR18
Disclaimer: the problem was initially reported by grafana user(using the fork https://github.com/grafana/pyroscope-dotnet) we then confirmed the same problem with the genuine (not fork) dd-trace-dotnet v0.34.0.
Summary of changes
Reason for change
Implementation details
Test coverage
Other details