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

Fix table indexing in dwarf_search_unwind_table #308

Merged
merged 1 commit into from
Nov 26, 2021

Conversation

ararslan
Copy link
Contributor

@ararslan ararslan commented Nov 6, 2021

table_len is used as an index into table, assuming it represents the number of entries. However, it is defined as the number of entries multiplied by sizeof(unw_word_t). This is accounted for in other places that use table_len, e.g. in lookup, which divides out the size of unw_word_t, but the indexing expression uses table_len directly. So when table has say 2 entries, we're actually looking at index 15 rather than 1 in the comparison. This can cause the conditional to erroneously evaluate to true, allowing the following line to segfault.

This was observed with JIT compiled code from Julia with LLVM on FreeBSD. It manifested as JuliaLang/julia#41943. Unfortunately we weren't able to come up with a minimal reproducer, as it happened seemingly sporadically in the Julia tests.

cc @vtjnash

`table_len` is used as an index into `table`, assuming it represents the
number of entries. However, it is defined as the number of entries
multiplied by `sizeof(unw_word_t)`. This is accounted for in other
places that use `table_len`, e.g. in `lookup`, which divides out the
size of `unw_word_t`, but the indexing expression uses `table_len`
directly. So when `table` has say 2 entries, we're actually looking at
index 16 rather than 2 in the comparison. This can cause the conditional
to erroneously evaluate to true, allowing the following line to
segfault.

This was observed with JIT compiled code from Julia with LLVM on
FreeBSD.

Co-Authored-By: Jameson Nash <vtjnash@gmail.com>
@djwatson
Copy link
Member

Awesome, thanks! Nice find.

@djwatson djwatson merged commit 8b3832f into libunwind:master Nov 26, 2021
@ararslan ararslan deleted the aa/table_len branch November 29, 2021 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants