This is an archive of the discontinued LLVM Phabricator instance.

Fix use-after-free in CodeGenPrepare
ClosedPublic

Authored by beccadax on Aug 15 2019, 7:38 PM.

Details

Summary

If OptimizeExtractBits() encountered a shift instruction with no operands at all, it would erase the instruction, but still return false. This previously didn’t matter because its caller would always return after processing the instruction, but https://reviews.llvm.org/D63233 changed the function’s caller to fall through if it returned false, which would then cause a use-after-free detectable by ASAN.

This change makes OptimizeExtractBits return true if it removes a shift instruction with no users, terminating processing of the instruction.

Diff Detail

Repository
rL LLVM

Event Timeline

beccadax created this revision.Aug 15 2019, 7:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2019, 7:38 PM
lebedev.ri accepted this revision.Aug 15 2019, 11:47 PM
lebedev.ri added a subscriber: tstellar.

Please file a blocker bug for https://bugs.llvm.org/show_bug.cgi?id=42474, this sounds 9.0-worthy.
This looks obviously correct (C), but wait a bit in case anyone else wants to comment.

This revision is now accepted and ready to land.Aug 15 2019, 11:47 PM
spatel accepted this revision.Aug 16 2019, 7:42 AM

LGTM - in D63233, I added a TODO that I've marked here for reference, but this appears to be a minimal/safe fix.

llvm/lib/CodeGen/CodeGenPrepare.cpp
7019 ↗(On Diff #215530)

Alternative to this patch: act on that TODO.

beccadax marked an inline comment as done.Aug 16 2019, 1:42 PM
beccadax added inline comments.
llvm/lib/CodeGen/CodeGenPrepare.cpp
7019 ↗(On Diff #215530)

Even if I did act on the TODO, I think we would still need the fix in this patch to avoid calling optimizeShiftInst() with the freed instruction.

@spatel @lebedev.ri I don't have commit access, so could one of you commit this when you think it's had enough time for comments?

This revision was automatically updated to reflect the committed changes.