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 false positive case #5742

Merged
merged 7 commits into from
Aug 31, 2022
Merged

*: fix asan false positive case #5742

merged 7 commits into from
Aug 31, 2022

Conversation

solotzg
Copy link
Contributor

@solotzg solotzg commented Aug 31, 2022

What problem does this PR solve?

Issue Number: ref #5294

Problem Summary:

https://ci.pingcap.net/blue/rest/organizations/jenkins/pipelines/tiflash-sanitizer-daily/runs/486/nodes/83/steps/87/log/?start=0

[2022-08-30T19:21:23.463Z] ==10469==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffe30dca61f at pc 0x000000490b4f bp 0x7ffe30dca550 sp 0x7ffe30dca548
[2022-08-30T19:21:23.463Z] READ of size 32 at 0x7ffe30dca61f thread T0
[2022-08-30T19:21:23.463Z]     #0 0x490b4e in mem_utils::details::load_block32(void const*) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/include/common/avx2_mem_utils.h:66:12
[2022-08-30T19:21:23.463Z]     #1 0x490b4e in mem_utils::details::get_block32_cmp_eq_mask(void const*, long long vector[4] const&) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/include/common/avx2_strstr.h:34:24
[2022-08-30T19:21:23.463Z]     #2 0x490b4e in char const* mem_utils::details::avx2_strstr_impl<mem_utils::details::avx2_memchr(char const*, unsigned long, char)::'lambda'(char const*)>(char const*, char, long, mem_utils::details::avx2_memchr(char const*, unsigned long, char)::'lambda'(char const*)&&) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/include/common/avx2_strstr.h:139:21
[2022-08-30T19:21:23.463Z]     #3 0x490b4e in mem_utils::details::avx2_memchr(char const*, unsigned long, char) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/include/common/avx2_strstr.h:267:12
[2022-08-30T19:21:23.463Z]     #4 0x490b4e in mem_utils::avx2_memchr(char const*, unsigned long, char) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/src/avx2_mem_utils_impl.cpp:46:12
[2022-08-30T19:21:23.463Z]     #5 0x42ab3b in TestFunc(unsigned long) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/src/tests/gtest_mem_utils_opt.cpp:40:5
[2022-08-30T19:21:23.463Z]     #6 0x42ea67 in MemUtilsTestOPT_CompareNormal_Test::TestBody() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/libs/libcommon/src/tests/gtest_mem_utils_opt.cpp:85:9
[2022-08-30T19:21:23.464Z]     #7 0x523750 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2443:10
[2022-08-30T19:21:23.464Z]     #8 0x523750 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2479:14
[2022-08-30T19:21:23.464Z]     #9 0x4c1158 in testing::Test::Run() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2517:5
[2022-08-30T19:21:23.464Z]     #10 0x4c42e7 in testing::TestInfo::Run() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2693:11
[2022-08-30T19:21:23.464Z]     #11 0x4c585f in testing::TestCase::Run() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2811:28
[2022-08-30T19:21:23.464Z]     #12 0x4f0278 in testing::internal::UnitTestImpl::RunAllTests() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:5177:43
[2022-08-30T19:21:23.464Z]     #13 0x525e20 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2443:10
[2022-08-30T19:21:23.464Z]     #14 0x525e20 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:2479:14
[2022-08-30T19:21:23.464Z]     #15 0x4eeaf1 in testing::UnitTest::Run() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest.cc:4786:10
[2022-08-30T19:21:23.464Z]     #16 0x468f0f in RUN_ALL_TESTS() /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/include/gtest/gtest.h:2341:46
[2022-08-30T19:21:23.464Z]     #17 0x468f0f in main /home/jenkins/agent/workspace/tiflash-sanitizer-daily/tiflash/contrib/googletest/googletest/src/gtest_main.cc:36:10
[2022-08-30T19:21:23.464Z]     #18 0x7f315cadd554 in __libc_start_main (/lib64/libc.so.6+0x22554)
[2022-08-30T19:21:23.464Z]     #19 0x317ce8 in _start (/tiflash/gtests_libcommon+0x317ce8)


caused by #5658

