|
|
c616bf |
From 5a5e7890cefa112e95e1de9800d8081c2a38a1da Mon Sep 17 00:00:00 2001
|
|
|
c616bf |
From: "H.J. Lu" <hjl.tools@gmail.com>
|
|
|
c616bf |
Date: Wed, 5 Jan 2022 18:04:21 -0800
|
|
|
c616bf |
Subject: [PATCH 4/4] x86: Generate INT3 for __builtin_eh_return
|
|
|
c616bf |
|
|
|
c616bf |
Generate INT3 after indirect jmp in exception return for -fcf-protection
|
|
|
c616bf |
with -mharden-sls=indirect-jmp.
|
|
|
c616bf |
|
|
|
c616bf |
gcc/
|
|
|
c616bf |
|
|
|
c616bf |
PR target/103925
|
|
|
c616bf |
* config/i386/i386.c (ix86_output_indirect_function_return):
|
|
|
c616bf |
Generate INT3 after indirect jmp for -mharden-sls=indirect-jmp.
|
|
|
c616bf |
|
|
|
c616bf |
gcc/testsuite/
|
|
|
c616bf |
|
|
|
c616bf |
PR target/103925
|
|
|
c616bf |
* gcc.target/i386/harden-sls-6.c: New test.
|
|
|
c616bf |
|
|
|
c616bf |
(cherry picked from commit c2e5c4feed32c808591b5278f680bbabe63eb225)
|
|
|
c616bf |
---
|
|
|
c616bf |
gcc/config/i386/i386.c | 9 ++++++---
|
|
|
c616bf |
gcc/testsuite/gcc.target/i386/harden-sls-6.c | 18 ++++++++++++++++++
|
|
|
c616bf |
2 files changed, 24 insertions(+), 3 deletions(-)
|
|
|
c616bf |
create mode 100644 gcc/testsuite/gcc.target/i386/harden-sls-6.c
|
|
|
c616bf |
|
|
|
c616bf |
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
|
|
|
c616bf |
index 3bc14e20105..dbc3d462fda 100644
|
|
|
c616bf |
--- a/gcc/config/i386/i386.c
|
|
|
c616bf |
+++ b/gcc/config/i386/i386.c
|
|
|
c616bf |
@@ -29083,11 +29083,14 @@ ix86_output_indirect_function_return (rtx ret_op)
|
|
|
c616bf |
}
|
|
|
c616bf |
else
|
|
|
c616bf |
output_indirect_thunk (need_prefix, regno);
|
|
|
c616bf |
-
|
|
|
c616bf |
- return "";
|
|
|
c616bf |
}
|
|
|
c616bf |
else
|
|
|
c616bf |
- return "%!jmp\t%A0";
|
|
|
c616bf |
+ {
|
|
|
c616bf |
+ output_asm_insn ("%!jmp\t%A0", &ret_op);
|
|
|
c616bf |
+ if (ix86_harden_sls & harden_sls_indirect_jmp)
|
|
|
c616bf |
+ fputs ("\tint3\n", asm_out_file);
|
|
|
c616bf |
+ }
|
|
|
c616bf |
+ return "";
|
|
|
c616bf |
}
|
|
|
c616bf |
|
|
|
c616bf |
/* Split simple return with popping POPC bytes from stack to indirect
|
|
|
c616bf |
diff --git a/gcc/testsuite/gcc.target/i386/harden-sls-6.c b/gcc/testsuite/gcc.target/i386/harden-sls-6.c
|
|
|
c616bf |
new file mode 100644
|
|
|
c616bf |
index 00000000000..9068eb64008
|
|
|
c616bf |
--- /dev/null
|
|
|
c616bf |
+++ b/gcc/testsuite/gcc.target/i386/harden-sls-6.c
|
|
|
c616bf |
@@ -0,0 +1,18 @@
|
|
|
c616bf |
+/* { dg-do compile { target { ! ia32 } } } */
|
|
|
c616bf |
+/* { dg-options "-O2 -fcf-protection -mharden-sls=indirect-jmp" } */
|
|
|
c616bf |
+
|
|
|
c616bf |
+struct _Unwind_Context _Unwind_Resume_or_Rethrow_this_context;
|
|
|
c616bf |
+
|
|
|
c616bf |
+void offset (int);
|
|
|
c616bf |
+
|
|
|
c616bf |
+struct _Unwind_Context {
|
|
|
c616bf |
+ void *reg[7];
|
|
|
c616bf |
+} _Unwind_Resume_or_Rethrow() {
|
|
|
c616bf |
+ struct _Unwind_Context cur_contextcur_context =
|
|
|
c616bf |
+ _Unwind_Resume_or_Rethrow_this_context;
|
|
|
c616bf |
+ offset(0);
|
|
|
c616bf |
+ __builtin_eh_return ((long) offset, 0);
|
|
|
c616bf |
+}
|
|
|
c616bf |
+
|
|
|
c616bf |
+/* { dg-final { scan-assembler "jmp\[ \t\]+\\*%rcx" } } */
|
|
|
c616bf |
+/* { dg-final { scan-assembler-times "int3" 1 } } */
|
|
|
c616bf |
--
|
|
|
c616bf |
2.36.1
|
|
|
c616bf |
|