Received: by 10.223.176.5 with SMTP id f5csp2832965wra; Mon, 5 Feb 2018 10:36:27 -0800 (PST) X-Google-Smtp-Source: AH8x226XGlbCE0dcgbl5Ct2t53NLEQCrA2u14bVFBECUG58dfGUeIXd9YzJhnhwnrMkx0PikcyiK X-Received: by 2002:a17:902:7290:: with SMTP id d16-v6mr14630516pll.303.1517855787327; Mon, 05 Feb 2018 10:36:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517855787; cv=none; d=google.com; s=arc-20160816; b=nQq9yocFMLgo6E33A+RCX+RZhf4+R9NC2JumH6P5DoHq0l1n7IMnGJC+MbibjMV8qu cLQdNl9L17tTxIuK4JWus3Elr2PIjZEaKROIeVTpoJNpiXP/Hn+RQ0Lgv0/fh+LtYshb 1lSNbbDWc3Lxy6mWNtwKhg1aIP2d9dqoIRpiH+LHIPt/QCvf7ayfcF7+lBUTWR1xwFxb CwSuqnheKZjg/V80KOCG52alhbbiatsm0dehb/yY3nlA4A4ij/cIrJ7VESfvAQ63QLA1 dA3RTLGHgA4ODoO5oqJ9u0KS3bLe7+euB0HGgkN3p7HZcrpooKNHkF4XsSZh1GAHZNj3 fy8g== 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=nMRA/GgkDZztbw6u5v7Cz/6+f/3N0qFadu618zEra0g=; b=kVb5bJnFyJCyl1G/vrD8vnTwetxsNYHKVXU+osUFstWyuNSBiy2pfC8CZrzmhW6Xws 8oK+e4EtwDg4jeyphBM6QDcw/0Ze2p1bvE5zMmG29wk33+UBieWr1YqbaFhxpcnrVUD5 nx6E8s27sZo0In/3SFbvoyx/XmQxSXMiGDzSbUhAO6IhtntK/BOUgijEnzYTnh53ZEN/ MvsP0I/dm7nozuJAqieDmkKBysGO36NIpw6l9XQCIW2gNzENioUesOKklwr5xC2P7x+L gEDveYgd6xfWaPEq/dyAXkQNgrYklVbgMtMPmFw2xhbT9V305qxBZxWeS5hgSDgywg6F YFCw== 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 a9si5759952pgf.39.2018.02.05.10.36.12; Mon, 05 Feb 2018 10:36:27 -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 S1753887AbeBES3a (ORCPT + 99 others); Mon, 5 Feb 2018 13:29:30 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52438 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753452AbeBESZO (ORCPT ); Mon, 5 Feb 2018 13:25:14 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 897331125; Mon, 5 Feb 2018 18:25:03 +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 , Guenter Roeck , "H. Peter Anvin" , Juergen Gross , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.15 25/60] objtool: Add support for alternatives at the end of a section Date: Mon, 5 Feb 2018 10:22:58 -0800 Message-Id: <20180205182214.970097989@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 17bc33914bcc98ba3c6b426fd1c49587a25c0597 Now that the previous patch gave objtool the ability to read retpoline alternatives, it shows a new warning: arch/x86/entry/entry_64.o: warning: objtool: .entry_trampoline: don't know how to handle alternatives at end of section This is due to the JMP_NOSPEC in entry_SYSCALL_64_trampoline(). Previously, objtool ignored this situation because it wasn't needed, and it would have required a bit of extra code. Now that this case exists, add proper support for it. Signed-off-by: Josh Poimboeuf Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Guenter Roeck Cc: H. Peter Anvin Cc: Juergen Gross Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/2a30a3c2158af47d891a76e69bb1ef347e0443fd.1517284349.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- tools/objtool/check.c | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -594,7 +594,7 @@ static int handle_group_alt(struct objto struct instruction *orig_insn, struct instruction **new_insn) { - struct instruction *last_orig_insn, *last_new_insn, *insn, *fake_jump; + struct instruction *last_orig_insn, *last_new_insn, *insn, *fake_jump = NULL; unsigned long dest_off; last_orig_insn = NULL; @@ -610,28 +610,30 @@ static int handle_group_alt(struct objto last_orig_insn = insn; } - if (!next_insn_same_sec(file, last_orig_insn)) { - WARN("%s: don't know how to handle alternatives at end of section", - special_alt->orig_sec->name); - return -1; - } - - fake_jump = malloc(sizeof(*fake_jump)); - if (!fake_jump) { - WARN("malloc failed"); - return -1; + if (next_insn_same_sec(file, last_orig_insn)) { + fake_jump = malloc(sizeof(*fake_jump)); + if (!fake_jump) { + WARN("malloc failed"); + return -1; + } + memset(fake_jump, 0, sizeof(*fake_jump)); + INIT_LIST_HEAD(&fake_jump->alts); + clear_insn_state(&fake_jump->state); + + fake_jump->sec = special_alt->new_sec; + fake_jump->offset = -1; + fake_jump->type = INSN_JUMP_UNCONDITIONAL; + fake_jump->jump_dest = list_next_entry(last_orig_insn, list); + fake_jump->ignore = true; } - memset(fake_jump, 0, sizeof(*fake_jump)); - INIT_LIST_HEAD(&fake_jump->alts); - clear_insn_state(&fake_jump->state); - - fake_jump->sec = special_alt->new_sec; - fake_jump->offset = -1; - fake_jump->type = INSN_JUMP_UNCONDITIONAL; - fake_jump->jump_dest = list_next_entry(last_orig_insn, list); - fake_jump->ignore = true; if (!special_alt->new_len) { + if (!fake_jump) { + WARN("%s: empty alternative at end of section", + special_alt->orig_sec->name); + return -1; + } + *new_insn = fake_jump; return 0; } @@ -654,8 +656,14 @@ static int handle_group_alt(struct objto continue; dest_off = insn->offset + insn->len + insn->immediate; - if (dest_off == special_alt->new_off + special_alt->new_len) + if (dest_off == special_alt->new_off + special_alt->new_len) { + if (!fake_jump) { + WARN("%s: alternative jump to end of section", + special_alt->orig_sec->name); + return -1; + } insn->jump_dest = fake_jump; + } if (!insn->jump_dest) { WARN_FUNC("can't find alternative jump destination", @@ -670,7 +678,8 @@ static int handle_group_alt(struct objto return -1; } - list_add(&fake_jump->list, &last_new_insn->list); + if (fake_jump) + list_add(&fake_jump->list, &last_new_insn->list); return 0; }