From 48580982ef41907a45cda259a63d9e6878cbbea3 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 22 Jun 2017 05:50:20 -0700 Subject: x86: Support Intel Shadow Stack with SHSTK property To support Intel Shadow Stack (SHSTK) in Intel Control-flow Enforcement Technology (CET) instructions: https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf #define GNU_PROPERTY_X86_FEATURE_1_SHSTK (1U << 1) is added to GNU program properties to indicate that all executable sections are compatible with SHSTK where return address popped from shadow stack always matches return address popped from normal stack. GNU_PROPERTY_X86_FEATURE_1_SHSTK is set on output only if it is set on all relocatable inputs. bfd/ * elf32-i386.c (elf_i386_merge_gnu_properties): If info->shstk is set, turn on GNU_PROPERTY_X86_FEATURE_1_SHSTK. (elf_i386_link_setup_gnu_properties): If info->shstk is set, turn on GNU_PROPERTY_X86_FEATURE_1_IBT. * elf64-x86-64.c (elf_x86_64_merge_gnu_properties): If info->shstk is set, turn on GNU_PROPERTY_X86_FEATURE_1_SHSTK. (elf_x86_64_link_setup_gnu_properties): If info->shstk is set, turn on GNU_PROPERTY_X86_FEATURE_1_IBT. binutils/ * readelf.c (decode_x86_feature): Decode GNU_PROPERTY_X86_FEATURE_1_SHSTK. * testsuite/binutils-all/i386/shstk.d: New file. * testsuite/binutils-all/i386/shstk.s: Likewise. * testsuite/binutils-all/x86-64/shstk-x32.d: Likewise. * testsuite/binutils-all/x86-64/shstk.d: Likewise. * testsuite/binutils-all/x86-64/shstk.s: Likewise. include/ * bfdlink.h (bfd_link_info): Add shstk. * elf/common.h (GNU_PROPERTY_X86_FEATURE_1_SHSTK): New. ld/ * NEWS: Mention -z shstk and GNU_PROPERTY_X86_FEATURE_1_SHSTK. * emulparams/cet.sh (PARSE_AND_LIST_OPTIONS_CET): Add "-z shstk". (PARSE_AND_LIST_ARGS_CASE_Z_CET): Support "-z shstk". * ld.texinfo: Document -z shstk. * testsuite/ld-i386/i386.exp: Run SHSTK tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/property-x86-shstk.s: New file. * testsuite/ld-i386/property-x86-shstk1a.d: Likewise. * testsuite/ld-i386/property-x86-shstk1b.d: Likewise. * testsuite/ld-i386/property-x86-shstk2.d: Likewise. * testsuite/ld-i386/property-x86-shstk3a.d: Likewise. * testsuite/ld-i386/property-x86-shstk3b.d: Likewise. * testsuite/ld-i386/property-x86-shstk4.d: Likewise. * testsuite/ld-i386/property-x86-shstk5.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk.s: Likewise. * testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk2.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk4.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-shstk5.d: Likewise. --- binutils/testsuite/binutils-all/i386/shstk.d | 9 ++++++++ binutils/testsuite/binutils-all/i386/shstk.s | 27 ++++++++++++++++++++++ binutils/testsuite/binutils-all/x86-64/shstk-x32.d | 10 ++++++++ binutils/testsuite/binutils-all/x86-64/shstk.d | 9 ++++++++ binutils/testsuite/binutils-all/x86-64/shstk.s | 27 ++++++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 binutils/testsuite/binutils-all/i386/shstk.d create mode 100644 binutils/testsuite/binutils-all/i386/shstk.s create mode 100644 binutils/testsuite/binutils-all/x86-64/shstk-x32.d create mode 100644 binutils/testsuite/binutils-all/x86-64/shstk.d create mode 100644 binutils/testsuite/binutils-all/x86-64/shstk.s (limited to 'binutils/testsuite') diff --git a/binutils/testsuite/binutils-all/i386/shstk.d b/binutils/testsuite/binutils-all/i386/shstk.d new file mode 100644 index 0000000..933704c --- /dev/null +++ b/binutils/testsuite/binutils-all/i386/shstk.d @@ -0,0 +1,9 @@ +#PROG: objcopy +#as: --32 +#objcopy: +#readelf: -n + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x0000000c NT_GNU_PROPERTY_TYPE_0 + Properties: x86 feature: SHSTK diff --git a/binutils/testsuite/binutils-all/i386/shstk.s b/binutils/testsuite/binutils-all/i386/shstk.s new file mode 100644 index 0000000..4c3218a --- /dev/null +++ b/binutils/testsuite/binutils-all/i386/shstk.s @@ -0,0 +1,27 @@ + .section ".note.gnu.property", "a" +.ifdef __64_bit__ + .p2align 3 +.else + .p2align 2 +.endif + .long 1f - 0f /* name length */ + .long 5f - 2f /* data length */ + .long 5 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: +.ifdef __64_bit__ + .p2align 3 +.else + .p2align 2 +.endif +2: .long 0xc0000002 /* pr_type. */ + .long 4f - 3f /* pr_datasz. */ +3: + .long 0x2 +4: +.ifdef __64_bit__ + .p2align 3 +.else + .p2align 2 +.endif +5: diff --git a/binutils/testsuite/binutils-all/x86-64/shstk-x32.d b/binutils/testsuite/binutils-all/x86-64/shstk-x32.d new file mode 100644 index 0000000..1dfc4fd --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/shstk-x32.d @@ -0,0 +1,10 @@ +#source: shstk.s +#PROG: objcopy +#as: --x32 +#objcopy: +#readelf: -n + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x0000000c NT_GNU_PROPERTY_TYPE_0 + Properties: x86 feature: SHSTK diff --git a/binutils/testsuite/binutils-all/x86-64/shstk.d b/binutils/testsuite/binutils-all/x86-64/shstk.d new file mode 100644 index 0000000..1f131b8 --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/shstk.d @@ -0,0 +1,9 @@ +#PROG: objcopy +#as: --64 -defsym __64_bit__=1 +#objcopy: +#readelf: -n + +Displaying notes found in: .note.gnu.property + Owner Data size Description + GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 + Properties: x86 feature: SHSTK diff --git a/binutils/testsuite/binutils-all/x86-64/shstk.s b/binutils/testsuite/binutils-all/x86-64/shstk.s new file mode 100644 index 0000000..4c3218a --- /dev/null +++ b/binutils/testsuite/binutils-all/x86-64/shstk.s @@ -0,0 +1,27 @@ + .section ".note.gnu.property", "a" +.ifdef __64_bit__ + .p2align 3 +.else + .p2align 2 +.endif + .long 1f - 0f /* name length */ + .long 5f - 2f /* data length */ + .long 5 /* note type */ +0: .asciz "GNU" /* vendor name */ +1: +.ifdef __64_bit__ + .p2align 3 +.else + .p2align 2 +.endif +2: .long 0xc0000002 /* pr_type. */ + .long 4f - 3f /* pr_datasz. */ +3: + .long 0x2 +4: +.ifdef __64_bit__ + .p2align 3 +.else + .p2align 2 +.endif +5: -- cgit v1.1