Skip to content

[sanitizer] Add CHECKs to validate calculated TLS range #107941

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

Conversation

vitalybuka
Copy link
Collaborator

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/107941.diff

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp (+4)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
index 666e6f3b351067..a1107ff7d24737 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -151,6 +151,10 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
     // This may happen inside the DTOR of main thread, so just ignore it.
     tls_size = 0;
   }
+  if (tls_size) {
+    CHECK_LE(tls_beg, reinterpret_cast<uptr>(res));
+    CHECK_LT(reinterpret_cast<uptr>(res), tls_beg + tls_size);
+  }
   dtv->beg = tls_beg;
   dtv->size = tls_size;
   return dtv;

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.sanitizer-add-checks-to-validate-calculated-tls-range to main September 10, 2024 00:08
@vitalybuka vitalybuka merged commit 957af73 into main Sep 10, 2024
9 of 10 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/sanitizer-add-checks-to-validate-calculated-tls-range branch September 10, 2024 22:07
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 10, 2024

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-test-suite running on ppc64le-clang-test-suite while building compiler-rt at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/3635

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'SanitizerCommon-asan-powerpc64le-Linux :: Linux/getgrouplist.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=address  -m64 -fno-function-sections -funwind-tables  -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test -ldl -O0 -g /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/asan-powerpc64le-Linux/Linux/Output/getgrouplist.cpp.tmp &&  /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/asan-powerpc64le-Linux/Linux/Output/getgrouplist.cpp.tmp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=address -m64 -fno-function-sections -funwind-tables -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test -ldl -O0 -g /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/asan-powerpc64le-Linux/Linux/Output/getgrouplist.cpp.tmp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/asan-powerpc64le-Linux/Linux/Output/getgrouplist.cpp.tmp
AddressSanitizer: CHECK failed: sanitizer_tls_get_addr.cpp:156 "((reinterpret_cast<uptr>(res))) < ((tls_beg + tls_size))" (0x7e7ff6ce8040, 0x7e7ff6ce0100) (tid=2167537)
    #0 0x000100118f3c in __asan::CheckUnwind() /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/asan/asan_rtl.cpp:69:3
    #1 0x00010013ebf8 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:86:5
    #2 0x00010013806c in __sanitizer::DTLS_on_tls_get_addr(void*, void*, unsigned long, unsigned long) /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp:156:5
    #3 0x00010009ac94 in __tls_get_addr_opt /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:5440:20
    #4 0x7dfff49be574  (/lib64/libnss_systemd.so.2+0xe574) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #5 0x7dfff4a59380  (/lib64/libnss_systemd.so.2+0xa9380) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #6 0x7dfff4a3c1dc  (/lib64/libnss_systemd.so.2+0x8c1dc) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #7 0x7dfff4a3c624  (/lib64/libnss_systemd.so.2+0x8c624) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #8 0x7dfff49edf04  (/lib64/libnss_systemd.so.2+0x3df04) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #9 0x7dfff49ee41c  (/lib64/libnss_systemd.so.2+0x3e41c) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #10 0x7dfff49ee7d0  (/lib64/libnss_systemd.so.2+0x3e7d0) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #11 0x7dfff49ee8c8  (/lib64/libnss_systemd.so.2+0x3e8c8) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #12 0x7dfff49bffc8  (/lib64/libnss_systemd.so.2+0xffc8) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #13 0x7ffff79a030c in compat_call.constprop.0 (/lib64/libc.so.6+0xf030c) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)
    #14 0x7ffff79a0a74 in internal_getgrouplist (/lib64/libc.so.6+0xf0a74) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)
    #15 0x7ffff79a0c34 in getgrouplist (/lib64/libc.so.6+0xf0c34) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)
    #16 0x0001000befac in getgrouplist /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:7326:9
    #17 0x0001001669b8 in main /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp:20:7
    #18 0x7ffff78da968 in generic_start_main.isra.0 (/lib64/libc.so.6+0x2a968) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)
    #19 0x7ffff78dab00 in __libc_start_main (/lib64/libc.so.6+0x2ab00) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)


--

********************

Step 7 (test-build-unified-tree-check-runtimes) failure: test (failure)
******************** TEST 'SanitizerCommon-msan-powerpc64le-Linux :: Linux/getpwnam_r_invalid_user.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 2: /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=memory  -m64 -fno-function-sections -funwind-tables  -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test -ldl -O0 -g /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/getpwnam_r_invalid_user.cpp.tmp &&  /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/getpwnam_r_invalid_user.cpp.tmp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=memory -m64 -fno-function-sections -funwind-tables -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test -ldl -O0 -g /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cpp -o /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/getpwnam_r_invalid_user.cpp.tmp
+ /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/build/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/msan-powerpc64le-Linux/Linux/Output/getpwnam_r_invalid_user.cpp.tmp
MemorySanitizer: CHECK failed: sanitizer_tls_get_addr.cpp:156 "((reinterpret_cast<uptr>(res))) < ((tls_beg + tls_size))" (0x306000008000, 0x3060000000c0) (tid=3983551)
    #0 0x00010005ef58 in CheckUnwind() /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/msan/msan.cpp:440:3
    #1 0x000100040768 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:86:5
    #2 0x000100039b8c in __sanitizer::DTLS_on_tls_get_addr(void*, void*, unsigned long, unsigned long) /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp:156:5
    #3 0x00010009ed84 in __tls_get_addr_opt /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/msan/../sanitizer_common/sanitizer_common_interceptors.inc:5440:20
    #4 0x7ffff5dbe574  (/lib64/libnss_systemd.so.2+0xe574) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #5 0x7ffff5e59380  (/lib64/libnss_systemd.so.2+0xa9380) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #6 0x7ffff5e3c1dc  (/lib64/libnss_systemd.so.2+0x8c1dc) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #7 0x7ffff5e3c624  (/lib64/libnss_systemd.so.2+0x8c624) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #8 0x7ffff5dedf04  (/lib64/libnss_systemd.so.2+0x3df04) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #9 0x7ffff5dee41c  (/lib64/libnss_systemd.so.2+0x3e41c) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #10 0x7ffff5dee7d0  (/lib64/libnss_systemd.so.2+0x3e7d0) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #11 0x7ffff5dee8c8  (/lib64/libnss_systemd.so.2+0x3e8c8) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #12 0x7ffff5dc0918 in _nss_systemd_getpwnam_r (/lib64/libnss_systemd.so.2+0x10918) (BuildId: 1cdbb72c5467047b5410c35c93a03e31c66fd933)
    #13 0x7ffff79a481c in getpwnam_r@@GLIBC_2.17 (/lib64/libc.so.6+0xf481c) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)
    #14 0x000100085438 in getpwnam_r /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/lib/msan/../sanitizer_common/sanitizer_common_interceptors.inc:1962:13
    #15 0x0001000e78b8 in main /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-test-suite/clang-ppc64le-test-suite/llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cpp:16:13
    #16 0x7ffff78da968 in generic_start_main.isra.0 (/lib64/libc.so.6+0x2a968) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)
    #17 0x7ffff78dab00 in __libc_start_main (/lib64/libc.so.6+0x2ab00) (BuildId: 1b9785bdef9e03ff9eac097ebd8cfdd5f8367bce)


--

********************


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants