Received: by 10.223.176.5 with SMTP id f5csp2828358wra; Mon, 5 Feb 2018 10:31:40 -0800 (PST) X-Google-Smtp-Source: AH8x225B34qBp7LyOMRIixUbjEY3tColaafqlw06DrkWXM226C+KgPFzO64vdYbR5PRWrX7nGIAJ X-Received: by 2002:a17:902:7682:: with SMTP id m2-v6mr23804923pll.163.1517855500138; Mon, 05 Feb 2018 10:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517855500; cv=none; d=google.com; s=arc-20160816; b=xQIZ0iNuxApI9MlZ7qc3bZsW+q5DSo8TeaoP9Uy3rtJoJ6HzydvE0hH3PQhtm3vDYp fHxn/ZfPhkPg13CGDlJ08mZTvB8MEov8pEt4QjUyD7SO2a6nvATbGsxYBHJvawZnyXWD oSQURzMGIpCD+Vgn49zt+G7ckrJZqWB/nEWvzHzQo8MPN2D/Q/CsJsqOIRIY/ZmgFmwP 1H16hrP0wqsHtiI4GWzSej/VlHa/x1TZfUPJDcvbgcUYNRqsliSwG+XGziZZR0xVK6aF 641w3cJ4LBWM4HogkrlZ18fYRi2MJip9JUX1w9BE6BjyaQo2p4ppP7H5RniAkt+sC2Ra I/ig== 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=YlgFhsI5NkVSQuaa6OkP5+1qOR7hn75yGgQpoyaX7Fo=; b=XokgKha+aIn/l3ljpZqUAGZvMMY3bKrKzxtyKtwnXx+yvbNDFGaFeomKzz4KDnrheR AVu/U+4yGqA94srxufSUcrq5rDio+Zdu6+T3YkhlTzryA/JzzdFw0aDt/eBhamSujrOj K75NP+D/klqu7bLdR4ZuZs6nRNXnDMhJaNWZ4MUdXoms5yHrFaHIFC15F904k+He+cEe y/dw6d3IQW0emdqmjIKNu0GQchZ19mvoU/c7IbcvaKpqfc9Ejy4+IAJeN6wlnKexSwmm NaFZ8bYl8ERf240C/G7HVUVZ+hBQdDxQBDKsOlJWjD6EmvS8nQ/0HXGtwVbfVm22bFBn 9PSQ== 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 1-v6si7243220plv.283.2018.02.05.10.31.24; Mon, 05 Feb 2018 10:31:40 -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 S1754031AbeBES3W (ORCPT + 99 others); Mon, 5 Feb 2018 13:29:22 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52398 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753709AbeBESZN (ORCPT ); Mon, 5 Feb 2018 13:25:13 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 714241121; Mon, 5 Feb 2018 18:25:02 +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.15 24/60] objtool: Improve retpoline alternative handling Date: Mon, 5 Feb 2018 10:22:57 -0800 Message-Id: <20180205182214.927673937@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182213.902626065@linuxfoundation.org> References: <20180205182213.902626065@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.15-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) {