From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226zLlZGYFsm+bu8L4xNLSxb7onW11s4lG1XYhj7xtgV5QU7CdRuWmXSKnKg1bkc3525IZ3V ARC-Seal: i=1; a=rsa-sha256; t=1517302424; cv=none; d=google.com; s=arc-20160816; b=nIyqfJp5QlAnpG8WCIhLehC04q4uGEF65oSP2WOdezCls4rQLAclmZaba+5LHjPxSr RusJnGH31cby+iN2g6UBCPSnt6F5YyZA6XUA2kC5qRl/AfETGnkqFpFkpZoxHVciy8Xk DIzqK/k7rYcdOJcHyqlaEEV1Lok8wRm4Cpv/j5Y6ixewxNI18Gpb8d5JbGuTjKwdvuMF TL1RfWSoZynmHa9nddEIWijr0JckqQ/SvpKwZKi5K6jswtnyU8mXKW0t02NAqOoD9M4W datv75kQSN+b7ar2jVtGQ7yHKw8taeBfsv2TJGWc1LyZcVWiIEBrPGHTI6TA5aoDTt1i zSog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=precedence:content-disposition:content-transfer-encoding :mime-version:robot-unsubscribe:robot-id:git-commit-id:subject:to :references:in-reply-to:reply-to:cc:message-id:from:sender:date :arc-authentication-results; bh=Vb8TD7mGleqYxPNT6tuMPdVBumy5/+qGwn149zCelr8=; b=lwvei0C1y7ZgcahMq9bxHh5quiz0sFLdZXkIAWl5oxwIemZLR/+md8nYRKqYvKdcQK 4Yv8Ms/w9UWC18T0vlz66i1HRGIpy4NJPlda0OCQWcUmFAmUH7mdHLL1DZgZHQXrYzA/ 9c2QWpvBpFFjEe7GiEBeXUjeRSJqTShUlKT+KEq+iM1mRgSwWXiPnfB0f1CTwFuoxDcr KRQEDXzD3ptYEDZPOgIlCXD5nS3Eg+rZmk5zRAlolR2zv9K9YAKu3sJ7RVMLE6aBMTZn A6bRUdN+tApxVZAID264rP+jvDfu782orT+aUggdnFg8saEEqX0+K7/oQ/zGeatoFr3L Opsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of tipbot@zytor.com designates 65.50.211.136 as permitted sender) smtp.mailfrom=tipbot@zytor.com Authentication-Results: mx.google.com; spf=pass (google.com: domain of tipbot@zytor.com designates 65.50.211.136 as permitted sender) smtp.mailfrom=tipbot@zytor.com Date: Tue, 30 Jan 2018 00:46:19 -0800 Sender: tip tree robot From: tip-bot for Josh Poimboeuf Message-ID: Cc: mingo@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, tglx@linutronix.de, peterz@infradead.org, jpoimboe@redhat.com, luto@kernel.org, linux@roeck-us.net, jgross@suse.com, dwmw2@infradead.org, hpa@zytor.com, torvalds@linux-foundation.org Reply-To: torvalds@linux-foundation.org, hpa@zytor.com, dwmw2@infradead.org, jgross@suse.com, linux@roeck-us.net, luto@kernel.org, tglx@linutronix.de, peterz@infradead.org, jpoimboe@redhat.com, dave.hansen@linux.intel.com, bp@alien8.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, mingo@kernel.org In-Reply-To: <819e50b6d9c2e1a22e34c1a636c0b2057cc8c6e5.1517284349.git.jpoimboe@redhat.com> References: <819e50b6d9c2e1a22e34c1a636c0b2057cc8c6e5.1517284349.git.jpoimboe@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] objtool: Improve retpoline alternative handling Git-Commit-ID: 44510d9e1656fbc52721e7ceb41033359576f2a7 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1591006907461300139?= X-GMAIL-MSGID: =?utf-8?q?1591006907461300139?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: Commit-ID: 44510d9e1656fbc52721e7ceb41033359576f2a7 Gitweb: https://git.kernel.org/tip/44510d9e1656fbc52721e7ceb41033359576f2a7 Author: Josh Poimboeuf AuthorDate: Mon, 29 Jan 2018 22:00:39 -0600 Committer: Ingo Molnar CommitDate: Tue, 30 Jan 2018 07:55:04 +0100 objtool: Improve retpoline alternative handling Currently objtool requires all retpolines to be: a) patched in with alternatives; and b) annotated with ANNOTATE_NOSPEC_ALTERNATIVE. If you forget to do both of the above, objtool segfaults trying to dereference a NULL 'insn->call_dest' pointer. Avoid that situation and print a more helpful error message: quirks.o: warning: objtool: efi_delete_dummy_variable()+0x99: unsupported intra-function call quirks.o: warning: objtool: If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE. Future improvements can be made to make objtool smarter with respect to retpolines, but this is a good incremental improvement for now. Reported-and-tested-by: Guenter Roeck Signed-off-by: Josh Poimboeuf Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: H. Peter Anvin Cc: Juergen Gross Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/819e50b6d9c2e1a22e34c1a636c0b2057cc8c6e5.1517284349.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar --- tools/objtool/check.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f40d46e..bc3490d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -543,18 +543,14 @@ static int add_call_destinations(struct objtool_file *file) dest_off = insn->offset + insn->len + insn->immediate; insn->call_dest = find_symbol_by_offset(insn->sec, dest_off); - /* - * FIXME: Thanks to retpolines, it's now considered - * normal for a function to call within itself. So - * disable this warning for now. - */ -#if 0 - if (!insn->call_dest) { - WARN_FUNC("can't find call dest symbol at offset 0x%lx", - insn->sec, insn->offset, dest_off); + + if (!insn->call_dest && !insn->ignore) { + WARN_FUNC("unsupported intra-function call", + insn->sec, insn->offset); + WARN("If this is a retpoline, please patch it in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE."); return -1; } -#endif + } else if (rela->sym->type == STT_SECTION) { insn->call_dest = find_symbol_by_offset(rela->sym->sec, rela->addend+4); @@ -648,6 +644,8 @@ static int handle_group_alt(struct objtool_file *file, last_new_insn = insn; + insn->ignore = orig_insn->ignore_alts; + if (insn->type != INSN_JUMP_CONDITIONAL && insn->type != INSN_JUMP_UNCONDITIONAL) continue; @@ -729,10 +727,6 @@ static int add_special_section_alts(struct objtool_file *file) goto out; } - /* Ignore retpoline alternatives. */ - if (orig_insn->ignore_alts) - continue; - new_insn = NULL; if (!special_alt->group || special_alt->new_len) { new_insn = find_insn(file, special_alt->new_sec, @@ -1089,11 +1083,11 @@ static int decode_sections(struct objtool_file *file) if (ret) return ret; - ret = add_call_destinations(file); + ret = add_special_section_alts(file); if (ret) return ret; - ret = add_special_section_alts(file); + ret = add_call_destinations(file); if (ret) return ret; @@ -1720,10 +1714,12 @@ static int validate_branch(struct objtool_file *file, struct instruction *first, insn->visited = true; - list_for_each_entry(alt, &insn->alts, list) { - ret = validate_branch(file, alt->insn, state); - if (ret) - return 1; + if (!insn->ignore_alts) { + list_for_each_entry(alt, &insn->alts, list) { + ret = validate_branch(file, alt->insn, state); + if (ret) + return 1; + } } switch (insn->type) {