-
Notifications
You must be signed in to change notification settings - Fork 80
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 when using split dwarf #141
Comments
Can you try with version 0.6.2? If you’re on centos 7 dladdr1 should exist but there was an issue with it not being selected properly in 0.6.1. |
On 0.6.2 the second problem ( |
Thanks, glad the other issue was resolved. A segfault is concerning, unfortunately I probably need to be able to repro to debug. I can spin up a centos 7 box later to try. Can you send the exact code you’re using just so I can be sure I am using the same setup? Another helpful data point, if it’s not too much work, would be to turn on address sanitizer (both for the library and binary) and see if it catches anything. To answer the question at the end of the issue:
Object information has to be resolved in order to get line info. For a given instruction pointer in runtime address space, cpptrace must figure out what object it came from (either the main executable or a library .so), then any runtime address randomization must be reversed, then any offsets from the ELF must be reversed, and only then can the appropriate debug information be looked up in the executable/library object. |
I setup a centos 7 VM but was unable to reproduce. I used devtoolset-10 while testing. |
Here are my results.
|
UPD: I added the same options as in prod to the simple project and now sanitizer triggering on heap-use-after-free. |
This information is immensely helpful, thanks so much for taking the time to look into this. It's especially helpful to know it might be an issue in the split dwarf code path. Something does definitely seem wrong so I'll try to understand what's going on here. |
I'm was able to reproduce a sanitizer error in your setup doing a RelWithDebInfo build. I built cpptrace with sanitizers and then used a trimmed cmake file:
I realized the issue, it's a very subtle issue with destructors I'd ran into previously but didn't handle with split dwarf. Fix should be the following, will commit later diff --git a/src/symbols/dwarf/dwarf_resolver.cpp b/src/symbols/dwarf/dwarf_resolver.cpp
index 7627cd6..1c47a17 100644
--- a/src/symbols/dwarf/dwarf_resolver.cpp
+++ b/src/symbols/dwarf/dwarf_resolver.cpp
@@ -208,6 +208,8 @@ namespace libdwarf {
}
// subprograms_cache needs to be destroyed before dbg otherwise there will be another use after free
subprograms_cache.clear();
+ split_full_cu_resolvers.clear();
+ skeleton.reset();
if(aranges) {
dwarf_dealloc(dbg, aranges, DW_DLA_LIST);
} |
It seems that fixes the heap-use-after-free issue.
and then hundreds of The given path and file |
Hi, there’s a chance this could be related to an upstream libdwarf issue regarding how rangelists are handled. Does item 5 happen when you haven’t pulled cpptrace into your project directly and instead link to a copy built elsewhere? |
Two issues occurred when I tried to use the library for a big project on Linux.
Maybe they depend on each other, but maybe don't.
The project is built on CentOS Linux 7, using gcc-11.2 and is statically linked.
1. Coredump
Do nothing special. Just try to get stacktrace.
2. Fail to read object file.
The same
generate_trace
call reports multiple errorsCpptrace internal error: Unable to read object file main
before core.Although I'm not able to enter by debugger inside of cpptrace (no matter if it was built in ReleaseWithDebug or Debug or Release mode), its modification reveals that this happened inside of the
#else
branch ofobject.cpp
(!defined(CPPTRACE_HAS_DL_FIND_OBJECT) && !defined(HAS_DLADDR1)
"main" is what is mentioned in the CmakeList.txt in
target_link_libraries(main ....)
and the name of the directory.It is also mentioned by the
boost::stacktrace
output (... in main
) for that stacktrace.But no "main" file exists at all, and moreover, in the current directory, the executable has a different name (
cserver
).I'm not interested in object file information, but I'm interested in the line information.
I'm not sure why this info is needed and if the library will still be workable without loading object files.
The text was updated successfully, but these errors were encountered: