2020-05-05 14:16:16

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V4 part 1 08/36] x86/doublefault: Remove memmove() call

Use of memmove() in #DF is problematic considered tracing and other
instrumentation.

Remove the memmove() call and simply write out what needs doing; this
even clarifies the code, win-win! The code copies from the espfix64
stack to the normal task stack, there is no possible way for that to
overlap.

Survives selftests/x86, specifically sigreturn_64.

Suggested-by: Borislav Petkov <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Andy Lutomirski <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/kernel/traps.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -278,6 +278,7 @@ dotraplinkage void do_double_fault(struc
regs->ip == (unsigned long)native_irq_return_iret)
{
struct pt_regs *gpregs = (struct pt_regs *)this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1;
+ unsigned long *p = (unsigned long *)regs->sp;

/*
* regs->sp points to the failing IRET frame on the
@@ -285,7 +286,11 @@ dotraplinkage void do_double_fault(struc
* in gpregs->ss through gpregs->ip.
*
*/
- memmove(&gpregs->ip, (void *)regs->sp, 5*8);
+ gpregs->ip = p[0];
+ gpregs->cs = p[1];
+ gpregs->flags = p[2];
+ gpregs->sp = p[3];
+ gpregs->ss = p[4];
gpregs->orig_ax = 0; /* Missing (lost) #GP error code */

/*


2020-05-06 23:05:11

by Alexandre Chartre

[permalink] [raw]
Subject: Re: [patch V4 part 1 08/36] x86/doublefault: Remove memmove() call


On 5/5/20 3:16 PM, Thomas Gleixner wrote:
> Use of memmove() in #DF is problematic considered tracing and other
> instrumentation.
>
> Remove the memmove() call and simply write out what needs doing; this
> even clarifies the code, win-win! The code copies from the espfix64
> stack to the normal task stack, there is no possible way for that to
> overlap.
>
> Survives selftests/x86, specifically sigreturn_64.
>
> Suggested-by: Borislav Petkov <[email protected]>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Acked-by: Andy Lutomirski <[email protected]>
> Link: https://lkml.kernel.org/r/[email protected]
> ---
> arch/x86/kernel/traps.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Alexandre Chartre <[email protected]>

alex.

> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -278,6 +278,7 @@ dotraplinkage void do_double_fault(struc
> regs->ip == (unsigned long)native_irq_return_iret)
> {
> struct pt_regs *gpregs = (struct pt_regs *)this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1;
> + unsigned long *p = (unsigned long *)regs->sp;
>
> /*
> * regs->sp points to the failing IRET frame on the
> @@ -285,7 +286,11 @@ dotraplinkage void do_double_fault(struc
> * in gpregs->ss through gpregs->ip.
> *
> */
> - memmove(&gpregs->ip, (void *)regs->sp, 5*8);
> + gpregs->ip = p[0];
> + gpregs->cs = p[1];
> + gpregs->flags = p[2];
> + gpregs->sp = p[3];
> + gpregs->ss = p[4];
> gpregs->orig_ax = 0; /* Missing (lost) #GP error code */
>
> /*
>

Subject: [tip: x86/entry] x86/doublefault: Remove memmove() call

The following commit has been merged into the x86/entry branch of tip:

Commit-ID: f44e70325748c7998cf089d2ae67b4b5bc8d8ad9
Gitweb: https://git.kernel.org/tip/f44e70325748c7998cf089d2ae67b4b5bc8d8ad9
Author: Peter Zijlstra <[email protected]>
AuthorDate: Thu, 20 Feb 2020 13:17:27 +01:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Fri, 15 May 2020 20:03:04 +02:00

x86/doublefault: Remove memmove() call

Use of memmove() in #DF is problematic considered tracing and other
instrumentation.

Remove the memmove() call and simply write out what needs doing; this
even clarifies the code, win-win! The code copies from the espfix64
stack to the normal task stack, there is no possible way for that to
overlap.

Survives selftests/x86, specifically sigreturn_64.

Suggested-by: Borislav Petkov <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Alexandre Chartre <[email protected]>
Acked-by: Andy Lutomirski <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/kernel/traps.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index e85561f..75fa765 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -369,6 +369,7 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsign
regs->ip == (unsigned long)native_irq_return_iret)
{
struct pt_regs *gpregs = (struct pt_regs *)this_cpu_read(cpu_tss_rw.x86_tss.sp0) - 1;
+ unsigned long *p = (unsigned long *)regs->sp;

/*
* regs->sp points to the failing IRET frame on the
@@ -376,7 +377,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code, unsign
* in gpregs->ss through gpregs->ip.
*
*/
- memmove(&gpregs->ip, (void *)regs->sp, 5*8);
+ gpregs->ip = p[0];
+ gpregs->cs = p[1];
+ gpregs->flags = p[2];
+ gpregs->sp = p[3];
+ gpregs->ss = p[4];
gpregs->orig_ax = 0; /* Missing (lost) #GP error code */

/*