Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Fixes**:

- Linux/ARM32: prevent recursive crashes when libunwind receives an unmapped initial instruction pointer during crash handling. ([#1977](https://github.com/getsentry/sentry-native/pull/1977))

## 0.16.3

**Features**:
Expand Down
6 changes: 6 additions & 0 deletions src/unwinder/sentry_unwinder_libunwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ sentry__unwind_stack_libunwind(
if (n < max_frames) {
ptrs[n++] = (void *)ip;
}

mem_range_t code = { 0, 0 };
if (uctx && !find_mem_range((uintptr_t)ip, &code)) {
return n;
}

unw_word_t sp = 0;
(void)unw_get_reg(&cursor, UNW_REG_SP, &sp);

Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_unwinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# include "unwinder/sentry_unwinder.h"
# include <fcntl.h>
# include <unistd.h>
# if defined(__arm__)
# define UNW_LOCAL_ONLY
# include <libunwind.h>
# endif
extern bool find_mem_range_from_fd(int fd, uintptr_t ptr, mem_range_t *range);
#endif

Expand Down Expand Up @@ -103,6 +107,29 @@ SENTRY_TEST(unwinder)
}
}

SENTRY_TEST(unwinder_unmapped_ip)
{
#if !defined(SENTRY_WITH_UNWINDER_LIBUNWIND) || !defined(__arm__)
SKIP_TEST();
#else
int stack_var = 0;
// libunwind uses its own register-array context on ARM.
unw_context_t unwind_context = { 0 };
unwind_context.regs[13] = (uintptr_t)&stack_var;
unwind_context.regs[15] = 0x10c;

sentry_ucontext_t context = { 0 };
context.user_context = (ucontext_t *)&unwind_context;

void *backtrace[2] = { 0 };
size_t frame_count
= sentry_unwind_stack_from_ucontext(&context, backtrace, 2);

TEST_CHECK_INT_EQUAL(frame_count, 1);
TEST_CHECK_PTR_EQUAL(backtrace[0], (void *)(uintptr_t)0x10c);
#endif
}

SENTRY_TEST(find_mem_range)
{
#if !defined(SENTRY_WITH_UNWINDER_LIBUNWIND)
Expand Down
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ XX(uint128_struct_size)
XX(uninitialized)
XX(unsampled_spans)
XX(unwinder)
XX(unwinder_unmapped_ip)
XX(update_from_header_no_sampled_flag)
XX(update_from_header_null_ctx)
XX(update_release_and_environment_late)
Expand Down
Loading