lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 20 Aug 2020 17:51:34 +0200
From:   peterz@...radead.org
To:     Daniel Thompson <daniel.thompson@...aro.org>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Kyle Huey <me@...ehuey.com>,
        Alexandre Chartre <alexandre.chartre@...cle.com>,
        Robert O'Callahan <rocallahan@...il.com>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        Frederic Weisbecker <frederic@...nel.org>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Sean Christopherson <sean.j.christopherson@...el.com>,
        Masami Hiramatsu <mhiramat@...nel.org>,
        Petr Mladek <pmladek@...e.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Joel Fernandes <joel@...lfernandes.org>,
        Boris Ostrovsky <boris.ostrovsky@...cle.com>,
        Juergen Gross <jgross@...e.com>,
        Brian Gerst <brgerst@...il.com>,
        Andy Lutomirski <luto@...nel.org>,
        Josh Poimboeuf <jpoimboe@...hat.com>
Subject: Re: [RFC][PATCH 4/7] x86/debug: Move historical SYSENTER junk into
 exc_debug_kernel()

On Thu, Aug 20, 2020 at 04:28:28PM +0100, Daniel Thompson wrote:
> On Thu, Aug 20, 2020 at 12:38:36PM +0200, Peter Zijlstra wrote:
> > 
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> > ---
> >  arch/x86/kernel/traps.c |   24 ++++++++++++------------
> >  1 file changed, 12 insertions(+), 12 deletions(-)
> > 
> > --- a/arch/x86/kernel/traps.c
> > +++ b/arch/x86/kernel/traps.c
> > @@ -820,18 +820,6 @@ static void handle_debug(struct pt_regs
> >  		goto out;
> >  	}
> >  
> > -	if (WARN_ON_ONCE((dr6 & DR_STEP) && !user_mode(regs))) {
> > -		/*
> > -		 * Historical junk that used to handle SYSENTER single-stepping.
> > -		 * This should be unreachable now.  If we survive for a while
> > -		 * without anyone hitting this warning, we'll turn this into
> > -		 * an oops.
> > -		 */
> > -		tsk->thread.debugreg6 &= ~DR_STEP;
> > -		set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
> > -		regs->flags &= ~X86_EFLAGS_TF;
> > -	}
> > -
> >  	si_code = get_si_code(tsk->thread.debugreg6);
> >  	if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
> >  		send_sigtrap(regs, 0, si_code);
> > @@ -874,6 +862,18 @@ static __always_inline void exc_debug_ke
> >  	if (kprobe_debug_handler(regs))
> >  		goto out;
> >  
> > +	if (WARN_ON_ONCE(dr6 & DR_STEP)) {
> > +		/*
> > +		 * Historical junk that used to handle SYSENTER single-stepping.
> > +		 * This should be unreachable now.  If we survive for a while
> > +		 * without anyone hitting this warning, we'll turn this into
> > +		 * an oops.
> > +		 */
> > +		dr6 &= ~DR_STEP;
> > +		set_thread_flag(TIF_SINGLESTEP);
> > +		regs->flags &= ~X86_EFLAGS_TF;
> > +	}
> > +
> 
> I was hoping just to share a Tested-by: on the patchset but
> unfortunately it wasn't to be. After a quick bisect this patch comes
> back as causing kdb single stepping to fail.

Yeah, Josh just asked me about this:

  https://lkml.kernel.org/r/20200820152111.GC1362448@hirez.programming.kicks-ass.net

How's this on top of the lot?

---

--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -828,25 +828,24 @@ static __always_inline void exc_debug_ke
 	if (kprobe_debug_handler(regs))
 		goto out;
 
-	if (WARN_ON_ONCE(dr6 & DR_STEP)) {
-		/*
-		 * Historical junk that used to handle SYSENTER single-stepping.
-		 * This should be unreachable now.  If we survive for a while
-		 * without anyone hitting this warning, we'll turn this into
-		 * an oops.
-		 */
-		dr6 &= ~DR_STEP;
-		set_thread_flag(TIF_SINGLESTEP);
-		regs->flags &= ~X86_EFLAGS_TF;
-	}
-
 	/*
 	 * The kernel doesn't use INT1
 	 */
 	if (!dr6)
 		goto out;
 
-	notify_debug(regs, dr6);
+	if (notify_debug(regs, dr6))
+		goto out;
+
+	/*
+	 * The kernel doesn't use TF single-step outside of:
+	 *
+	 *  - Kprobes, consumed through kprobe_debug_handler()
+	 *  - KGDB, consumed through notify_debug()
+	 *
+	 * So if we get here with DR_STEP set, something is wonky.
+	 */
+	BUG_ON(current->thread.debugreg6 & DR_STEP);
 
 out:
 	instrumentation_end();

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