[EventPipe] Fix user_events metadata label scope#118474
Merged
mdh1418 merged 1 commit intodotnet:mainfrom Aug 7, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a critical memory corruption bug in the EventPipe session tracepoint writing functionality. The issue was caused by a stack-allocated variable going out of scope during a writev operation, leading to potential data corruption in the first 5 bytes of metadata extensions.
Key changes:
- Move stack variable declaration to correct scope to prevent memory corruption
- Ensure metadata extension buffer remains valid during
writevsystem call
lateralusX
approved these changes
Aug 7, 2025
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.
Alternate internal testing showed that the first 5 bytes of the metadata extension were zeroed out. I missed that the stack allocated variable corresponding to the metadata label + metadata size would be out of scope during the writev, and thus prone to corruption.
The corruption never occurred during my manual testing which read the values from sys/kernel/tracing/trace.