// align address to 32 for better performance
// memory allocator will always alloc memory aligned to `Page Size`(usually 4K, one Block `512B` at least) from system
// if there is valid data at address S, then it is safe to visit address [ALIGN_TO_PAGE_SIZE(S), ALIGN_TO_PAGE_SIZE(S)+PAGE_SIZE).
if (uint8_t offset = OFFSET_FROM_ALIGNED(size_t(src), BLOCK32_SIZE); offset != 0)
{
// align to 32
src = reinterpret_cast<decltype(src)>(ALIGNED_ADDR(size_t(src), BLOCK32_SIZE));
// right shift offset to remove useless mask bit
auto mask = get_block32_cmp_eq_mask(src, check_block32) >> offset;
for (; mask;)

  • load block 32 from new aligned address may cause false positives when using AddressSanitizer because asan will provide a malloc()/free() alternative and detect memory visitation.
  • generally it's safe to visit address which won't cross page boundary.

What is changed and how it works?

use stl function if ADDRESS_SANITIZER is defined

verified in https://ci.pingcap.net/blue/organizations/jenkins/tiflash-sanitizer-daily/detail/tiflash-sanitizer-daily/487/pipeline

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 31, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • windtalker
  • zanmato1984

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 31, 2022
@solotzg solotzg changed the title Fix asan false positive case *: fix asan false positive case Aug 31, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/run-sanitizer-test asan

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
avx2_strstr.h                     149                17    88.59%          14                 0   100.00%         236                38    83.90%          82                 3    96.34%
mem_utils_opt.h                     6                 1    83.33%           3                 1    66.67%          45                33    26.67%           2                 0   100.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             155                18    88.39%          17                 1    94.12%         281                71    74.73%          84                 3    96.43%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18475      8321             54.96%    213736  85890        59.81%

full coverage report (for internal network access only)

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 31, 2022
Copy link
Contributor

@zanmato1984 zanmato1984 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 31, 2022
@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 3f52c37

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 31, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
avx2_strstr.h                     149                17    88.59%          14                 0   100.00%         236                38    83.90%          82                 3    96.34%
mem_utils_opt.h                     6                 1    83.33%           3                 1    66.67%          45                33    26.67%           2                 0   100.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             155                18    88.39%          17                 1    94.12%         281                71    74.73%          84                 3    96.43%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18475      8322             54.96%    213736  85901        59.81%

full coverage report (for internal network access only)

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
avx2_strstr.h                     149                17    88.59%          14                 0   100.00%         236                38    83.90%          82                 3    96.34%
mem_utils_opt.h                     6                 1    83.33%           3                 1    66.67%          45                33    26.67%           2                 0   100.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             155                18    88.39%          17                 1    94.12%         281                71    74.73%          84                 3    96.43%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18475      8321             54.96%    213736  85932        59.80%

full coverage report (for internal network access only)

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/run-integration-test

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
avx2_strstr.h                     149                17    88.59%          14                 0   100.00%         236                38    83.90%          82                 3    96.34%
mem_utils_opt.h                     6                 1    83.33%           3                 1    66.67%          45                33    26.67%           2                 0   100.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             155                18    88.39%          17                 1    94.12%         281                71    74.73%          84                 3    96.43%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18475      8322             54.96%    213736  85899        59.81%

full coverage report (for internal network access only)

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/rebuild

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/rebuild

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/merge

@ti-chi-bot
Copy link
Member

@solotzg: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/rebuild

@solotzg
Copy link
Contributor Author

solotzg commented Aug 31, 2022

/run-integration-test

@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
avx2_strstr.h                     149                17    88.59%          14                 0   100.00%         236                38    83.90%          82                 3    96.34%
mem_utils_opt.h                     6                 1    83.33%           3                 1    66.67%          45                33    26.67%           2                 0   100.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             155                18    88.39%          17                 1    94.12%         281                71    74.73%          84                 3    96.43%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18488      8323             54.98%    213856  85922        59.82%

full coverage report (for internal network access only)

@ti-chi-bot
Copy link
Member

@solotzg: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@JaySon-Huang
Copy link
Contributor

/run-unit-test

@sre-bot
Copy link
Collaborator

sre-bot commented Aug 31, 2022

Coverage for changed files

Filename                      Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
avx2_strstr.h                     149                17    88.59%          14                 0   100.00%         236                38    83.90%          82                 3    96.34%
mem_utils_opt.h                     6                 1    83.33%           3                 1    66.67%          45                33    26.67%           2                 0   100.00%
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                             155                18    88.39%          17                 1    94.12%         281                71    74.73%          84                 3    96.43%

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18488      8322             54.99%    213856  85870        59.85%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit 0410d3f into pingcap:master Aug 31, 2022
@solotzg solotzg deleted the fix-asan branch September 1, 2022 00:21
solotzg added a commit to solotzg/tiflash that referenced this pull request Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants