All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	clang-built-linux@googlegroups.com,
	Miroslav Benes <mbenes@suse.cz>
Subject: [PATCH v2 06/20] objtool: Assume only ELF functions do sibling calls
Date: Thu, 21 Jan 2021 15:29:22 -0600	[thread overview]
Message-ID: <0e9ab6f3628cc7bf3bde7aa6762d54d7df19ad78.1611263461.git.jpoimboe@redhat.com> (raw)
In-Reply-To: <cover.1611263461.git.jpoimboe@redhat.com>

There's an inconsistency in how sibling calls are detected in
non-function asm code, depending on the scope of the object.  If the
target code is external to the object, objtool considers it a sibling
call.  If the target code is internal but not a function, objtool
*doesn't* consider it a sibling call.

This can cause some inconsistencies between per-object and vmlinux.o
validation.

Instead, assume only ELF functions can do sibling calls.  This generally
matches existing reality, and makes sibling call validation consistent
between vmlinux.o and per-object.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/objtool/check.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 5f5949951ca7..b4e1655017de 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -110,15 +110,20 @@ static struct instruction *prev_insn_same_sym(struct objtool_file *file,
 
 static bool is_sibling_call(struct instruction *insn)
 {
+	/*
+	 * Assume only ELF functions can make sibling calls.  This ensures
+	 * sibling call detection consistency between vmlinux.o and individual
+	 * objects.
+	 */
+	if (!insn->func)
+		return false;
+
 	/* An indirect jump is either a sibling call or a jump to a table. */
 	if (insn->type == INSN_JUMP_DYNAMIC)
 		return list_empty(&insn->alts);
 
-	if (!is_static_jump(insn))
-		return false;
-
 	/* add_jump_destinations() sets insn->call_dest for sibling calls. */
-	return !!insn->call_dest;
+	return (is_static_jump(insn) && insn->call_dest);
 }
 
 /*
@@ -774,7 +779,7 @@ static int add_jump_destinations(struct objtool_file *file)
 			continue;
 
 		reloc = find_reloc_by_dest_range(file->elf, insn->sec,
-					       insn->offset, insn->len);
+						 insn->offset, insn->len);
 		if (!reloc) {
 			dest_sec = insn->sec;
 			dest_off = arch_jump_destination(insn);
@@ -794,18 +799,21 @@ static int add_jump_destinations(struct objtool_file *file)
 
 			insn->retpoline_safe = true;
 			continue;
-		} else if (reloc->sym->sec->idx) {
-			dest_sec = reloc->sym->sec;
-			dest_off = reloc->sym->sym.st_value +
-				   arch_dest_reloc_offset(reloc->addend);
-		} else {
-			/* external sibling call */
+		} else if (insn->func) {
+			/* internal or external sibling call (with reloc) */
 			insn->call_dest = reloc->sym;
 			if (insn->call_dest->static_call_tramp) {
 				list_add_tail(&insn->static_call_node,
 					      &file->static_call_list);
 			}
 			continue;
+		} else if (reloc->sym->sec->idx) {
+			dest_sec = reloc->sym->sec;
+			dest_off = reloc->sym->sym.st_value +
+				   arch_dest_reloc_offset(reloc->addend);
+		} else {
+			/* non-func asm code jumping to another file */
+			continue;
 		}
 
 		insn->jump_dest = find_insn(file, dest_sec, dest_off);
@@ -854,7 +862,7 @@ static int add_jump_destinations(struct objtool_file *file)
 			} else if (insn->jump_dest->func->pfunc != insn->func->pfunc &&
 				   insn->jump_dest->offset == insn->jump_dest->func->offset) {
 
-				/* internal sibling call */
+				/* internal sibling call (without reloc) */
 				insn->call_dest = insn->jump_dest->func;
 				if (insn->call_dest->static_call_tramp) {
 					list_add_tail(&insn->static_call_node,
@@ -2587,7 +2595,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 
 		case INSN_JUMP_CONDITIONAL:
 		case INSN_JUMP_UNCONDITIONAL:
-			if (func && is_sibling_call(insn)) {
+			if (is_sibling_call(insn)) {
 				ret = validate_sibling_call(insn, &state);
 				if (ret)
 					return ret;
@@ -2609,7 +2617,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
 
 		case INSN_JUMP_DYNAMIC:
 		case INSN_JUMP_DYNAMIC_CONDITIONAL:
-			if (func && is_sibling_call(insn)) {
+			if (is_sibling_call(insn)) {
 				ret = validate_sibling_call(insn, &state);
 				if (ret)
 					return ret;
-- 
2.29.2


  parent reply	other threads:[~2021-01-21 21:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 21:29 [PATCH v2 00/20] objtool: vmlinux.o and CLANG LTO support Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 01/20] objtool: Fix error handling for STD/CLD warnings Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 02/20] objtool: Fix retpoline detection in asm code Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 03/20] objtool: Fix ".cold" section suffix check for newer versions of GCC Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 04/20] objtool: Support retpoline jump detection for vmlinux.o Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 05/20] x86/ftrace: Add UNWIND_HINT_FUNC annotation for ftrace_stub Josh Poimboeuf
2021-01-21 21:29 ` Josh Poimboeuf [this message]
2021-01-21 21:29 ` [PATCH v2 07/20] objtool: Add asm version of STACK_FRAME_NON_STANDARD Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 08/20] objtool: Combine UNWIND_HINT_RET_OFFSET and UNWIND_HINT_FUNC Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 09/20] objtool: Add xen_start_kernel() to noreturn list Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 10/20] objtool: Move unsuffixed symbol conversion to a helper function Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 11/20] objtool: Add CONFIG_CFI_CLANG support Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 12/20] x86/xen: Support objtool validation in xen-asm.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 13/20] x86/xen: Support objtool vmlinux.o validation in xen-head.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 14/20] x86/xen/pvh: Annotate indirect branch as safe Josh Poimboeuf
2021-01-22  5:17   ` Jürgen Groß
2021-01-21 21:29 ` [PATCH v2 15/20] x86/ftrace: Support objtool vmlinux.o validation in ftrace_64.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 16/20] x86/acpi: Annotate indirect branch as safe Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 17/20] x86/acpi: Support objtool validation in wakeup_64.S Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 18/20] x86/power: Annotate indirect branches as safe Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 19/20] x86/power: Move restore_registers() to top of the file Josh Poimboeuf
2021-01-21 21:29 ` [PATCH v2 20/20] x86/power: Support objtool validation in hibernate_asm_64.S Josh Poimboeuf
2021-01-21 22:38 ` [PATCH v2 00/20] objtool: vmlinux.o and CLANG LTO support Sedat Dilek
2021-01-22 15:41   ` Josh Poimboeuf
2021-01-22 21:17     ` Sami Tolvanen
2021-01-23  1:32       ` Nick Desaulniers
2021-01-23  2:26         ` Josh Poimboeuf
2021-01-23  2:31           ` Sedat Dilek
2021-01-23  2:46             ` Josh Poimboeuf
2021-01-23  2:50               ` Sedat Dilek
2021-01-25 22:43           ` Sami Tolvanen

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=0e9ab6f3628cc7bf3bde7aa6762d54d7df19ad78.1611263461.git.jpoimboe@redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=samitolvanen@google.com \
    --cc=sedat.dilek@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.