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 ASAN issue #959

Merged
merged 1 commit into from
Nov 14, 2022
Merged

Fix ASAN issue #959

merged 1 commit into from
Nov 14, 2022

Conversation

rui314
Copy link
Contributor

@rui314 rui314 commented Nov 12, 2022

Description

ASAN reports an error if we try to downcast a misaligned address. To avoid it, we need to check if an address is valid before casting it.

Here is the ASAN error:

/home/runner/work/mold/mold/third-party/tbb/src/tbb/../../include/tbb/../oneapi/tbb/concurrent_hash_map.h:446:23: runtime error: downcast of misaligned address 0x000000000003 for type 'tbb::detail::d2::hash_map_iterator<tbb::detail::d2::concurrent_hash_map<std::basic_string_view<char, std::char_traits>, std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator>, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator>>>, tbb::detail::d1::tbb_hash_compare<std::basic_string_view<char, std::char_traits>>, tbb::detail::d1::tbb_allocator<std::pair<const std::basic_string_view<char, std::char_traits>, std::vector<std::__cxx11::basic_string<char, std::char_traits, std::allocator>, std::allocator<std::__cxx11::basic_string<char, std::char_traits, std::allocator>>>>>>, std::pair<const std::basic_string_view<char, std::char_traits>, std::vector<std::__cxx11::basic_string<char, std::char_traits, st0x000000000003: note: pointer points here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/runner/work/mold/mold/third-party/tbb/src/tbb/../../include/tbb/../oneapi/tbb/concurrent_hash_map.h:446:23

  • - git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details)

Type of change

Choose one or multiple, leave empty if none of the other choices apply

Add a respective label(s) to PR if you have permissions

  • bug fix - change that fixes an issue
  • new feature - change that adds functionality
  • tests - change in tests
  • infrastructure - change in infrastructure and CI
  • documentation - documentation update

Tests

  • added - required for new features and some bug fixes
  • not needed

Documentation

  • updated in # - add PR number
  • needs to be updated
  • not needed

Breaks backward compatibility

  • Yes
  • No
  • Unknown

ASAN report an error if we tries to downcast a misaligned address.
To avoid it, we need to check if an address is valid before casting it.

Here is the ASAN error:

/home/runner/work/mold/mold/third-party/tbb/src/tbb/../../include/tbb/../oneapi/tbb/concurrent_hash_map.h:446:23: runtime error: downcast of misaligned address 0x000000000003 for type 'tbb::detail::d2::hash_map_iterator<tbb::detail::d2::concurrent_hash_map<std::basic_string_view<char, std::char_traits<char>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, tbb::detail::d1::tbb_hash_compare<std::basic_string_view<char, std::char_traits<char>>>, tbb::detail::d1::tbb_allocator<std::pair<const std::basic_string_view<char, std::char_traits<char>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>>>, std::pair<const std::basic_string_view<char, std::char_traits<char>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, st0x000000000003: note: pointer points here
<memory cannot be printed>
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/runner/work/mold/mold/third-party/tbb/src/tbb/../../include/tbb/../oneapi/tbb/concurrent_hash_map.h:446:23

Signed-off-by: Rui Ueyama <ruiu@cs.stanford.edu>
@phprus
Copy link
Contributor

phprus commented Nov 12, 2022

Related issue: #908

Copy link
Contributor

@kboyarinov kboyarinov left a comment

Choose a reason for hiding this comment

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

LGTM

@kboyarinov kboyarinov merged commit 4146a9e into uxlfoundation:master Nov 14, 2022
@stephen-yee-adsk
Copy link

Hi,

Is the same fix required in the hash_map_iterator constructor?

The node_base* n given as an argument to the constructor is static_cast-ed to a node* in the initialization of my_node, without checking if its valid first.

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.

4 participants