linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH] objtool: WARN about ENDBR instructions
@ 2021-02-10  8:39 Peter Zijlstra
  2021-02-10 16:09 ` Josh Poimboeuf
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2021-02-10  8:39 UTC (permalink / raw)
  To: Josh Poimboeuf, Linus Torvalds, Dave Hansen, x86, linux-kernel
  Cc: Steven Rostedt, yu-cheng.yu



Given all the ENDBR fun we recently had, do we want the below? Until
someone comes and fixes up kprobes/ftrace/livepatch etc.. having them is
a giant pain and we'd better warn about it.

---
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 931cef78b857..e708731b10cd 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -91,7 +91,7 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 {
 	struct insn insn;
 	int x86_64, sign;
-	unsigned char op1, op2, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0,
+	unsigned char op1, op2, pfx = 0, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0,
 		      rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0,
 		      modrm_reg = 0, sib = 0;
 	struct stack_op *op = NULL;
@@ -118,6 +118,9 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 	op1 = insn.opcode.bytes[0];
 	op2 = insn.opcode.bytes[1];
 
+	if (insn.prefixes.nbytes)
+		pfx = insn.prefixes.bytes[0];
+
 	if (insn.rex_prefix.nbytes) {
 		rex = insn.rex_prefix.bytes[0];
 		rex_w = X86_REX_W(rex) >> 3;
@@ -444,6 +447,11 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 			/* nopl/nopw */
 			*type = INSN_NOP;
 
+		} else if (op2 == 0x1e && pfx == 0xf3 && (modrm == 0xfa || modrm == 0xfb)) {
+
+			/* endbr32/endbr64 */
+			WARN("endbr32/64 instruction at %s:0x%lx", sec->name, offset);
+
 		} else if (op2 == 0xa0 || op2 == 0xa8) {
 
 			/* push fs/gs */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] objtool: WARN about ENDBR instructions
  2021-02-10  8:39 [RFC][PATCH] objtool: WARN about ENDBR instructions Peter Zijlstra
@ 2021-02-10 16:09 ` Josh Poimboeuf
  2021-02-10 17:01   ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Poimboeuf @ 2021-02-10 16:09 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Linus Torvalds, Dave Hansen, x86, linux-kernel, Steven Rostedt,
	yu-cheng.yu

On Wed, Feb 10, 2021 at 09:39:53AM +0100, Peter Zijlstra wrote:
> 
> 
> Given all the ENDBR fun we recently had, do we want the below? Until
> someone comes and fixes up kprobes/ftrace/livepatch etc.. having them is
> a giant pain and we'd better warn about it.

Meh...

Is there a point in doing this, now that we killed it with
-fcf-protection=none?

That said, the patch is nicely small and localized.

-- 
Josh


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC][PATCH] objtool: WARN about ENDBR instructions
  2021-02-10 16:09 ` Josh Poimboeuf
@ 2021-02-10 17:01   ` Peter Zijlstra
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2021-02-10 17:01 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Linus Torvalds, Dave Hansen, x86, linux-kernel, Steven Rostedt,
	yu-cheng.yu

On Wed, Feb 10, 2021 at 10:09:45AM -0600, Josh Poimboeuf wrote:
> On Wed, Feb 10, 2021 at 09:39:53AM +0100, Peter Zijlstra wrote:
> > 
> > 
> > Given all the ENDBR fun we recently had, do we want the below? Until
> > someone comes and fixes up kprobes/ftrace/livepatch etc.. having them is
> > a giant pain and we'd better warn about it.
> 
> Meh...
> 
> Is there a point in doing this, now that we killed it with
> -fcf-protection=none?
> 
> That said, the patch is nicely small and localized.

Yeah, paranoia, just making absolutely sure it doesn't sneak back in
unexpected.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-10 17:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10  8:39 [RFC][PATCH] objtool: WARN about ENDBR instructions Peter Zijlstra
2021-02-10 16:09 ` Josh Poimboeuf
2021-02-10 17:01   ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).