Guard stackwalking in IXClrDataStackWalk codepaths to account for underlying max size of context#125819
Merged
Merged
Conversation
…derlying max size of context
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a memory-safety issue in CoreCLR DAC stackwalking (IXCLRDataStackWalk / IXCLRDataFrame) when callers provide a CONTEXT buffer larger than the underlying T_CONTEXT (e.g., AMD64 CONTEXT + appended XSTATE), which could previously cause out-of-bounds reads/writes during CopyMemory.
Changes:
- Cap
GetContextcopies tosizeof(T_CONTEXT)to avoid reading past the local context struct when callers supply oversized output buffers. - Cap
SetContext2copies tosizeof(m_context)to avoid overwriting adjacent fields when callers supply oversized input buffers (e.g., with XSTATE).
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
IXClrDataStackWalk methods don't take into account that the Windows context size is the one of the Windows SDK CONTEXT on AMD64. It does not include inline XSTATE. If some customer passes in XSTATE, ContextSizeForFlags always returns 0x4D0 regardless of context flag. So CheckContextSizeForBuffer always returns true. Then CopyMemory(&m_context, context, ...) will overrun for any XSTATE input and overwrite other fields.