From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x224CfW3LvkQWL3I0RoyVldTKBDSs0aLMWQBHSKkBmCMHa1yvLgj6OkNvJCNUXiM5qAH88qs8 ARC-Seal: i=1; a=rsa-sha256; t=1517321855; cv=none; d=google.com; s=arc-20160816; b=rW0AsF2CfBIU6nb/9rpv/64zzI25GqTL0D2b5YLCX/I7DWQUtb58Uk52W4zcJTMMDe w6lnGPL/wi6gQD4NmDHKsmveo2nqBLCOQ1eVQdjsndTPqBRo4eCcczkk7SCyovgxFLW+ u1XGaoI7U+6ppsxoHXg3hobfK0vSt3qP58Sq49AljoL1P0V5pv/sIU5ZCkWN35bbAPBF BOjEndOwZUQcNPrrt/88axCx/kDRpqy2mU1PaxeO/+XEGTL7N00VdSd5NF8/rom/IvW1 n2j7Q550xnTlwDyZga+amSS9jd/BOAgaub31BVugClUpobodXD05PCoNPBuxoAKPKwqU HIuA== 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=X2APuLNWyJ2ycy9abmAMLhphaurH5uIRwrsuk5fFBSU=; b=Uw0W0Zcm4YT1SliJWZaQQnkIBUSRNIMlfWbMz0gYIyYqFrvtki1E/BX/WOAMaiHyjz mzw7hFeIhZJbIitL4/TXsr6l4pMDRXY3jMH6kEQRH0FsfIjm5vUrt25c78C0AlKsY6VG KXHELTdy++KaVn9tVLqQpTsDORgvqABCKjROQ8H7C0400A1OuHOlB4VvkDCdD4suXXJC 8gsg2u4N07uow1u/d/bJbSzHwcZCiiT5T5qRXN+n6UIPLHv2u6vii+jgFy1oaMMVYfgn Vr27nFF2FjtRRyQmMUjIYec6OEDOzKgsCF4O8o28sCzmLHVr9XQan5ZwvqYXqQ24xzY6 L6bg== 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 06:12:50 -0800 Sender: tip tree robot From: tip-bot for Josh Poimboeuf Message-ID: Cc: peterz@infradead.org, gregkh@linuxfoundation.org, linux@roeck-us.net, torvalds@linux-foundation.org, jpoimboe@redhat.com, linux-kernel@vger.kernel.org, luto@kernel.org, jgross@suse.com, tglx@linutronix.de, hpa@zytor.com, dwmw2@infradead.org, bp@alien8.de, mingo@kernel.org, dave.hansen@linux.intel.com Reply-To: dave.hansen@linux.intel.com, bp@alien8.de, mingo@kernel.org, hpa@zytor.com, dwmw2@infradead.org, tglx@linutronix.de, jgross@suse.com, luto@kernel.org, linux-kernel@vger.kernel.org, jpoimboe@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, linux@roeck-us.net, peterz@infradead.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: a845c7cf4b4cb5e9e3b2823867892b27646f3a98 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?1591027281431099022?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: Commit-ID: a845c7cf4b4cb5e9e3b2823867892b27646f3a98 Gitweb: https://git.kernel.org/tip/a845c7cf4b4cb5e9e3b2823867892b27646f3a98 Author: Josh Poimboeuf AuthorDate: Mon, 29 Jan 2018 22:00:39 -0600 Committer: Ingo Molnar CommitDate: Tue, 30 Jan 2018 15:09:14 +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) {