public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Andy Lutomirski <luto@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>, X86 ML <x86@kernel.org>,
	Dmitry Vyukov <dvyukov@google.com>,
	Marco Elver <elver@google.com>,
	Andrey Konovalov <andreyknvl@google.com>,
	Mark Rutland <Mark.Rutland@arm.com>,
	Matthew Helsley <mhelsley@vmware.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	jthierry@redhat.com, Miroslav Benes <mbenes@suse.cz>
Subject: Re: [PATCH 1/7] x86/entry: Fix #UD vs WARN more
Date: Thu, 18 Jun 2020 21:02:07 +0200	[thread overview]
Message-ID: <20200618190207.GO576905@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <CALCETrWvrmuuTqZzhGswsFSCWxO3tuVBiJ+M4a=Negqwo1dyNA@mail.gmail.com>

On Thu, Jun 18, 2020 at 11:36:53AM -0700, Andy Lutomirski wrote:

> I wasn't imagining going far down the rabbit hole at all -- I think
> that, at most, we should cover the path for when the fault wasn't a
> BUG/WARN in the first place.  I admit that, for #UD in particular,
> this isn't a big deal, but if it were a different vector, this could
> matter.

Right, so there's 3 cases for ud2:

 - WARN;  ud2,  bug_entry, recovers
 - BUG;   ud2,  bug_entry, dies
 - UBSAN; ud2, !bug_entry, dies

Nothing else should be generating ud2 instructions, any other #UD goes
into handle_invalid_op() -> do_error_trap() -> ... -> die().

[ while there, we should probably restructure do_trap() to have
  cond_local_irq_enable() _after_ do_trap_no_signal(). ]

We could probably change is_valid_bugaddr() to not use
probe_kernel_address(), because if it couldn't read the instruction,
we'd not be getting #UD in the first place.

If we've gotten rid of probe_kernel_address() we can noinstr/inline that
and then we can only call into report_bug() IFF ud2.

Does that make things 'better' ? This can only go realy bad if there's a
1 byte instruction that triggers #UD, but I think that was ruled out.


---
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index c26751e303f1..275a621f1aff 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -91,10 +91,7 @@ int is_valid_bugaddr(unsigned long addr)
 	if (addr < TASK_SIZE_MAX)
 		return 0;
 
-	if (probe_kernel_address((unsigned short *)addr, ud))
-		return 0;
-
-	return ud == INSN_UD0 || ud == INSN_UD2;
+	return *(unsigned short *)addr == INSN_UD2;
 }
 
 static nokprobe_inline int
@@ -220,15 +217,17 @@ static noinstr bool handle_bug(struct pt_regs *regs)
 {
 	bool handled = false;
 
-	/*
-	 * All lies, just get the WARN/BUG out.
-	 */
-	instrumentation_begin();
-	if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) {
-		regs->ip += LEN_UD2;
-		handled = true;
+	if (is_valid_bugaddr(regs->ip)) {
+		/*
+		 * All lies, just get the WARN/BUG out.
+		 */
+		instrumentation_begin();
+		if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) {
+			regs->ip += LEN_UD2;
+			handled = true;
+		}
+		instrumentation_end();
 	}
-	instrumentation_end();
 
 	return handled;
 }

  reply	other threads:[~2020-06-18 19:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-18 14:44 [PATCH 0/7] x86/entry: noinstr fixes Peter Zijlstra
2020-06-18 14:44 ` [PATCH 1/7] x86/entry: Fix #UD vs WARN more Peter Zijlstra
2020-06-18 14:57   ` Andy Lutomirski
2020-06-18 15:50     ` Peter Zijlstra
2020-06-18 18:36       ` Andy Lutomirski
2020-06-18 19:02         ` Peter Zijlstra [this message]
2020-06-18 19:29           ` Andy Lutomirski
2020-06-18 21:18             ` Peter Zijlstra
2020-06-22 11:47               ` Peter Zijlstra
2020-06-24 22:37                 ` Andy Lutomirski
2020-06-25 11:53                 ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-18 14:44 ` [PATCH 2/7] objtool: Dont consider vmlinux a C-file Peter Zijlstra
2020-06-25 11:53   ` [tip: x86/entry] objtool: Don't " tip-bot2 for Peter Zijlstra
2020-06-18 14:44 ` [PATCH 3/7] x86/entry: Fixup bad_iret vs noinstr Peter Zijlstra
2020-06-18 15:13   ` Marco Elver
2020-06-25 11:53   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-18 14:44 ` [PATCH 4/7] x86/entry: Increase entry_stack size to a full page Peter Zijlstra
2020-06-18 15:06   ` Marco Elver
2020-06-19  3:10   ` Lai Jiangshan
2020-06-25 11:53   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-18 14:44 ` [PATCH 5/7] objtool: Clean up elf_write() condition Peter Zijlstra
2020-06-18 14:44 ` [PATCH 6/7] objtool: Provide elf_write_{insn,reloc}() Peter Zijlstra
2020-06-18 14:44 ` [PATCH 7/7] objtool: Fix noinstr vs KCOV Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200618190207.GO576905@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Mark.Rutland@arm.com \
    --cc=andreyknvl@google.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=jthierry@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=mhelsley@vmware.com \
    --cc=rostedt@goodmis.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox