Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use after free in CodeGenPrepare::optimizeInst() #42366

Closed
beccadax opened this issue Aug 16, 2019 · 4 comments
Closed

Use after free in CodeGenPrepare::optimizeInst() #42366

beccadax opened this issue Aug 16, 2019 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm:codegen

Comments

@beccadax
Copy link
Contributor

Bugzilla Link 43021
Resolution FIXED
Resolved on Aug 20, 2019 02:45
Version trunk
OS All
Blocks #41819
CC @zmodem,@LebedevRI,@RKSimon
Fixed by commit(s) r369168

Extended Description

The OptimizeExtractBits() helper function in CodeGenPrepare.cpp is meant to replace certain uses of "lshr" and "ashr" instructions, then erase the original instruction if it is no longer used anywhere. It returns a flag indicating whether it made a change. However, it only sets that flag to "true" when it replaces an instruction. If it is passed an instruction that does not have any users to begin with, it will erase it and still return "false".

This behavior was previously harmless, but rL363511 changed OptimizeExtractBits()'s call site in CodeGenPrepare::optimizeInst() to allow processing of the instruction to continue if OptimizeExtractBits() returns false. The result is that CodeGenPrepare::optimizeInst() continues working on the instruction even though it has been freed. This can cause occasional, unpredictable crashes in normal builds, but it crashes reliably under ASAN.

I've prepared a test case and fix for this issue at https://reviews.llvm.org/D66330.

@beccadax
Copy link
Contributor Author

assigned to @beccadax

@RKSimon
Copy link
Collaborator

RKSimon commented Aug 18, 2019

Committed to trunk at rL369168

@LebedevRI
Copy link
Member

(still needs to be cherry-picked i think)

@zmodem
Copy link
Collaborator

zmodem commented Aug 20, 2019

Merged in r369355.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:codegen
Projects
None yet
Development

No branches or pull requests

4 participants