[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200220123742.GZ18400@hirez.programming.kicks-ass.net>
Date: Thu, 20 Feb 2020 13:37:42 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Borislav Petkov <bp@...en8.de>
Cc: Steven Rostedt <rostedt@...dmis.org>, linux-kernel@...r.kernel.org,
linux-arch@...r.kernel.org, mingo@...nel.org,
joel@...lfernandes.org, gregkh@...uxfoundation.org,
gustavo@...eddedor.com, tglx@...utronix.de, paulmck@...nel.org,
josh@...htriplett.org, mathieu.desnoyers@...icios.com,
jiangshanlai@...il.com, luto@...nel.org, tony.luck@...el.com,
frederic@...nel.org, dan.carpenter@...cle.com, mhiramat@...nel.org
Subject: Re: [PATCH v3 04/22] x86/doublefault: Make memmove() notrace/NOKPROBE
On Thu, Feb 20, 2020 at 01:17:27PM +0100, Borislav Petkov wrote:
> On Wed, Feb 19, 2020 at 04:57:15PM +0100, Peter Zijlstra wrote:
> > - memmove(&gpregs->ip, (void *)regs->sp, 5*8);
> > + for (i = 0; i < count; i++) {
> > + int idx = (dst <= src) ? i : count - i;
> > + dst[idx] = src[idx];
> > + }
>
> Or, you can actually unroll it. This way it even documents clearly what
> it does:
>
> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> index fe38015ed50a..2b790a574ba5 100644
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -298,6 +298,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
> @@ -305,7 +306,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;
> + 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 */
>
> /*
While I love that; is that actually correct? This is an unroll of
memcpy() not memmove(). IFF the ranges overlap, the above is buggered.
Was the original memmove() really needed?
Powered by blists - more mailing lists