[compiler-rt] 4989779 - asan: fix crash on odd stack size
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 12 03:21:50 PDT 2023
Author: Dmitry Vyukov
Date: 2023-03-12T11:21:33+01:00
New Revision: 4989779d7a412a19bab168a1281f6f33edc40870
URL: https://github.com/llvm/llvm-project/commit/4989779d7a412a19bab168a1281f6f33edc40870
DIFF: https://github.com/llvm/llvm-project/commit/4989779d7a412a19bab168a1281f6f33edc40870.diff
LOG: asan: fix crash on odd stack size
The test currently crashes as:
AddressSanitizer: CHECK failed: asan_poisoning.cpp:38 "((AddrIsAlignedByGranularity(addr))) != (0)"
Main stack address/size don't have to be aligned on asan shadow granularity.
Align stack bottom.
Reviewed By: melver, vitalybuka
Differential Revision: https://reviews.llvm.org/D145799
Added:
compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp
Modified:
compiler-rt/lib/asan/asan_thread.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index 003cd2b9eee8d..56636b51618ae 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -306,6 +306,7 @@ void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
&tls_begin_, &tls_size);
stack_top_ = RoundDownTo(stack_bottom_ + stack_size, ASAN_SHADOW_GRANULARITY);
+ stack_bottom_ = RoundDownTo(stack_bottom_, ASAN_SHADOW_GRANULARITY);
tls_end_ = tls_begin_ + tls_size;
dtls_ = DTLS_Get();
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp
new file mode 100644
index 0000000000000..205c56051cb20
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/odd_stack_size.cpp
@@ -0,0 +1,30 @@
+// RUN: %clangxx -O1 %s -o %t && %run %t
+// UNSUPPORTED: android
+
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ if (getenv("SANITIZER_TEST_REEXECED"))
+ exit(0);
+ struct rlimit rl;
+ assert(!getrlimit(RLIMIT_STACK, &rl));
+ struct rlimit rl_new = rl;
+ rl_new.rlim_cur = 17351;
+ assert(!setrlimit(RLIMIT_STACK, &rl_new));
+ int pid = fork();
+ assert(pid >= 0);
+ if (pid == 0) {
+ const char *envp[] = {"SANITIZER_TEST_REEXECED=1", nullptr};
+ execve(argv[0], argv, const_cast<char **>(envp));
+ assert(false);
+ }
+ int status;
+ while (waitpid(-1, &status, __WALL) != pid) {
+ }
+ assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+ return 0;
+}
More information about the llvm-commits
mailing list