[PLAT-7010 ] Fix strlen crash in bsg_ksmachgetThreadQueueName #1157
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.
Goal
Fixes a (rare) crash in
bsg_ksmachgetThreadQueueName
when callingstrlen
for a dispatch queue label.Analysis
When a thread is being destroyed, its
dispatch_queue
's memory may be deallocated (and reused for something else) whilebsg_ksmachgetThreadQueueName
is executing, resulting in callingdispatch_queue_get_label
with an invalid pointer.Previous fixes ensured that the
dispatch_queue
points to readable memory, but sincedispatch_queue_get_label
simply returns a pointer from an offset into the struct, an invalid pointer could be returned that would causestrlen
to crash.Changeset
vm_read_overwrite
is now used to safely read from the pointer returned bydispatch_queue_get_label
.Testing
A unit test case has been added that is able to reliably reproduce the crash (without the fix in place) when
MallocScribble
is enabled.See https://buildkite.com/bugsnag/bugsnag-cocoa/builds/3068 for positive detection of the crash without the fix in place.