Received: by 10.223.176.5 with SMTP id f5csp2862373wra; Mon, 5 Feb 2018 11:08:18 -0800 (PST) X-Google-Smtp-Source: AH8x2277qQ1jI9L+AbBOfUEJU/PiJ3/8iCxDPjYpzjD86Vgy7ml9DeRVnM3CeZ5BBVDQKbNZyBqT X-Received: by 10.98.252.141 with SMTP id e135mr8809663pfh.159.1517857698671; Mon, 05 Feb 2018 11:08:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517857698; cv=none; d=google.com; s=arc-20160816; b=pgo1xlgU35SOwj4SUuwW3qRkKxGzx7cwrO5ytkQa2Fn8EZ2WSimQpcj/99OuHVcGJZ Z8kIRqXhXmHNh0BaZxD0ZV/qAp2ovowNQvAORmLL7JjBlE+TGXrKDvKcYCu1heS9ia5s lxbOu2rVyh4AVXK2NTGvbLTc+FgHzb3ITj6KZ+xM/AzAOJfdGouoidTFB7M14WIYv0oA 5uFZaYfoJuItgXgFN27mL/AMEOtr/3hvw22x66pknJRfLhAtHXv2rFlyX9xVRR9wa3Ln 8uwylZYIt2arRdXghEKskm0njssl8LMZ5+6K3A8VuwJY05Pw5EFuNLyn7nxDhxVuKCUb yXFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=/EdHxLbPbQL/+txObrsV/y6Hl6g2/ENIBEhid+ff4KI=; b=v5d8/OFkuf3r97mwZ2KZBNzhqfk+owXf/FAbjBArx/kwzv5c7XC1x22PSGqJmEMEjd MJBxEEFbFPkXa7mD/gOUK94gBMCFFqpbESB10uLAwdh2Rfe9WoXc3pSIXiZONTNElMmo voSZotVCB1m+InUpUByvo06/dTIKGUjfpjJ37bDS698ZwnCPh6RDVucDnMeUa6dsMOfd 3ToT8WpXVTf08aHVUmtgnQhtCiPStTxrAF90JKEU/7QniModU2uYK5SzwyxyFFhWC8EO ox+AZL5DQaY9oSjvpVsTwHh/Mw8j3Wuav6OdiL2/pmWgyAia1Tgn264lAY2nf1soPQ52 D+Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si2292146pgw.132.2018.02.05.11.08.03; Mon, 05 Feb 2018 11:08:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753793AbeBETGS (ORCPT + 99 others); Mon, 5 Feb 2018 14:06:18 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50974 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753320AbeBESXs (ORCPT ); Mon, 5 Feb 2018 13:23:48 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 467D3FA2; Mon, 5 Feb 2018 18:23:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josh Poimboeuf , Andy Lutomirski , Borislav Petkov , Dave Hansen , David Woodhouse , "H. Peter Anvin" , Juergen Gross , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.14 28/64] objtool: Improve retpoline alternative handling Date: Mon, 5 Feb 2018 10:22:47 -0800 Message-Id: <20180205182139.722565597@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182138.571333346@linuxfoundation.org> References: <20180205182138.571333346@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josh Poimboeuf jpoimboe@redhat.com commit a845c7cf4b4cb5e9e3b2823867892b27646f3a98 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 Signed-off-by: Greg Kroah-Hartman --- tools/objtool/check.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -543,18 +543,14 @@ static int add_call_destinations(struct 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 objto 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(stru 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 objtoo 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 objtoo 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) {