x86/asm/entry/64: Enable interrupts *after* we fetch PER_CPU_VAR(old_rsp)
PATCH v2 1/2 x86/asm/entry/64: Enable interrupts *after* we fetch PER_CPU_VAR(old_rsp)
Without this change, it is still not possible to get rid of PER_CPU_VAR(old_rsp) usage in switch_to: if preemption happens while we did not fetch PER_CPU_VAR(old_rsp) and stored it in pt_regs->sp, PER_CPU_VAR(old_rsp) gets corrupted by other task's user sp.
---
Changes since v1: don't try to be clever and use CLBR_RAX
arch/x86/kernel/entry_64.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/entry_64.S +5 -5
@@ -241,17 +241,17 @@ GLOBAL(system_call_after_swapgs) movq %rsp,PER_CPU_VAR(old_rsp) /* kernel_stack is set so that 5 slots (iret frame) are preallocated */ movq PER_CPU_VAR(kernel_stack),%rsp - /* - * No need to follow this irqs off/on section - it's straight - * and short: - */ - ENABLE_INTERRUPTS(CLBR_NONE) ALLOC_PT_GPREGS_ON_STACK 8 /* +8: space for orig_ax */ movq %rcx,RIP(%rsp) movq PER_CPU_VAR(old_rsp),%rcx movq %r11,EFLAGS(%rsp) movq %rcx,RSP(%rsp) + /* + * No need to follow this irqs off/on section - it's straight + * and short: + */ + ENABLE_INTERRUPTS(CLBR_NONE) movq_cfi rax,ORIG_RAX SAVE_C_REGS_EXCEPT_RAX_RCX_R11 movq $-ENOSYS,RAX(%rsp) CFI_REL_OFFSET rip,RIP
Signature · 1 line
1.8.1.4
Borislav Petkov
maintainerQuoted 19 lines · Denys Vlasenko
Without this change, it is still not possible to get rid of
PER_CPU_VAR(old_rsp)usage inswitch_to: if preemption happens while we did not fetchPER_CPU_VAR(old_rsp)and stored it inpt_regs->sp,PER_CPU_VAR(old_rsp)gets corrupted by other task's user sp.Signed-off-by Denys Vlasenko <[email protected]>CC Linus Torvalds <[email protected]>CC Steven Rostedt <[email protected]>CC Ingo Molnar <[email protected]>CC Borislav Petkov <[email protected]>CC "H. Peter Anvin" <[email protected]>CC Andy Lutomirski <[email protected]>CC Oleg Nesterov <[email protected]>CC Frederic Weisbecker <[email protected]>CC Alexei Starovoitov <[email protected]>CC Will Drewry <[email protected]>CC Kees Cook <[email protected]>
Quoted 6 lines
---
Changes since v1: don't try to be clever and use
CLBR_RAXarch/x86/kernel/entry_64.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Thanks Denys!
Signature · 5 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.
--Quoted 4 lines · Denys Vlasenko
Without this change, it is still not possible to get rid of
PER_CPU_VAR(old_rsp)usage inswitch_to: if preemption happens while we did not fetchPER_CPU_VAR(old_rsp)and stored it inpt_regs->sp,PER_CPU_VAR(old_rsp)gets corrupted by other task's user sp.
Well, wouldn't this be a much clearer explanation:
"We want to use PER_CPU_VAR(old_rsp) as a simple temporary register,
to shuffle user-space RSP into (and from) when we set up the system call stack frame. At that point we cannot shuffle values into general purpose registers, because we have not saved them yet.
To be able to do this shuffling into a memory location, we must be atomic and must not be preempted while we do the shuffling, otherwise the 'temporary' register gets overwritten by some other task's temporary register contents ..."
Agreed?
Thanks,
Ingo
Quoted 15 lines · Ingo Molnar
Quoted 4 lines · Denys Vlasenko
Without this change, it is still not possible to get rid of
PER_CPU_VAR(old_rsp)usage inswitch_to: if preemption happens while we did not fetchPER_CPU_VAR(old_rsp)and stored it inpt_regs->sp,PER_CPU_VAR(old_rsp)gets corrupted by other task's user sp.Well, wouldn't this be a much clearer explanation:
"We want to use
PER_CPU_VAR(old_rsp)as a simple temporary register,
to shuffle user-space RSP into (and from) when we set up the system call stack frame. At that point we cannot shuffle values into general purpose registers, because we have not saved them yet.
Quoted 6 lines
To be able to do this shuffling into a memory location, we must be atomic and must not be preempted while we do the shuffling, otherwise the 'temporary' register gets overwritten by some other task's temporary register contents ..."
Agreed?
Sounds good to me.
tip-bot for Denys Vlasenko
merge botx86/asm/entry/64: Enable interrupts *after* we fetch PER_CPU_VAR(old_rsp)
Commit-ID: 33db1fd48ac3d90385b412b41a8a6525096ac6d5 Gitweb: http://git.kernel.org/tip/33db1fd48ac3d90385b412b41a8a6525096ac6d5 Author: Denys Vlasenko <[email protected]> AuthorDate: Tue, 17 Mar 2015 14:52:24 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 17 Mar 2015 16:01:40 +0100
x86/asm/entry/64: Enable interrupts *after* we fetch PER_CPU_VAR(old_rsp)
We want to use PER_CPU_VAR(old_rsp) as a simple temporary register, to shuffle user-space RSP into (and from) when we set up the system call stack frame. At that point we cannot shuffle values into general purpose registers, because we have not saved them yet.
To be able to do this shuffling into a memory location, we must be atomic and must not be preempted while we do the shuffling, otherwise the 'temporary' register gets overwritten by some other task's temporary register contents ...
--- arch/x86/kernel/entry_64.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/x86/kernel/entry_64.S +5 -5
@@ -241,16 +241,16 @@ GLOBAL(system_call_after_swapgs) movq %rsp,PER_CPU_VAR(old_rsp) /* kernel_stack is set so that 5 slots (iret frame) are preallocated */ movq PER_CPU_VAR(kernel_stack),%rsp - /* - * No need to follow this irqs off/on section - it's straight - * and short: - */ - ENABLE_INTERRUPTS(CLBR_NONE) ALLOC_PT_GPREGS_ON_STACK 8 /* +8: space for orig_ax */ movq %rcx,RIP(%rsp) movq PER_CPU_VAR(old_rsp),%rcx movq %r11,EFLAGS(%rsp) movq %rcx,RSP(%rsp) + /* + * No need to follow this irqs off/on section - it's straight + * and short: + */ + ENABLE_INTERRUPTS(CLBR_NONE) movq_cfi rax,ORIG_RAX SAVE_C_REGS_EXCEPT_RAX_RCX_R11 movq $-ENOSYS,RAX(%rsp)