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

[NFC][sanitizer] Add checks for impossible state #108672

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Sep 14, 2024

Before it was touched here afec953.

Important assumption that the stack is descending, but I don't think we
support ascending stack anyware.

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 14, 2024

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

Author: Vitaly Buka (vitalybuka)

Changes

I don't have reproducers, and don't know if this
branch is even possible but it looks like a typo
in 031c40d.

Before the patch:
For order "stk_begin, tls_begin, stk_end, tls_end", range [stk_end, tls_end) was discarded.
For order "stk_begin, tls_begin, tls_end, stk_end", range [stk_end, stk_end) was discarded.

After the patch:
For order "stk_begin, tls_begin, stk_end, tls_end", range [stk_end, tls_end) goes to tls.
For order "stk_begin, tls_begin, tls_end, stk_end", range [stk_end, stk_end) goes to tls.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp (+1-1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index c3c717bbdbe4c9..579d163479858c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -642,7 +642,7 @@ void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
   if (!main) {
     // If stack and tls intersect, make them non-intersecting.
     if (*tls_addr > *stk_addr && *tls_addr < *stk_addr + *stk_size) {
-      if (*stk_addr + *stk_size < *tls_addr + *tls_size)
+      if (*stk_addr + *stk_size > *tls_addr + *tls_size)
         *tls_size = *stk_addr + *stk_size - *tls_addr;
       *stk_size = *tls_addr - *stk_addr;
     }

arteen1000 and others added 2 commits September 13, 2024 20:07
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-fix-intersecting-stacks-workaround to main September 14, 2024 03:07
Created using spr 1.3.4
@MaskRay
Copy link
Member

MaskRay commented Sep 16, 2024

I believe the intention was:

Before the patch:
"stk_begin, tls_begin, stk_end, tls_end": range [stk_end, tls_end) was discarded.

However, the case is invalid and impossible. If stk_begin<tls_begin<stk_end, the tls range must be a subrange of [stk_begin,stk_end).

After the patch:
"stk_begin, tls_begin, stk_end, tls_end": range [stk_end, tls_end) goes to tls.

I think this is a no-op.

"stk_begin, tls_begin, tls_end, stk_end": range [stk_end, stk_end) goes to tls.

This extension effect isn't needed.


I think we can remove this statement.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4
@vitalybuka vitalybuka changed the title [sanitizer] Fix intersecting stacks workaround [NFC][sanitizer] Check that TLS is not in the middle of the stack Sep 16, 2024
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4
@vitalybuka vitalybuka changed the title [NFC][sanitizer] Check that TLS is not in the middle of the stack [NFC][sanitizer] Simplify splitting TLS and stack Sep 16, 2024
@vitalybuka
Copy link
Collaborator Author

I think we can remove this statement.

More aggressive checks

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka marked this pull request as draft September 17, 2024 03:54
Copy link

github-actions bot commented Sep 17, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
Created using spr 1.3.4
@vitalybuka vitalybuka marked this pull request as ready for review September 17, 2024 20:19
@vitalybuka vitalybuka changed the title [NFC][sanitizer] Simplify splitting TLS and stack [NFC][sanitizer] Add checks for impossible state Sep 17, 2024
Created using spr 1.3.4
@fmayer
Copy link
Contributor

fmayer commented Sep 20, 2024

Important assumption that the stack is descending, but I don't think we
support ascending stack anyware.

Put this into a comment.

@vitalybuka vitalybuka marked this pull request as draft October 12, 2024 01:10
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.

5 participants