diff mbox series

[6/7] linux-user: add IBT support to x86 safe-syscall.S

Message ID 20190313124042.12855-7-pbonzini@redhat.com
State New
Headers show
Series CET support | expand

Commit Message

Paolo Bonzini March 13, 2019, 12:40 p.m. UTC
Because safe-syscall.S does not go through the C compiler, the
.note.gnu.property note has to be added manually.  Safe syscalls do not
involve any indirect branch or stack unwinding, so they are trivially
safe for IBT or shadow stacks.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 linux-user/host/i386/safe-syscall.inc.S   | 19 +++++++++++++++++++
 linux-user/host/x86_64/safe-syscall.inc.S | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+)

Comments

Richard Henderson March 13, 2019, 11:52 p.m. UTC | #1
On 3/13/19 5:40 AM, Paolo Bonzini wrote:
> Because safe-syscall.S does not go through the C compiler, the
> .note.gnu.property note has to be added manually.  Safe syscalls do not
> involve any indirect branch or stack unwinding, so they are trivially
> safe for IBT or shadow stacks.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  linux-user/host/i386/safe-syscall.inc.S   | 19 +++++++++++++++++++
>  linux-user/host/x86_64/safe-syscall.inc.S | 19 +++++++++++++++++++
>  2 files changed, 38 insertions(+)

I suppose it's not worth trying to share these 19 lines...

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Paolo Bonzini March 14, 2019, 10:37 a.m. UTC | #2
On 14/03/19 00:52, Richard Henderson wrote:
> On 3/13/19 5:40 AM, Paolo Bonzini wrote:
>> Because safe-syscall.S does not go through the C compiler, the
>> .note.gnu.property note has to be added manually.  Safe syscalls do not
>> involve any indirect branch or stack unwinding, so they are trivially
>> safe for IBT or shadow stacks.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  linux-user/host/i386/safe-syscall.inc.S   | 19 +++++++++++++++++++
>>  linux-user/host/x86_64/safe-syscall.inc.S | 19 +++++++++++++++++++
>>  2 files changed, 38 insertions(+)
> 
> I suppose it's not worth trying to share these 19 lines...

They aren't exactly shared, one is .p2align 2, the other is .p2align 3.

Paolo

> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> 
> r~
>
diff mbox series

Patch

diff --git a/linux-user/host/i386/safe-syscall.inc.S b/linux-user/host/i386/safe-syscall.inc.S
index 9e58fc6504..6c6d568d62 100644
--- a/linux-user/host/i386/safe-syscall.inc.S
+++ b/linux-user/host/i386/safe-syscall.inc.S
@@ -98,3 +98,22 @@  safe_syscall_end:
 	.cfi_endproc
 
 	.size	safe_syscall_base, .-safe_syscall_base
+
+	.pushsection ".note.gnu.property", "a"
+	.p2align 2
+	.long 1f - 0f          /* name length.  */
+	.long 4f - 1f          /* data length.  */
+	.long 5                /* NT_GNU_PROPERTY_TYPE_0.  */
+0:
+	.asciz "GNU"           /* vendor name.  */
+	.p2align 2
+1:
+        /* GNU_PROPERTY_X86_FEATURE_1_AND.  */
+	.long 0xc0000002       /* pr_type.  */
+	.long 3f - 2f          /* pr_datasz.  */
+2:
+	.long 0x3              /* IBT, SHSTK */
+3:
+	.p2align 2
+4:
+	.popsection
diff --git a/linux-user/host/x86_64/safe-syscall.inc.S b/linux-user/host/x86_64/safe-syscall.inc.S
index f36992daa3..e1a57db338 100644
--- a/linux-user/host/x86_64/safe-syscall.inc.S
+++ b/linux-user/host/x86_64/safe-syscall.inc.S
@@ -89,3 +89,22 @@  safe_syscall_end:
         .cfi_endproc
 
         .size   safe_syscall_base, .-safe_syscall_base
+
+	.pushsection ".note.gnu.property", "a"
+	.p2align 3
+	.long 1f - 0f          /* name length.  */
+	.long 4f - 1f          /* data length.  */
+	.long 5                /* NT_GNU_PROPERTY_TYPE_0.  */
+0:
+	.asciz "GNU"           /* vendor name.  */
+	.p2align 3
+1:
+        /* GNU_PROPERTY_X86_FEATURE_1_AND.  */
+	.long 0xc0000002       /* pr_type.  */
+	.long 3f - 2f          /* pr_datasz.  */
+2:
+	.long 0x3              /* IBT, SHSTK */
+3:
+	.p2align 3
+4:
+	.popsection