From 869c3df00e8bb468df5e08734d9d82b7bf236bfd Mon Sep 17 00:00:00 2001
From: Sotiris Apostolakis <apostolakis@google.com>
Date: Mon, 5 Apr 2021 23:11:34 +0000
Subject: [PATCH 1/2] i#4425: handle unspecified-by-the-app sigaction restorer
 for AArch64

Prevents a seg fault in the burst_aarch64_sys test that was caused by reading an unspecified
sigaction restorer in sig_has_restorer() in unix/signal.c. Does so by returning false early
in sig_has_restorer() for AArch64 when the SA_RESTORER flag is not set.

By preventing the seg fault, it also prevents the nested signal handling and consequently
the stack overflow in burst_aarch64_sys.

Issue: #4425
---
 clients/drcachesim/tests/burst_aarch64_sys.cpp |  4 +---
 core/unix/signal.c                             | 11 +++++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clients/drcachesim/tests/burst_aarch64_sys.cpp b/clients/drcachesim/tests/burst_aarch64_sys.cpp
index 1b274ea20..71c12f5e4 100644
--- a/clients/drcachesim/tests/burst_aarch64_sys.cpp
+++ b/clients/drcachesim/tests/burst_aarch64_sys.cpp
@@ -177,9 +177,7 @@ static std::string
 gather_trace()
 {
     if (!my_setenv("DYNAMORIO_OPTIONS",
-                   // XXX i#4425: Fix debug-build stack overflow issue and
-                   // remove custom signal_stack_size below.
-                   "-stderr_mask 0xc -signal_stack_size 64K "
+                   "-stderr_mask 0xc "
                    "-client_lib ';;-offline'"))
         std::cerr << "failed to set env var!\n";
 
diff --git a/core/unix/signal.c b/core/unix/signal.c
index 882523fe1..4dd105ab2 100644
--- a/core/unix/signal.c
+++ b/core/unix/signal.c
@@ -2879,6 +2879,17 @@ sig_has_restorer(thread_sig_info_t *info, int sig)
         return false;
     if (TEST(SA_RESTORER, info->app_sigaction[sig]->flags))
         return true;
+#    ifdef AARCH64
+    /* In AArch64 either the app or the kernel defines a restorer, not glibc, contrary
+     * to x86/ARM where glibc defines a restorer if the app did not define one. Thus,
+     * reading info->app_sigaction[sig]->restorer when SA_RESTORER is not specified by
+     * the app was never an issue for x86/ARM, but for AArch64 if the SA_RESTORER is
+     * not specified DR will read garbage leading to a seg fault later when
+     * safe_reading the restorer. To avoid this issue return false early for AArch64 if
+     * SA_RESTORER is not specified.
+     */
+    return false;
+#    endif
     if (info->app_sigaction[sig]->restorer == NULL)
         return false;
     /* we cache the result due to the safe_read cost */
-- 
GitLab


From 104936162a1286398c065277a376fd5e267c1a6f Mon Sep 17 00:00:00 2001
From: Sotiris Apostolakis <apostolakis@google.com>
Date: Wed, 7 Apr 2021 14:50:06 +0000
Subject: [PATCH 2/2] formatting

---
 clients/drcachesim/tests/burst_aarch64_sys.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clients/drcachesim/tests/burst_aarch64_sys.cpp b/clients/drcachesim/tests/burst_aarch64_sys.cpp
index 71c12f5e4..f8807d6a1 100644
--- a/clients/drcachesim/tests/burst_aarch64_sys.cpp
+++ b/clients/drcachesim/tests/burst_aarch64_sys.cpp
@@ -176,9 +176,7 @@ post_process()
 static std::string
 gather_trace()
 {
-    if (!my_setenv("DYNAMORIO_OPTIONS",
-                   "-stderr_mask 0xc "
-                   "-client_lib ';;-offline'"))
+    if (!my_setenv("DYNAMORIO_OPTIONS", "-stderr_mask 0xc -client_lib ';;-offline'"))
         std::cerr << "failed to set env var!\n";
 
     std::cerr << "pre-DR init\n";
-- 
GitLab