Clear AC bit in RFLAGS to protect Xen itself by SMAP
PATCH v2 2/7 Clear AC bit in RFLAGS to protect Xen itself by SMAP
Clear AC bit in RFLAGS at the beginning of exception, interrupt, hypercall, so Xen itself can be protected by SMAP mechanism.
--- xen/arch/x86/x86_64/compat/entry.S | 1 + xen/arch/x86/x86_64/entry.S | 26 ++++++++++++++++++++++++++ xen/include/asm-x86/x86_64/asm_defns.h | 1 + 3 files changed, 28 insertions(+)
xen/arch/x86/x86_64/compat/entry.S +1 -0
@@ -13,6 +13,7 @@ #include <irq_vectors.h> ENTRY(compat_hypercall) + ASM_CLAC pushq $0 SAVE_VOLATILE type=TRAP_syscall compat=1
xen/arch/x86/x86_64/entry.S +26 -0
@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLAC sti movl $FLAT_KERNEL_SS,24(%rsp) pushq %rcx
@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0
@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception ENTRY(int80_direct_trap) + ASM_CLAC pushq $0 SAVE_VOLATILE 0x80
@@ -476,6 +479,7 @@ ENTRY(ret_from_intr) jmp compat_test_all_events ENTRY(page_fault) + ASM_CLAC movl $TRAP_page_fault,4(%rsp) /* No special register assumptions. */ GLOBAL(handle_exception)
@@ -532,81 +536,98 @@ FATAL_exception_with_ints_disabled: ud2 ENTRY(divide_error) + ASM_CLAC pushq $0 movl $TRAP_divide_error,4(%rsp) jmp handle_exception ENTRY(coprocessor_error) + ASM_CLAC pushq $0 movl $TRAP_copro_error,4(%rsp) jmp handle_exception ENTRY(simd_coprocessor_error) + ASM_CLAC pushq $0 movl $TRAP_simd_error,4(%rsp) jmp handle_exception ENTRY(device_not_available) + ASM_CLAC pushq $0 movl $TRAP_no_device,4(%rsp) jmp handle_exception ENTRY(debug) + ASM_CLAC pushq $0 movl $TRAP_debug,4(%rsp) jmp handle_exception ENTRY(int3) + ASM_CLAC pushq $0 movl $TRAP_int3,4(%rsp) jmp handle_exception ENTRY(overflow) + ASM_CLAC pushq $0 movl $TRAP_overflow,4(%rsp) jmp handle_exception ENTRY(bounds) + ASM_CLAC pushq $0 movl $TRAP_bounds,4(%rsp) jmp handle_exception ENTRY(invalid_op) + ASM_CLAC pushq $0 movl $TRAP_invalid_op,4(%rsp) jmp handle_exception ENTRY(coprocessor_segment_overrun) + ASM_CLAC pushq $0 movl $TRAP_copro_seg,4(%rsp) jmp handle_exception ENTRY(invalid_TSS) + ASM_CLAC movl $TRAP_invalid_tss,4(%rsp) jmp handle_exception ENTRY(segment_not_present) + ASM_CLAC movl $TRAP_no_segment,4(%rsp) jmp handle_exception ENTRY(stack_segment) + ASM_CLAC movl $TRAP_stack_error,4(%rsp) jmp handle_exception ENTRY(general_protection) + ASM_CLAC movl $TRAP_gp_fault,4(%rsp) jmp handle_exception ENTRY(alignment_check) + ASM_CLAC movl $TRAP_alignment_check,4(%rsp) jmp handle_exception ENTRY(spurious_interrupt_bug) + ASM_CLAC pushq $0 movl $TRAP_spurious_int,4(%rsp) jmp handle_exception ENTRY(double_fault) + ASM_CLAC movl $TRAP_double_fault,4(%rsp) SAVE_ALL movq %rsp,%rdi
@@ -615,6 +636,7 @@ ENTRY(double_fault) .pushsection .init.text, "ax", @progbits ENTRY(early_page_fault) + ASM_CLAC SAVE_ALL movq %rsp,%rdi call do_early_page_fault
@@ -622,6 +644,7 @@ ENTRY(early_page_fault) .popsection ENTRY(nmi) + ASM_CLAC pushq $0 movl $TRAP_nmi,4(%rsp) handle_ist_exception:
@@ -659,6 +682,7 @@ handle_ist_exception: jmp compat_restore_all_guest ENTRY(nmi_crash) + ASM_CLAC pushq $0 movl $TRAP_nmi,4(%rsp) SAVE_ALL
@@ -667,6 +691,7 @@ ENTRY(nmi_crash) ud2 ENTRY(machine_check) + ASM_CLAC pushq $0 movl $TRAP_machine_check,4(%rsp) jmp handle_ist_exception
@@ -689,6 +714,7 @@ ENTRY(enable_nmis) /* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretq
xen/include/asm-x86/x86_64/asm_defns.h +1 -0
@@ -212,6 +212,7 @@ __asm__( \"\n" __ALIGN_STR"\n" \"common_interrupt:\n\t" \ + ASM_CLAC(%)"\n\t" \ STR(SAVE_ALL) "\n\t" \"movq %rsp,%rdi\n\t" \ "callq " STR(do_IRQ) "\n\t" \
Signature · 1 line
1.8.3.1
Quoted 27 lines · Feng Wu
Clear AC bit in RFLAGS at the beginning of exception, interrupt, hypercall, so Xen itself can be protected by SMAP mechanism.
Signed-off-by Feng Wu <[email protected]>--- xen/arch/x86/x86_64/compat/entry.S | 1 + xen/arch/x86/x86_64/entry.S | 26 ++++++++++++++++++++++++++ xen/include/asm-x86/x86_64/asm_defns.h | 1 + 3 files changed, 28 insertions(+)xen/arch/x86/x86_64/compat/entry.S +1
-0@@ -13,6 +13,7 @@ #include <irq_vectors.h> ENTRY(compat_hypercall) + ASM_CLAC pushq $0 SAVE_VOLATILE type=TRAP_syscall compat=1xen/arch/x86/x86_64/entry.S +0
-0
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 4 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLAC
Surely this can be sorted more succinctly by setting X86_EFLAGS_AC in MSR 0xc0000084 ?
You also need to patch the entry points in the compat trampoline in
Quoted 14 lines
xen/arch/x86/x86_64/entry.S +1
-0sti movl $FLAT_KERNEL_SS,24(%rsp) pushq %rcx@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception
...
Quoted 4 lines
.pushsection .init.text, "ax", @progbits
ENTRY(early_page_fault)
+ASM_CLAC
I don't think CLAC is appropriate here. This is a pagefault handler for Xen early boot, and is replaced with a real handler substantially before dom0 is created.
Quoted 28 lines
SAVE_ALL
movq %rsp,%rdi
calldo_early_page_faultxen/arch/x86/x86_64/entry.S +3
-0@@ -622,6 +644,7 @@ ENTRY(early_page_fault) .popsection ENTRY(nmi) + ASM_CLAC pushq $0 movl $TRAP_nmi,4(%rsp) handle_ist_exception:@@ -659,6 +682,7 @@ handle_ist_exception: jmp compat_restore_all_guest ENTRY(nmi_crash) + ASM_CLAC pushq $0 movl $TRAP_nmi,4(%rsp) SAVE_ALL@@ -667,6 +691,7 @@ ENTRY(nmi_crash) ud2 ENTRY(machine_check) + ASM_CLAC pushq $0 movl $TRAP_machine_check,4(%rsp) jmp handle_ist_exception
xen/arch/x86/x86_64/entry.S ENTRY(enable_nmis) · line 718
Quoted 5 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -689,6 +714,7 @@ ENTRY(enable_nmis) /* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretq
This is not sensible in the slightest, given the following instruction.
~Andrew
Quoted 14 lines
xen/include/asm-x86/x86_64/asm_defns.h +1
-0@@ -212,6 +212,7 @@ __asm__( \"\n" __ALIGN_STR"\n" \"common_interrupt:\n\t" \ + ASM_CLAC(%)"\n\t" \ STR(SAVE_ALL) "\n\t" \"movq %rsp,%rdi\n\t" \ "callq " STR(do_IRQ) "\n\t" \
Quoted 35 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: Wednesday, April 23, 2014 6:20 PM
To: Wu, Feng
Cc: [email protected]; [email protected]; Tian, Kevin; Dong, Eddie; Nakajima, Jun; [email protected]
Subject: Re: [PATCH v2 2/7] Clear AC bit in RFLAGS to protect Xen itself by SMAPQuoted 7 lines · Feng Wu
Clear AC bit in RFLAGS at the beginning of exception, interrupt, hypercall, so Xen itself can be protected by SMAP mechanism.
Signed-off-by Feng Wu <[email protected]>--- xen/arch/x86/x86_64/compat/entry.S | 1 + xen/arch/x86/x86_64/entry.S | 26++++++++++++++++++++++++++
Review
Quoted 4 lines
xen/include/asm-x86/x86_64/asm_defns.h | 1 + 3 files changed, 28 insertions(+)(quoted diff) +0
-0
b/xen/arch/x86/x86_64/compat/entry.SQuoted 11 lines
index 32b3bcc..ac594c9 100644
xen/arch/x86/x86_64/compat/entry.S +1
-0@@ -13,6 +13,7 @@ #include <irq_vectors.h> ENTRY(compat_hypercall) + ASM_CLAC pushq $0 SAVE_VOLATILE type=TRAP_syscall compat=1
Quoted 12 lines
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 9 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLACSurely this can be sorted more succinctly by setting
X86_EFLAGS_ACin MSR0xc0000084?
Okay.
Quoted 2 lines
You also need to patch the entry points in the compat trampoline in
The MSR_SYSCALL_MASK is common in long mode and compat mode, right? Seems no need to do anything else for compat mode.
Quoted 17 lines
Quoted 15 lines
xen/arch/x86/x86_64/entry.S +1
-0sti movl $FLAT_KERNEL_SS,24(%rsp) pushq %rcx@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception...
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
.pushsection .init.text, "ax", @progbits
ENTRY(early_page_fault)
+ASM_CLACI don't think CLAC is appropriate here. This is a pagefault handler for Xen early boot, and is replaced with a real handler substantially before dom0 is created.
Adding CLAC here is not so useful, but harmful neither. If you think it should be removed, I will do that in the next post.
Quoted 30 lines
Quoted 30 lines
SAVE_ALL
movq %rsp,%rdi
calldo_early_page_faultxen/arch/x86/x86_64/entry.S +3
-0@@ -622,6 +644,7 @@ ENTRY(early_page_fault) .popsection ENTRY(nmi) + ASM_CLAC pushq $0 movl $TRAP_nmi,4(%rsp) handle_ist_exception:@@ -659,6 +682,7 @@ handle_ist_exception: jmp compat_restore_all_guest ENTRY(nmi_crash) + ASM_CLAC pushq $0 movl $TRAP_nmi,4(%rsp) SAVE_ALL@@ -667,6 +691,7 @@ ENTRY(nmi_crash) ud2 ENTRY(machine_check) + ASM_CLAC pushq $0 movl $TRAP_machine_check,4(%rsp) jmp handle_ist_exception@@ -689,6 +714,7 @@ ENTRY(enable_nmis)
Quoted 9 lines
xen/arch/x86/x86_64/entry.S ENTRY(enable_nmis) · line 718
Quoted 4 lines
xen/arch/x86/x86_64/entry.S +1
-0/* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretqThis is not sensible in the slightest, given the following instruction.
~Andrew
The same comments as early_page_fault case.
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +0
-0
b/xen/include/asm-x86/x86_64/asm_defns.h
Quoted 11 lines
xen/include/asm-x86/x86_64/asm_defns.h line 218
Quoted 11 lines
index bf63ac1..69f76b2 100644
xen/include/asm-x86/x86_64/asm_defns.h +1
-0@@ -212,6 +212,7 @@ __asm__( \"\n" __ALIGN_STR"\n" \"common_interrupt:\n\t" \ + ASM_CLAC(%)"\n\t" \ STR(SAVE_ALL) "\n\t" \"movq %rsp,%rdi\n\t" \ "callq " STR(do_IRQ) "\n\t" \
Thanks,
Feng
Quoted 14 lines
Quoted 13 lines
Quoted 1 line · On 24.04.14 at 08:45, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 7 lines · Feng Wu
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLACSurely this can be sorted more succinctly by setting
X86_EFLAGS_ACin MSR0xc0000084?
Quoted 7 lines
Okay.
Quoted 2 lines
You also need to patch the entry points in the compat trampoline in
The
MSR_SYSCALL_MASKis common in long mode and compat mode, right? Seems no need to do anything else for compat mode.
The same stub is being written there twice, just with different CS selectors, and both are behind that EFLAGS masking MSR. So I'm not sure what Andrew's apparently incomplete sentence was actually intended to mean.
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/x86_64/entry.S bad_hypercall: · line 275
Quoted 8 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0
Looking at this again, btw, makes me thing that the clac should go after the sti here.
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
xen/arch/x86/x86_64/entry.S +0
-0@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception...
Quoted 4 lines
.pushsection .init.text, "ax", @progbits
ENTRY(early_page_fault)
+ASM_CLAC
Quoted 6 lines
Quoted 3 lines
I don't think CLAC is appropriate here. This is a pagefault handler for Xen early boot, and is replaced with a real handler substantially before dom0 is created.
Adding CLAC here is not so useful, but harmful neither. If you think it should be removed, I will do that in the next post.
Yes, let's not scatter it around pointlessly (even more so now that you plan on enabling SMAP only after having built Dom0).
Quoted 10 lines
Quoted 8 lines
xen/arch/x86/x86_64/entry.S ENTRY(enable_nmis) · line 718
Quoted 6 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -689,6 +714,7 @@ ENTRY(enable_nmis) /* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretqThis is not sensible in the slightest, given the following instruction.
The same comments as
early_page_faultcase.
The situation is different here, but the addition indeed doesn't seem to make sense.
Jan
Quoted 29 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, April 24, 2014 3:19 PM
To: Wu, Feng
Cc: Andrew Cooper; [email protected]; Dong, Eddie; Nakajima, Jun; Tian, Kevin; [email protected]
Subject: RE: [PATCH v2 2/7] Clear AC bit in RFLAGS to protect Xen itself by SMAPQuoted 19 lines
Quoted 13 lines
Quoted 1 line · On 24.04.14 at 08:45, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 7 lines · Feng Wu
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLACSurely this can be sorted more succinctly by setting
X86_EFLAGS_ACin MSR0xc0000084?Okay.
Quoted 2 lines
You also need to patch the entry points in the compat trampoline in
Quoted 7 lines
Quoted 2 lines
The
MSR_SYSCALL_MASKis common in long mode and compat mode, right? Seems no need to do anything else for compat mode.The same stub is being written there twice, just with different CS selectors, and both are behind that EFLAGS masking MSR. So I'm not sure what Andrew's apparently incomplete sentence was actually intended to mean.
Yes, that is also my understanding.
Quoted 41 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/x86_64/entry.S bad_hypercall: · line 275
Quoted 9 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0Looking at this again, btw, makes me thing that the clac should go after the sti here.
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
xen/arch/x86/x86_64/entry.S +0
-0@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception...
Quoted 4 lines
.pushsection .init.text, "ax", @progbits
ENTRY(early_page_fault)
+ASM_CLACQuoted 6 lines
Quoted 3 lines
I don't think CLAC is appropriate here. This is a pagefault handler for Xen early boot, and is replaced with a real handler substantially before dom0 is created.
Adding CLAC here is not so useful, but harmful neither. If you think it should be removed, I will do that in the next post.
Yes, let's not scatter it around pointlessly (even more so now that you plan on enabling SMAP only after having built Dom0).
Quoted 9 lines
Quoted 8 lines
xen/arch/x86/x86_64/entry.S ENTRY(enable_nmis) · line 718
Quoted 6 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -689,6 +714,7 @@ ENTRY(enable_nmis) /* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretqThis is not sensible in the slightest, given the following instruction.
Quoted 6 lines
Quoted 1 line
The same comments as
early_page_faultcase.The situation is different here, but the addition indeed doesn't seem to make sense.
Jan
Thanks,
Feng
Quoted 23 lines · Feng
Quoted 23 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, April 24, 2014 3:19 PM
To: Wu, Feng
Cc: Andrew Cooper; [email protected]; Dong, Eddie; Nakajima, Jun; Tian, Kevin; [email protected]
Subject: RE: [PATCH v2 2/7] Clear AC bit in RFLAGS to protect Xen itself by SMAPQuoted 14 lines
Quoted 12 lines
Quoted 1 line · On 24.04.14 at 08:45, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 7 lines · Feng Wu
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLACSurely this can be sorted more succinctly by setting
X86_EFLAGS_ACin MSR0xc0000084?Okay.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
You also need to patch the entry points in the compat trampoline in
The
MSR_SYSCALL_MASKis common in long mode and compat mode, right? Seems no need to do anything else for compat mode.The same stub is being written there twice, just with different CS selectors, and both are behind that EFLAGS masking MSR. So I'm not sure what Andrew's apparently incomplete sentence was actually intended to mean.
Yes, that is also my understanding.
It was my mistake - I got the sysenter and syscall entry points confused given a brief look at the code yesterday. On more careful review it is currently fine.
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/x86_64/entry.S bad_hypercall: · line 275
Quoted 9 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0Looking at this again, btw, makes me thing that the clac should go after the sti here.
It must be after sysenter_eflags_saved, or we will erroneously clear the AC flag from the flags used to restore guest context.
Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/x86/x86_64/entry.S +0
-0@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception...
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
.pushsection .init.text, "ax", @progbits
ENTRY(early_page_fault)
+ASM_CLACI don't think CLAC is appropriate here. This is a pagefault handler for Xen early boot, and is replaced with a real handler substantially before dom0 is created.
Adding CLAC here is not so useful, but harmful neither. If you think it should be removed, I will do that in the next post.
Yes, let's not scatter it around pointlessly (even more so now that you plan on enabling SMAP only after having built Dom0).
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
xen/arch/x86/x86_64/entry.S +0
-0@@ -689,6 +714,7 @@ ENTRY(enable_nmis)
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
xen/arch/x86/x86_64/entry.S ENTRY(enable_nmis) · line 718
Quoted 4 lines
xen/arch/x86/x86_64/entry.S +1
-0/* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretqThis is not sensible in the slightest, given the following instruction.
The same comments as
early_page_faultcase.The situation is different here, but the addition indeed doesn't seem to make sense.
The handler is used to prevent NMIs and MCEs getting in the way of the crash path. Slowing down the return to the crash path is counter productive in all cases.
~Andrew
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 12:51, <[email protected]> wrote:
Quoted 7 lines · Feng
Quoted 7 lines
From: Jan Beulich [mailto:[email protected]]
Quoted 6 lines
Quoted 6 lines
Quoted 1 line · On 24.04.14 at 08:45, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
Quoted 3 lines · Feng Wu
xen/arch/x86/x86_64/entry.S +0
-0@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_eventsQuoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
xen/arch/x86/x86_64/entry.S bad_hypercall: · line 275
Quoted 5 lines
xen/arch/x86/x86_64/entry.S +1
-0ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0Looking at this again, btw, makes me thing that the clac should go after the sti here.
Quoted 2 lines
It must be after
sysenter_eflags_saved, or we will erroneously clear the AC flag from the flags used to restore guest context.
Indeed, and not just AC considering that the macro right now involves a conditional branch.
Jan
Quoted 27 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, April 24, 2014 7:37 PM
To: Andrew Cooper; Wu, Feng
Cc: [email protected]; Dong, Eddie; Nakajima, Jun; Tian, Kevin; [email protected]
Subject: Re: [PATCH v2 2/7] Clear AC bit in RFLAGS to protect Xen itself by SMAPQuoted 17 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 12:51, <[email protected]> wrote:
Quoted 14 lines · Feng
Quoted 14 lines
From: Jan Beulich [mailto:[email protected]]
Quoted 11 lines
Quoted 11 lines
Quoted 1 line · On 24.04.14 at 08:45, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
Review bad_hypercall: · line 275
Quoted 8 lines · Feng Wu
(quoted diff) +1
-0@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0Looking at this again, btw, makes me thing that the clac should go after the sti here.
Quoted 6 lines
Quoted 2 lines
It must be after
sysenter_eflags_saved, or we will erroneously clear the AC flag from the flags used to restore guest context.Indeed, and not just AC considering that the macro right now involves a conditional branch.
Thanks for your comments, I will change this, which may involve bugs here.
Quoted 1 line
Jan
Thanks,
Feng
Quoted 62 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: Thursday, April 24, 2014 6:51 PM
To: Wu, Feng
Cc: Jan Beulich; [email protected]; Dong, Eddie; Nakajima, Jun; Tian, Kevin; [email protected]
Subject: Re: [PATCH v2 2/7] Clear AC bit in RFLAGS to protect Xen itself by SMAPQuoted 6 lines · Feng
Quoted 6 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Thursday, April 24, 2014 3:19 PM
To: Wu, Feng
Cc: Andrew Cooper; [email protected]; Dong, Eddie; Nakajima, Jun;Tian,
Quoted 2 lines
Quoted 2 lines
Kevin; [email protected]
Subject: RE: [PATCH v2 2/7] Clear AC bit in RFLAGS to protect Xen itself bySMAP
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 2 lines · On 24.04.14 at 08:45, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 7 lines · Feng Wu
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLACSurely this can be sorted more succinctly by setting
X86_EFLAGS_ACin MSR0xc0000084?Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Okay.
Quoted 1 line
You also need to patch the entry points in the compat trampoline in
The
MSR_SYSCALL_MASKis common in long mode and compat mode,right?
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Seems no need to do anything else for compat mode.
The same stub is being written there twice, just with different CS selectors, and both are behind that EFLAGS masking MSR. So I'm not sure what Andrew's apparently incomplete sentence was actually intended to mean.
Yes, that is also my understanding.
It was my mistake - I got the sysenter and syscall entry points confused given a brief look at the code yesterday. On more careful review it is currently fine.
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/x86_64/entry.S bad_hypercall: · line 275
Quoted 9 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -268,6 +269,7 @@ bad_hypercall: jmp test_all_events ENTRY(sysenter_entry) + ASM_CLAC sti pushq $FLAT_USER_SS pushq $0Looking at this again, btw, makes me thing that the clac should go after the sti here.
Quoted 2 lines
It must be after
sysenter_eflags_saved, or we will erroneously clear the AC flag from the flags used to restore guest context.
Great comments, will follow it!
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
xen/arch/x86/x86_64/entry.S +0
-0@@ -309,6 +311,7 @@ UNLIKELY_END(sysenter_gpf) jmp .Lbounce_exception...
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
.pushsection .init.text, "ax", @progbits
ENTRY(early_page_fault)
+ASM_CLACI don't think CLAC is appropriate here. This is a pagefault handler for Xen early boot, and is replaced with a real handler substantially before dom0 is created.
Adding CLAC here is not so useful, but harmful neither. If you think it should be removed, I will do that in the next post.
Yes, let's not scatter it around pointlessly (even more so now that you plan on enabling SMAP only after having built Dom0).
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/x86_64/entry.S ENTRY(enable_nmis) · line 718
Quoted 6 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -689,6 +714,7 @@ ENTRY(enable_nmis) /* No op trap handler. Required for kexec crash path. */ GLOBAL(trap_nop) + ASM_CLAC iretqThis is not sensible in the slightest, given the following instruction.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
The same comments as
early_page_faultcase.The situation is different here, but the addition indeed doesn't seem to make sense.
The handler is used to prevent NMIs and MCEs getting in the way of the crash path. Slowing down the return to the crash path is counter productive in all cases.
Got it, thanks a lot for the clear explanation!
Quoted 1 line
~Andrew
xen/arch/x86/x86_64/entry.S restore_all_xen: · line 123
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 23.04.14 at 16:35, <[email protected]> wrote:
xen/arch/x86/x86_64/entry.S +1
-0@@ -120,6 +120,7 @@ restore_all_xen: * the space left by the trampoline. */ ENTRY(syscall_enter) + ASM_CLAC
This should be avoidable by instead adjusting the value written to MSR_SYSCALL_MASK.
xen/arch/x86/x86_64/entry.S ENTRY(ret_from_intr) · line 485
Quoted 8 lines
xen/arch/x86/x86_64/entry.S +1
-0@@ -476,6 +479,7 @@ ENTRY(ret_from_intr) jmp compat_test_all_events ENTRY(page_fault) + ASM_CLAC movl $TRAP_page_fault,4(%rsp) /* No special register assumptions. */ GLOBAL(handle_exception)
Considering that ASM_CLAC already contains a memory access (which hence isn't guarded) I wonder whether this wouldn't better be moved into handle_exception at least for now (reducing code redundancy).
Jan