Skip to content

[sanitizer] Adjust size for begin/start mismatch #109079

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

Follow up to 51d913a.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

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

Author: Vitaly Buka (vitalybuka)

Changes

Follow up to 51d913a.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp (+6-1)
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 0db8547268f4e2..6f3b6af3c58474 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -15,6 +15,7 @@
 #include "sanitizer_allocator_interface.h"
 #include "sanitizer_atomic.h"
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_internal_defs.h"
 #include "sanitizer_flags.h"
 #include "sanitizer_platform_interceptors.h"
 
@@ -116,10 +117,14 @@ SANITIZER_INTERFACE_WEAK_DEF(uptr, __sanitizer_get_dtls_size,
   const void *start = __sanitizer_get_allocated_begin(tls_begin);
   if (!start)
     return 0;
+  CHECK_LE(start, tls_begin);
   uptr tls_size = __sanitizer_get_allocated_size(start);
   VReport(2, "__tls_get_addr: glibc DTLS suspected; tls={%p,0x%zx}\n",
           tls_begin, tls_size);
-  return tls_size;
+  uptr offset =
+      (reinterpret_cast<uptr>(tls_begin) - reinterpret_cast<uptr>(start));
+  CHECK_LE(offset, tls_size);
+  return tls_size - offset;
 }
 
 DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,

@vitalybuka vitalybuka merged commit 38752ff into main Sep 18, 2024
10 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/sanitizer-adjust-size-for-beginstart-mismatch branch September 18, 2024 23:10
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
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.

3 participants