-
-
Notifications
You must be signed in to change notification settings - Fork 184
Description
Description
Crashes in get_code_id_from_text_fallback
when sentry_value_new_stacktrace(nullptr, 0)
is called
But also, whenever a debug symbol hash is calculated for any module that doesn't have a build-id
Caused by #431
Fundamental cause of this issue, is that a module is read from memory, instead of from the actual file (pre #431), and the mapped memory does not point to the assumed data. The crash happens when the offset for the section headers just happens to match one of the section's mappings in the module itself, so rubbish data is loaded.
This is exactly as the pre #431 code warned:
// At least on the android API-16, x86 simulator, the linker apparently
// does not load the complete file into memory. Or at least, the section
// headers which are located at the end of the file are not loaded, and
// we would be poking into invalid memory. To be safe, we mmap the complete
// file from disk, so we have the on-disk layout, and are independent of how
// the runtime linker would load or re-order any sections. The exception
// here is the linux-gate, which is not an actual file on disk, so we
// actually poke at its memory.
sentry_modulefinder_linux.c
get_code_id_from_text_fallback
for (int i = 0; i < elf.e_shnum; i++) {
Elf32_Shdr header;
ENSURE(sentry__module_read_safely(&header, module,
elf.e_shoff + elf.e_shentsize * i, sizeof(Elf32_Shdr))); // <--- header is read from invalid memory, so is rubbish
const char *name = names + header.sh_name; // <--- header.sh_name is rubbish (and is large)
if (header.sh_type == SHT_PROGBITS && strcmp(name, ".text") == 0) { // <--- segfault here since name is out of bonds
text = sentry__module_get_addr(
module, header.sh_offset, header.sh_size);
ENSURE(text);
text_size = header.sh_size;
break;
}
}
When does the problem happen
- During build
- During run-time
- When capturing a hard crash
Environment
- OS: Arm32 - Custom Embedded Linux (kernel: 5.10.87 - SMP PREEMPT_RT - armv7l GNU/Linux)
- Compiler: GCC 10.3.0 Crosscompiler
- CMake version and config: 3.22.1 (
-DSENTRY_BACKEND=crashpad
) - sentry version 0.4.12
Steps To Reproduce
random, as dependent on loaded modules not having a build-id, and if their elf section headers overlap with one of their internal elf section file mappings