This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Fix use-after-free in RewriteInstance::mapCodeSections
ClosedPublic

Authored by jobnoorman on Apr 15 2023, 5:36 AM.

Details

Summary

When a cold function is too large, its section gets deregistered.
However, the section is still dereferenced later to get its RuntimeDyld
ID. This patch moves the deregistration to after the last dereference.

Note that this came up in D147544 and I haven't found a way to actually
trigger this bug (i.e., I'm not sure how to create a cold function
that's considered "too large"). I tried to resolve the issue without
affecting BOLT's behavior but there might be better ways to solve it
(e.g., not deregistering, not mapping the deregistered section in
RuntimeDyld?).

Diff Detail

Event Timeline

jobnoorman created this revision.Apr 15 2023, 5:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 5:36 AM
jobnoorman requested review of this revision.Apr 15 2023, 5:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 5:36 AM
Amir accepted this revision.Apr 17 2023, 5:08 AM

Good catch!

This revision is now accepted and ready to land.Apr 17 2023, 5:08 AM
Amir added a comment.Apr 17 2023, 5:09 AM

Please remove "[NFC]" from title as bugfix is a functional change

jobnoorman retitled this revision from [BOLT][NFC] Fix use-after-free in RewriteInstance::mapCodeSections to [BOLT] Fix use-after-free in RewriteInstance::mapCodeSections.Apr 17 2023, 5:54 AM
This revision was landed with ongoing or failed builds.Apr 17 2023, 7:17 AM
This revision was automatically updated to reflect the committed changes.