-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-nm] Fix heap-use-after-free while executing 'llvm-nm -n --export-symbols' #65668
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
Conversation
Is there a test covering this case? |
@tstellar It seems that https://github.com/orgs/llvm/teams/pr-subscribers-llvm-binary-utilities cannot be added as a reviewer. Perhaps the team hasn't been properly set? |
No. I'm not sure what would be a good test for this. I can add a test that just run |
@llvm/pr-subscribers-llvm-binary-utilities ChangesUse symbol's flags saved in Here is the AddressSanitizer report:
-- 1 Files Affected:
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index 79213b3b2c27e31..8ac7eb2a825b57e 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -237,10 +237,8 @@ struct NMSymbol { std::string IndirectName; bool isDefined() const { - if (Sym.getRawDataRefImpl().p) { - uint32_t Flags = cantFail(Sym.getFlags()); - return !(Flags & SymbolRef::SF_Undefined); - } + if (Sym.getRawDataRefImpl().p) + return !(SymFlags & SymbolRef::SF_Undefined); return TypeChar != 'U'; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is purely code simplification, I think this is fine.
…t-symbols' Use symbol's flags saved in NMSymbol::SymFlags inside NMSymbol::isDefined() since BasicSymbolRef::getFlags() requires the symbol's containing entity object to exist (which doesn't, causing llvm-nm to crash). Here is the AddressSanitizer report: ==3324663==ERROR: AddressSanitizer: heap-use-after-free on address 0x60e000000200 READ of size 8 at 0x60e000000200 thread T0 #0 0x55c6536785d8 in llvm::object::BasicSymbolRef::getFlags() const llvm-project/llvm/include/llvm/Object/SymbolicFile.h:207:24 llvm#1 0x55c6536785d8 in (anonymous namespace)::NMSymbol::isDefined() const llvm-project/llvm/tools/llvm-nm/llvm-nm.cpp:241:37
a270f38
to
0f12a7a
Compare
…t-symbols' (llvm#65668) Use symbol's flags saved in `NMSymbol::SymFlags` inside `NMSymbol::isDefined()` since `BasicSymbolRef::getFlags()` requires the symbol's containing entity object to exist (which doesn't, causing llvm-nm to crash).
Use symbol's flags saved in
NMSymbol::SymFlags
insideNMSymbol::isDefined()
sinceBasicSymbolRef::getFlags()
requires the symbol's containing entity object to exist (which doesn't, causing llvm-nm to crash).Here is the AddressSanitizer report: