linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: x86@kernel.org, jpoimboe@redhat.com
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	elver@google.com, jbaron@akamai.com, rostedt@goodmis.org,
	ardb@kernel.org, mark.rutland@arm.com
Subject: [PATCH 2/7] objtool: Extend UNWIND_HINT based ENDBR rules
Date: Thu, 26 May 2022 12:52:54 +0200	[thread overview]
Message-ID: <20220526105957.817269865@infradead.org> (raw)
In-Reply-To: 20220526105252.440440893@infradead.org

Extend the UNWIND hint driven rules for ENDBR placement. Currently
objtool expects an ENDBR at any UNWINT_HINT_IRET_REGS that is at +0 of
an STB_GLOBAL symbol, with the expectation that this is an exception
entry point.

Extend this to also expect ENDBR at UNWIND_HINT_EMPTY at +0 for
STB_GLOBAL symbols, with the expectation that these are also machine
entry points (SYSCALL et. al.).

This guarantees all machine entry points are covered by objtool rules at
the expense of a few additional false positives:

  vmlinux.o: warning: objtool: startup_64+0x0: UNWIND_HINT_EMPTY without ENDBR
  vmlinux.o: warning: objtool: start_cpu0+0x0: UNWIND_HINT_EMPTY without ENDBR

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/kernel/head_64.S |    2 ++
 tools/objtool/check.c     |   23 ++++++++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -43,6 +43,7 @@ L3_START_KERNEL = pud_index(__START_KERN
 	.code64
 SYM_CODE_START_NOALIGN(startup_64)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR
 	/*
 	 * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
 	 * and someone has loaded an identity mapped page table
@@ -371,6 +372,7 @@ SYM_CODE_END(secondary_startup_64)
  */
 SYM_CODE_START(start_cpu0)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR
 	movq	initial_stack(%rip), %rsp
 	jmp	.Ljump_to_C_code
 SYM_CODE_END(start_cpu0)
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1947,14 +1947,27 @@ static int read_unwind_hints(struct objt
 
 		insn->hint = true;
 
-		if (opts.ibt && hint->type == UNWIND_HINT_TYPE_REGS_PARTIAL) {
+		if (opts.ibt) {
 			struct symbol *sym = find_symbol_by_offset(insn->sec, insn->offset);
 
-			if (sym && sym->bind == STB_GLOBAL &&
-			    insn->type != INSN_ENDBR && !insn->noendbr) {
-				WARN_FUNC("UNWIND_HINT_IRET_REGS without ENDBR",
-					  insn->sec, insn->offset);
+			if (!sym || sym->bind != STB_GLOBAL)
+				goto no_entry;
+
+			if (hint->type == UNWIND_HINT_TYPE_CALL && !hint->sp_reg) {
+				if (insn->type != INSN_ENDBR && !insn->noendbr) {
+					WARN_FUNC("UNWIND_HINT_EMPTY without ENDBR",
+							insn->sec, insn->offset);
+				}
+			}
+
+			if (hint->type == UNWIND_HINT_TYPE_REGS_PARTIAL) {
+				if (insn->type != INSN_ENDBR && !insn->noendbr) {
+					WARN_FUNC("UNWIND_HINT_IRET_REGS without ENDBR",
+							insn->sec, insn->offset);
+				}
 			}
+
+no_entry:		;
 		}
 
 		if (hint->type == UNWIND_HINT_TYPE_FUNC) {



  parent reply	other threads:[~2022-05-26 11:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-26 10:52 [PATCH 0/7] x86: Address various objtool complaints Peter Zijlstra
2022-05-26 10:52 ` [PATCH 1/7] x86/entry: Anchor annotation Peter Zijlstra
2022-05-26 15:04   ` Josh Poimboeuf
2022-05-26 10:52 ` Peter Zijlstra [this message]
2022-05-26 15:05   ` [PATCH 2/7] objtool: Extend UNWIND_HINT based ENDBR rules Josh Poimboeuf
2022-05-28 14:09     ` Peter Zijlstra
2022-05-26 10:52 ` [PATCH 3/7] objtool: Mark __ubsan_handle_builtin_unreachable() as noreturn Peter Zijlstra
2022-05-30 13:17   ` Marco Elver
2022-05-26 10:52 ` [PATCH 4/7] x86/cpu: Elide KCSAN for cpu_has() and friends Peter Zijlstra
2022-05-30 13:14   ` Marco Elver
2022-05-26 10:52 ` [PATCH 5/7] jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds Peter Zijlstra
2022-05-30 13:20   ` Marco Elver
2022-05-26 10:52 ` [PATCH 6/7] x86: Always inline on_thread_stack() and current_top_of_stack() Peter Zijlstra
2022-05-30 10:38   ` [tip: objtool/urgent] " tip-bot2 for Peter Zijlstra
2022-05-30 13:21   ` [PATCH 6/7] " Marco Elver
2022-05-26 10:52 ` [PATCH 7/7] context_tracking: Always inline empty stubs Peter Zijlstra
2022-05-26 15:02   ` Josh Poimboeuf
2022-05-26 15:10     ` Mark Rutland
2022-05-26 15:16       ` Josh Poimboeuf
2022-05-26 15:26         ` Mark Rutland
2022-05-30 10:38   ` [tip: objtool/urgent] " tip-bot2 for 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=20220526105957.817269865@infradead.org \
    --to=peterz@infradead.org \
    --cc=ardb@kernel.org \
    --cc=elver@google.com \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.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;
as well as URLs for NNTP newsgroup(s).