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

Not all modules were added to the modules list resulting in <unknown> stack traces #948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/modulefinder/sentry_modulefinder_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,17 +602,6 @@ get_linux_vdso(void)
return 0;
}

static bool
is_valid_elf_header(void *start)
{
unsigned char e_ident[EI_NIDENT];
if (!read_safely(e_ident, start, EI_NIDENT)) {
return false;
}
return e_ident[EI_MAG0] == ELFMAG0 && e_ident[EI_MAG1] == ELFMAG1
&& e_ident[EI_MAG2] == ELFMAG2 && e_ident[EI_MAG3] == ELFMAG3;
}

static void
load_modules(sentry_value_t modules)
{
Expand Down Expand Up @@ -669,8 +658,9 @@ load_modules(sentry_value_t modules)
break;
}

// skip mappings that are not readable
if (!module.start || module.permissions[0] != 'r') {
// skip mappings that are not readable/executable
if (!module.start
|| (module.permissions[0] != 'r' && module.permissions[2] != 'x')) {
continue;
}
// skip mappings in `/dev/` or mappings that have no filename
Expand All @@ -687,7 +677,14 @@ load_modules(sentry_value_t modules)
continue;
}

if (is_valid_elf_header((void *)(size_t)module.start)) {
// Module is appended if next module has different file name
if ((!last_module.file.len
&& (!module.file.len || last_module.file.len != module.file.len
|| memcmp(last_module.file.ptr, module.file.ptr,
module.file.len)))
|| (!module.file.len || last_module.file.len != module.file.len
|| memcmp(
last_module.file.ptr, module.file.ptr, module.file.len))) {
Comment on lines +681 to +687
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use !sentry__slice_eq(module.file, last_module.file) here to make this more readable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key here is that the ELF check must be removed. Not all memory areas are valid ELF binaries. It doesn't make sense to search for ELF header of the next memory area as a condition to add a module to the list. Quite often there's anonymous memory areas between loaded libraries, and in such case the original code doesn't work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sc-aki. Can you provide an example of such a memory map (or just a few entries that visualize the problem)?

Not all memory areas are valid ELF binaries.

But do they still contain valid ELF code referenced from the stack trace?

Quite often there's anonymous memory areas between loaded libraries, and in such case the original code doesn't work.

Yes, in these cases, we would ignore that map entry. Are you saying that you have anonymous entries that contain code that your stack trace is referencing? How do you ensure the code is readable in the backend symbolication?

Wouldn't this ignore anonymous map entries as well: https://github.com/getsentry/sentry-native/blob/master/src/modulefinder/sentry_modulefinder_linux.c#L677-L681

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you ensure the code is readable in the backend symbolication?

Or is this change only meant for Android (where symbolication happens in the client)?

// clang-format off
// On android, we sometimes have multiple mappings for the
// same inode at the same offset, such as this:
Expand Down
Loading