This is an archive of the discontinued LLVM Phabricator instance.

[memprof] Fix use-after-free in peekBuildIds.
ClosedPublic

Authored by snehasish on Jul 12 2023, 12:59 PM.

Details

Summary

To check the uniqueness of buildids, we held on to a StringRef of the build id string pushed into the vector. If the number of build ids were large enough to trigger a realloc in the vector then these references where invalidated resulting in a use-after free. This was exposed in downstream usage.

Diff Detail

Event Timeline

snehasish created this revision.Jul 12 2023, 12:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 12:59 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
snehasish requested review of this revision.Jul 12 2023, 12:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 12:59 PM
tejohnson accepted this revision.Jul 12 2023, 1:59 PM

lgtm but you could also consider collapsing both BuildIds and BuildIdsSet into a single SetVector for conciseness.

This revision is now accepted and ready to land.Jul 12 2023, 1:59 PM

lgtm but you could also consider collapsing both BuildIds and BuildIdsSet into a single SetVector for conciseness.

I did consider this prior to sending out the patch. Since SetVector::takeVector return a SmallVector we need to either

  • create a new result std::vector prior to avoid changing the return type, negating the benefit
  • update the return type which breaks downstream usage and will need to be updated

Since this isn't performance critical I chose the simplest approach.

lgtm but you could also consider collapsing both BuildIds and BuildIdsSet into a single SetVector for conciseness.

I did consider this prior to sending out the patch. Since SetVector::takeVector return a SmallVector we need to either

  • create a new result std::vector prior to avoid changing the return type, negating the benefit
  • update the return type which breaks downstream usage and will need to be updated

Since this isn't performance critical I chose the simplest approach.

Ack - thanks for the explanation. Agree with the approach you chose.

This revision was landed with ongoing or failed builds.Jul 12 2023, 2:21 PM
This revision was automatically updated to reflect the committed changes.