From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] Call BUILT_IN_ASAN_HANDLE_NO_RETURN before BUILT_IN_UNWIND_RESUME (PR sanitizer/81021).
Date: Tue, 13 Jun 2017 08:09:00 -0000 [thread overview]
Message-ID: <c9ab0efb-d401-c42c-4bd2-e848ebef0c87@suse.cz> (raw)
[-- Attachment #1: Type: text/plain, Size: 929 bytes --]
Hi.
For a function that does not handle an expection (and calls BUILT_IN_UNWIND_RESUME),
we need to emit call to BUILT_IN_ASAN_HANDLE_NO_RETURN. That will clean up stack
which can possibly contain poisoned shadow memory that will not be cleaned-up
in function prologue.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Ready to be installed?
Martin
gcc/testsuite/ChangeLog:
2017-06-12 Martin Liska <mliska@suse.cz>
PR sanitizer/81021
* g++.dg/asan/pr81021.C: New test.
gcc/ChangeLog:
2017-06-12 Martin Liska <mliska@suse.cz>
PR sanitizer/81021
* tree-eh.c (lower_resx): Call BUILT_IN_ASAN_HANDLE_NO_RETURN
before BUILT_IN_UNWIND_RESUME when ASAN is used.
---
gcc/testsuite/g++.dg/asan/pr81021.C | 33 +++++++++++++++++++++++++++++++++
gcc/tree-eh.c | 14 ++++++++++++++
2 files changed, 47 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/asan/pr81021.C
[-- Attachment #2: 0001-Call-BUILT_IN_ASAN_HANDLE_NO_RETURN-before-BUILT_IN_.patch --]
[-- Type: text/x-patch, Size: 2072 bytes --]
diff --git a/gcc/testsuite/g++.dg/asan/pr81021.C b/gcc/testsuite/g++.dg/asan/pr81021.C
new file mode 100644
index 00000000000..daa0525c273
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr81021.C
@@ -0,0 +1,33 @@
+// { dg-do run }
+
+#include <string>
+
+struct ConfigFile {
+ ConfigFile(std::string filename, std::string delimiter) { throw "error"; }
+ ConfigFile(std::string filename) {}
+};
+
+struct Configuration {
+ ConfigFile _configFile;
+
+ Configuration(const std::string &root, const char *baseName)
+ : _configFile(root + baseName, "=") { }
+ Configuration(const std::string &root, const char *a, const char *b)
+ : _configFile(root + a + b) { }
+};
+
+
+void test() {
+ std::string root("etc");
+ try {
+ Configuration config(root, "notthere");
+ }
+ catch (...) {
+ // exception is thrown, caught here and ignored...
+ }
+ Configuration config(root, "a", "b"); // ASAN error during constructor here
+}
+
+int main(int argc, const char *argv[]) {
+ test();
+}
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index fc016d795b7..fdd348c52e9 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -3304,6 +3304,20 @@ lower_resx (basic_block bb, gresx *stmt,
gimple_call_set_lhs (x, var);
gsi_insert_before (&gsi, x, GSI_SAME_STMT);
+ /* When exception handling is delegated to a caller function, we
+ have to guarantee that shadow memory variables living on stack
+ will be cleaner before control is given to a parent function. */
+ if ((flag_sanitize & SANITIZE_ADDRESS) != 0
+ && !lookup_attribute ("no_sanitize_address",
+ DECL_ATTRIBUTES (current_function_decl)))
+ {
+ tree decl
+ = builtin_decl_implicit (BUILT_IN_ASAN_HANDLE_NO_RETURN);
+ gimple *g = gimple_build_call (decl, 0);
+ gimple_set_location (g, gimple_location (stmt));
+ gsi_insert_before (&gsi, g, GSI_SAME_STMT);
+ }
+
fn = builtin_decl_implicit (BUILT_IN_UNWIND_RESUME);
x = gimple_build_call (fn, 1, var);
gsi_insert_before (&gsi, x, GSI_SAME_STMT);
next reply other threads:[~2017-06-13 8:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-13 8:09 Martin Liška [this message]
2017-06-20 12:16 ` Martin Liška
2017-06-28 13:16 ` Martin Liška
2017-06-29 17:17 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9ab0efb-d401-c42c-4bd2-e848ebef0c87@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).