Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp873631pxb; Wed, 3 Mar 2021 19:15:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyg4thOwSizsrQT1ok1yNwVh69yvXHym4rfJVwnwJykrU1pHNFOE/4dzElOFUdx4QEbAXXX X-Received: by 2002:a05:6402:26ce:: with SMTP id x14mr2075162edd.359.1614827707242; Wed, 03 Mar 2021 19:15:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614827707; cv=none; d=google.com; s=arc-20160816; b=oyZdBy77xxcb0UrOHtZtupzjtFnj9nsz6VGaDvDFJMpbHXePRrzA/n1w3cH5fBixRt /OqmUEzIwNQLtlhIw8vd1H9UkLfzk/CjEjGxLxikaPkH/vIm7KKCVMiuuByQlF9JksGT Nv2xPoIPO0SX6qDhR6V51w5uqkAsWLZBNkqnhnQqp7QCV6Tv53ocKgy4Zn2f+dB7a7Mm RAmkm6+l+WCDwmTdcLDd2THETTxiOWB+G9ruPhyGa8kNpWi2ikErxdxZTYRB3v/GDZqS jDn4XCZNcNLDRiFTmU6mJvXC08QjWcfhbuCITpofA2HTpyyuvu7FJ7wIi+aCQBslR5Yu 3dVg== 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=VSF1a5PZnJuZ+6rZoKiykm01lLUAwlOoKveopm61jWM=; b=kDadrKK3cA5OImhsImKY6TTyldqlfD2hIg90b/F9e6hvyNjXwbsmxDiHkoL1smK4/0 bsczLc3WWjzht6Q/viyqr9zigu6YNXKNX/WdrpsWffuknHozL6i3LScC9lOytTkg/Rx0 98dloxQI+RaO9m4OeYdZt2vMuwzIikAtIKKe4Pwd50si7ksTR6Q77gCYwHO8hgn8m4Kj 50sMTgzrRF4yjT3fLFE/JiNKb0j8FSUHV6VYuAOHFgIhrf9VosScGBa50DuFVDMlzSFR xUCiLpZeulZPPEgdgOtQG9H90FmgCnWKCF5+fQpQohGDuzzvbZ6Ui9L21q2r3t1bDtWN 2Zsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cj42+949; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f7si16649052edd.179.2021.03.03.19.14.43; Wed, 03 Mar 2021 19:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cj42+949; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1379164AbhCBB0m (ORCPT + 99 others); Mon, 1 Mar 2021 20:26:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:39812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241133AbhCATMm (ORCPT ); Mon, 1 Mar 2021 14:12:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0CA2C651D7; Mon, 1 Mar 2021 17:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619066; bh=ojeTjuDY35/u129zo93H02dlPVWhaoTGm7cCGJ+NniU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cj42+949m6EgssOWuiodftXKGZ8g9Au3XERGzJAFGGnZIe3UP/AsH2SSOp2+uzHj8 +1CLZY5FCrvXqaXb3WOtmV2RdVh6jP58Eb5BC+3Q9JUDLS/oP44lltq7bnNPUa/w6C ZR0u+IpGzihgYQiEpxOiIjZ1kEqPn2ncDLEF7zq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josh Poimboeuf , Sasha Levin Subject: [PATCH 5.10 319/663] objtool: Fix retpoline detection in asm code Date: Mon, 1 Mar 2021 17:09:27 +0100 Message-Id: <20210301161157.636120210@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josh Poimboeuf [ Upstream commit 1f9a1b74942485a0a29e7c4a9a9f2fe8aea17766 ] The JMP_NOSPEC macro branches to __x86_retpoline_*() rather than the __x86_indirect_thunk_*() wrappers used by C code. Detect jumps to __x86_retpoline_*() as retpoline dynamic jumps. Presumably this doesn't trigger a user-visible bug. I only found it when testing vmlinux.o validation. Fixes: 39b735332cb8 ("objtool: Detect jumps to retpoline thunks") Signed-off-by: Josh Poimboeuf Link: https://lore.kernel.org/r/31f5833e2e4f01e3d755889ac77e3661e906c09f.1611263461.git.jpoimboe@redhat.com Signed-off-by: Sasha Levin --- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/check.c | 3 ++- tools/objtool/check.h | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c index fd4af88c0ea52..151b13d0a2676 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -48,7 +48,7 @@ bool arch_support_alt_relocation(struct special_alt *special_alt, * replacement group. */ return insn->offset == special_alt->new_off && - (insn->type == INSN_CALL || is_static_jump(insn)); + (insn->type == INSN_CALL || is_jump(insn)); } /* diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2e154f00ccec2..48e22e3c6f186 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -789,7 +789,8 @@ static int add_jump_destinations(struct objtool_file *file) dest_sec = reloc->sym->sec; dest_off = reloc->sym->sym.st_value + arch_dest_reloc_offset(reloc->addend); - } else if (strstr(reloc->sym->name, "_indirect_thunk_")) { + } else if (!strncmp(reloc->sym->name, "__x86_indirect_thunk_", 21) || + !strncmp(reloc->sym->name, "__x86_retpoline_", 16)) { /* * Retpoline jumps are really dynamic jumps in * disguise, so convert them accordingly. diff --git a/tools/objtool/check.h b/tools/objtool/check.h index 5ec00a4b891b6..2804848e628e3 100644 --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -54,6 +54,17 @@ static inline bool is_static_jump(struct instruction *insn) insn->type == INSN_JUMP_UNCONDITIONAL; } +static inline bool is_dynamic_jump(struct instruction *insn) +{ + return insn->type == INSN_JUMP_DYNAMIC || + insn->type == INSN_JUMP_DYNAMIC_CONDITIONAL; +} + +static inline bool is_jump(struct instruction *insn) +{ + return is_static_jump(insn) || is_dynamic_jump(insn); +} + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset); -- 2.27.0