public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][pushed] ASAN: Support detect_invalid_pointer_pairs=1 with detect_stack_use_after_return=1
@ 2020-10-21  7:28 Martin Liška
  2020-10-21  7:30 ` [PATCH][pushed] libsanitizer: add test-case Martin Liška
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2020-10-21  7:28 UTC (permalink / raw)
  To: gcc-patches

This is one another backport from master.

Do not crash when AsanThread::GetStackVariableShadowStart does not find
a variable for a pointer on a shadow stack.

Cherry-pick from ad2be02a833e56f7fe280797280b219eb3312621.

Differential Revision: https://reviews.llvm.org/D89552
---
  libsanitizer/asan/asan_thread.cpp | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libsanitizer/asan/asan_thread.cpp b/libsanitizer/asan/asan_thread.cpp
index f0df8bd4b37..58cdc29d365 100644
--- a/libsanitizer/asan/asan_thread.cpp
+++ b/libsanitizer/asan/asan_thread.cpp
@@ -366,7 +366,9 @@ uptr AsanThread::GetStackVariableShadowStart(uptr addr) {
      bottom = stack_bottom();
    } else if (has_fake_stack()) {
      bottom = fake_stack()->AddrIsInFakeStack(addr);
-    CHECK(bottom);
+    if (bottom == 0) {
+      return 0;
+    }
    } else {
      return 0;
    }
-- 
2.28.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH][pushed] libsanitizer: add test-case
  2020-10-21  7:28 [PATCH][pushed] ASAN: Support detect_invalid_pointer_pairs=1 with detect_stack_use_after_return=1 Martin Liška
@ 2020-10-21  7:30 ` Martin Liška
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liška @ 2020-10-21  7:30 UTC (permalink / raw)
  To: gcc-patches

And here I'm adding a test-case for the PR.

Thanks,
Martin

gcc/testsuite/ChangeLog:

	PR sanitizer/97414
	* g++.dg/asan/pr97414.C: New test.
---
  gcc/testsuite/g++.dg/asan/pr97414.C | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/asan/pr97414.C

diff --git a/gcc/testsuite/g++.dg/asan/pr97414.C b/gcc/testsuite/g++.dg/asan/pr97414.C
new file mode 100644
index 00000000000..6ea03906daa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr97414.C
@@ -0,0 +1,19 @@
+/* PR sanitizer/97414 */
+/* { dg-do run } */
+/* { dg-set-target-env-var ASAN_OPTIONS "detect_invalid_pointer_pairs=1:halt_on_error=1,detect_stack_use_after_return=1" } */
+/* { dg-options "-fsanitize=address,pointer-compare,pointer-subtract" } */
+
+[[gnu::noinline]] auto pointer_diff(const int *begin, const int *end) {
+  return end - begin;
+}
+
+int main() {
+  constexpr auto size = (2048 / sizeof(int)) + 1;
+
+  auto buf = new int[size];
+  auto end = buf + size;
+  pointer_diff(end, buf);
+  delete[] buf;
+
+  return 0;
+}
-- 
2.28.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-21  7:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21  7:28 [PATCH][pushed] ASAN: Support detect_invalid_pointer_pairs=1 with detect_stack_use_after_return=1 Martin Liška
2020-10-21  7:30 ` [PATCH][pushed] libsanitizer: add test-case Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).