Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1371297imi; Sat, 23 Jul 2022 03:59:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uCUbM03A+fb4q5QLuKlSqqK+5pDrf5yRd7evjwEGT99kv+uQUCmRWCpPsBJZo3f9iHqTKA X-Received: by 2002:a17:907:96a1:b0:72b:918c:13f with SMTP id hd33-20020a17090796a100b0072b918c013fmr3219577ejc.659.1658573986602; Sat, 23 Jul 2022 03:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573986; cv=none; d=google.com; s=arc-20160816; b=EE4sr1JzsdkU09dQzKU1QNeGkjUe3zs02fsU7NGnVDo62G73CuBQ5yEeV4eEubs8ZH M5icSit6uTwwQTNFX05rsUSOgDdhql5DjfWE1D2E+AGRcjMT9O3WzxzaIFpVpUPZIKvu HlPCx/DN2sbNjU6JM/eFifnMXTB0zmNEetKAD1KHjh4HBt3DGwTgbeSeMvfD2HlYqmQm s5K+YiC7CMghECeEik5HaMWfFaLl3xSGu70vKz3nMkl+oKByTGCcX8cCqewnWER00Iv5 eBn9RE0NUTZh9Al3zgPjSR0v0PVK/xxm0YwafuGt6wr2NgymzN7cscUi5y/Rpn3Dr68X dKoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cwPe1aFL+M2gmcjSGzB2jvhZPuJwYpJOzEs8t6a++9s=; b=j/eF6d+f3a333zYXy8xHRbQN4ShTlCFr3yKHAjZvi2rTiTwXG2USi9riRT1HUe9Czx 6SwhVBa7o0XXKCHqntA0yyBE36RzzQMRlAPoh43CJN+6xNouV29+vLNUd4XwebL6XwBI +at5CuvRIO1DcgZbsaA2Adr8Sq9siEmLTjaePcc8veIF1axVh4ZGByQtGLmslU5T8NDi qdmZxzFxxSs60hob0ILUdkuyGSc935ZpcB9pHdRp0Subyb1HTsZL0+VWycq2pbqh/csk smYvIbB4NI2nOVNL6wEkGe8sXTVPTrAues61Zugg81mhE77MidNP5RFnu9KFUKIBuEhx z/wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0EqX2Ay7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn14-20020a1709070d0e00b0072b2fbd78bcsi9125317ejc.665.2022.07.23.03.59.22; Sat, 23 Jul 2022 03:59:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0EqX2Ay7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237597AbiGWKBy (ORCPT + 99 others); Sat, 23 Jul 2022 06:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237938AbiGWKAx (ORCPT ); Sat, 23 Jul 2022 06:00:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 479AB3F334; Sat, 23 Jul 2022 02:58:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C45CEB82C1A; Sat, 23 Jul 2022 09:58:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34642C341C7; Sat, 23 Jul 2022 09:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570309; bh=XZe6mZDywRYuCTJTB4/Kt7NN12giWZC5dpHCMsUZakg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0EqX2Ay7Lks1q1ATRNEyWTXw7sifxlaXRThxS1iYgoSiM2qr3jaPcPko40HloScyD JAoZJAaouiz38pu1fKR+6cvWOSauuJ7teBUFPeoEh5CioPoa3S7OHrb4d+Xr1rOcjd CZB2oXzPqx1NJIVP5fTHV76OD7eOZgn+SHBQBweE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Rothwell , Borislav Petkov , "Peter Zijlstra (Intel)" , Josh Poimboeuf , Nathan Chancellor , Ben Hutchings Subject: [PATCH 5.10 041/148] objtool: Teach get_alt_entry() about more relocation types Date: Sat, 23 Jul 2022 11:54:13 +0200 Message-Id: <20220723095235.834263566@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra commit 24ff652573754fe4c03213ebd26b17e86842feb3 upstream. Occasionally objtool encounters symbol (as opposed to section) relocations in .altinstructions. Typically they are the alternatives written by elf_add_alternative() as encountered on a noinstr validation run on vmlinux after having already ran objtool on the individual .o files. Basically this is the counterpart of commit 44f6a7c0755d ("objtool: Fix seg fault with Clang non-section symbols"), because when these new assemblers (binutils now also does this) strip the section symbols, elf_add_reloc_to_insn() is forced to emit symbol based relocations. As such, teach get_alt_entry() about different relocation types. Fixes: 9bc0bb50727c ("objtool/x86: Rewrite retpoline thunk calls") Reported-by: Stephen Rothwell Reported-by: Borislav Petkov Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Tested-by: Nathan Chancellor Link: https://lore.kernel.org/r/YVWUvknIEVNkPvnP@hirez.programming.kicks-ass.net Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- tools/objtool/special.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -55,6 +55,24 @@ void __weak arch_handle_alternative(unsi { } +static bool reloc2sec_off(struct reloc *reloc, struct section **sec, unsigned long *off) +{ + switch (reloc->sym->type) { + case STT_FUNC: + *sec = reloc->sym->sec; + *off = reloc->sym->offset + reloc->addend; + return true; + + case STT_SECTION: + *sec = reloc->sym->sec; + *off = reloc->addend; + return true; + + default: + return false; + } +} + static int get_alt_entry(struct elf *elf, struct special_entry *entry, struct section *sec, int idx, struct special_alt *alt) @@ -87,15 +105,12 @@ static int get_alt_entry(struct elf *elf WARN_FUNC("can't find orig reloc", sec, offset + entry->orig); return -1; } - if (orig_reloc->sym->type != STT_SECTION) { - WARN_FUNC("don't know how to handle non-section reloc symbol %s", + if (!reloc2sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off)) { + WARN_FUNC("don't know how to handle reloc symbol type: %s", sec, offset + entry->orig, orig_reloc->sym->name); return -1; } - alt->orig_sec = orig_reloc->sym->sec; - alt->orig_off = orig_reloc->addend; - if (!entry->group || alt->new_len) { new_reloc = find_reloc_by_dest(elf, sec, offset + entry->new); if (!new_reloc) { @@ -112,8 +127,11 @@ static int get_alt_entry(struct elf *elf if (arch_is_retpoline(new_reloc->sym)) return 1; - alt->new_sec = new_reloc->sym->sec; - alt->new_off = (unsigned int)new_reloc->addend; + if (!reloc2sec_off(new_reloc, &alt->new_sec, &alt->new_off)) { + WARN_FUNC("don't know how to handle reloc symbol type: %s", + sec, offset + entry->new, new_reloc->sym->name); + return -1; + } /* _ASM_EXTABLE_EX hack */ if (alt->new_off >= 0x7ffffff0)