linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
	Peter Anvin <h.peter.anvin@intel.com>,
	kernel test robot <xiaolong.ye@intel.com>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Lutomirski <luto@kernel.org>,
	Borislav Petkov <bp@alien8.de>, Brian Gerst <brgerst@gmail.com>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Peter Anvin <hpa@zytor.com>, tipbuild@zytor.com, LKP <lkp@01.org>
Subject: [PATCH] objtool: Detect assembly code falling through to INT3 padding
Date: Thu, 17 May 2018 08:49:34 -0500	[thread overview]
Message-ID: <20180517134934.eog2fgoby5azq5a7@treble> (raw)
In-Reply-To: <20180516033044.odb74pdgcn5nacwb@treble>

With the following commit:

  51bad67ffbce ("x86/asm: Pad assembly functions with INT3 instructions")

... asm function alignments are padded with INT3, so it's no longer safe
to fall through to an aligned function.  Make sure we catch any such
cases with objtool.

Note this only adds checking for 64-bit, since objtool doesn't support
x86-32.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 arch/x86/kernel/head_64.S       |  2 --
 tools/objtool/arch.h            |  3 ++-
 tools/objtool/arch/x86/decode.c |  2 +-
 tools/objtool/check.c           | 11 ++++++++++-
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 8344dd2f310a..3ed8cec6e765 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -285,11 +285,9 @@ ENTRY(early_idt_handler_array)
 	.endif
 	pushq $i		# 72(%rsp) Vector number
 	jmp early_idt_handler_common
-	UNWIND_HINT_IRET_REGS
 	i = i + 1
 	.fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
 	.endr
-	UNWIND_HINT_IRET_REGS offset=16
 END(early_idt_handler_array)
 
 early_idt_handler_common:
diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index b0d7dc3d71b5..6eb058a8ac00 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -33,7 +33,8 @@
 #define INSN_STACK		8
 #define INSN_BUG		9
 #define INSN_NOP		10
-#define INSN_OTHER		11
+#define INSN_PADDING		11
+#define INSN_OTHER		12
 #define INSN_LAST		INSN_OTHER
 
 enum op_dest_type {
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 7e86a743f851..82b41bb93c02 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -421,7 +421,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 
 	case 0xcc:
 		/* int3: used for asm function padding by the __ALIGN macro */
-		*type = INSN_NOP;
+		*type = INSN_PADDING;
 		break;
 
 	case 0xe3:
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index f4bbce838433..4d387448519f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1936,6 +1936,14 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
 			}
 			return 0;
 
+		case INSN_PADDING:
+			if (!file->c_file) {
+				WARN_FUNC("code falls through to INT3 padding",
+					  insn->sec, insn->offset);
+				return 1;
+			}
+			break;
+
 		case INSN_STACK:
 			if (update_insn_state(insn, &state))
 				return 1;
@@ -2032,7 +2040,8 @@ static bool ignore_unreachable_insn(struct instruction *insn)
 {
 	int i;
 
-	if (insn->ignore || insn->type == INSN_NOP)
+	if (insn->ignore || insn->type == INSN_NOP ||
+	    insn->type == INSN_PADDING)
 		return true;
 
 	/*
-- 
2.17.0

  reply	other threads:[~2018-05-17 13:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-15  8:00 [lkp-robot] [x86/asm] 51bad67ffb: int3:#[##] kernel test robot
2018-05-15 21:07 ` Alexey Dobriyan
     [not found]   ` <C40DC70F50313144AB3AF8625D4F407F90689B42@ORSMSX101.amr.corp.intel.com>
2018-05-15 21:43     ` Alexey Dobriyan
2018-05-15 22:22       ` Josh Poimboeuf
2018-05-15 22:26         ` Thomas Gleixner
2018-05-15 22:28         ` Linus Torvalds
2018-05-15 22:43           ` Josh Poimboeuf
2018-05-15 22:52             ` Linus Torvalds
2018-05-15 23:05               ` Linus Torvalds
2018-05-16  3:30                 ` Josh Poimboeuf
2018-05-17 13:49                   ` Josh Poimboeuf [this message]
2018-05-17 14:01                     ` [PATCH] objtool: Detect assembly code falling through to INT3 padding Peter Zijlstra
2018-05-18  7:24                       ` Ingo Molnar
2018-05-18  7:18                     ` Ingo Molnar
2018-05-18  7:27                       ` H. Peter Anvin
2018-05-18 16:06                         ` Borislav Petkov
2018-05-18  7:27                       ` Ingo Molnar
2018-05-18 17:51                       ` Alexey Dobriyan
2018-05-19  8:18                         ` hpa
2018-05-19  7:00                 ` "interesting" entry in hibernation code was Re: [lkp-robot] [x86/asm] 51bad67ffb: int3:#[##] Pavel Machek
2018-05-19  8:35                   ` Rafael J. Wysocki
2018-05-18  7:15               ` Ingo Molnar
2018-05-15 22:25       ` Thomas Gleixner
2018-05-15 22:29         ` Andy Lutomirski
2018-05-15 22:27       ` Linus Torvalds
2018-05-15 22:50         ` Alexey Dobriyan
2018-05-15 22:58           ` [PATCH v2] x86/asm: Pad assembly functions with INT3 instructions Alexey Dobriyan
2018-05-15 23:28             ` Linus Torvalds
2018-05-18  7:36             ` Ingo Molnar
2018-05-18 13:02               ` Josh Poimboeuf
2018-05-18 17:34                 ` Alexey Dobriyan

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=20180517134934.eog2fgoby5azq5a7@treble \
    --to=jpoimboe@redhat.com \
    --cc=adobriyan@gmail.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=h.peter.anvin@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@01.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tipbuild@zytor.com \
    --cc=torvalds@linux-foundation.org \
    --cc=xiaolong.ye@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).