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

Paolo Bonzini posted 7 patches 6 years, 8 months ago
[Qemu-devel] [PATCH 6/7] linux-user: add IBT support to x86 safe-syscall.S
Posted by Paolo Bonzini 6 years, 8 months ago
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(+)

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
-- 
2.20.1



Re: [Qemu-devel] [PATCH 6/7] linux-user: add IBT support to x86 safe-syscall.S
Posted by Richard Henderson 6 years, 8 months ago
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~


Re: [Qemu-devel] [PATCH 6/7] linux-user: add IBT support to x86 safe-syscall.S
Posted by Paolo Bonzini 6 years, 8 months ago
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~
>