From patchwork Thu Oct 12 06:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 151775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1020925vqb; Wed, 11 Oct 2023 23:26:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENEDNLnwpYdgAu9NhH0ZJ+eKdLKSzYAstpqTkyS9WSCe9VGNvLj6LjEcpMgxEvgDHxiCaY X-Received: by 2002:a05:6359:b9a:b0:147:eb87:3665 with SMTP id gf26-20020a0563590b9a00b00147eb873665mr18940111rwb.3.1697092003832; Wed, 11 Oct 2023 23:26:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697092003; cv=none; d=google.com; s=arc-20160816; b=aUtH+8OMs+mrW4PWe41DkMuKamLtU1bsm9ydYhk0wlaqKIyrYX2Ym49PP6tY6tCtxt 0HQpmI9/43Xi8PxT0HunBxzaLwH6nCjYGrt8U6/nth+sWj/YIKescuQjXtgLbZ1A8k8r Rc+qIT9IAtT+MoKyqhrMey5cRJxZTdZmqa9eahzIWH5DwzPZa7O+goQh8g08zR+5rBfI WYm8eJjjDT4Ea5xfHT8uB7ynyR/lolhOvAafIfdLG7XVoNGZhQ4eRoxZSkCob4xNJZzF 1t/EPQ636KL++ldTa7ZTgYJnRGE16FhNViVh/xFvSGfLLCBUdBT+swViwCdRhL1yYAhA RI+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=+1KP8+oYpEZJePS2HiaWvpVh2+B/XGV8vKsjA2aqHYE=; fh=RQiYPerYjSd+EqvorYaHWLqVX+te/5sQqM1E+CqvIVY=; b=GEqsoHI6zBEg5LyDVCZiqRrSQcEDi3c7EUwhrfHJHbfXIJfy7J2nma8fWdBryMA5KG tK6svDM9LQJvf90aOnlhBOh5ozZ9g9HbXZUUmUzxe87cVuD+9dL/qU2i6/7prXpHffMe S+XK0nfQeY9+nzNiohpRJV8XUbXvko3PfoT2/ScbmhmSKTMKHe6R3pjMcQLL6E0nD0zB L0QMDZcQzb9MhkISanSC5zF12H/xgk2xrMCWFcJjf+5W89Pq1cbIJWKUoYi/D4mcLS5S 2P8PfHaTbYpzruWx2/IAfhu0MKnK8Z78cVWefcKbdNHo8kTtjYMnHYT4dpHQFe+W1AuI Y3mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="j61sW8/s"; dkim=neutral (no key) header.i=@linutronix.de header.b=Rxu0bIRJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y18-20020a056a001c9200b0067ff1a1ccbcsi13288116pfw.63.2023.10.11.23.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:26:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="j61sW8/s"; dkim=neutral (no key) header.i=@linutronix.de header.b=Rxu0bIRJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4B4A98091C6D; Wed, 11 Oct 2023 23:26:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347095AbjJLG0V (ORCPT + 19 others); Thu, 12 Oct 2023 02:26:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235354AbjJLG0H (ORCPT ); Thu, 12 Oct 2023 02:26:07 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A780EA; Wed, 11 Oct 2023 23:25:37 -0700 (PDT) Date: Thu, 12 Oct 2023 06:25:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697091935; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+1KP8+oYpEZJePS2HiaWvpVh2+B/XGV8vKsjA2aqHYE=; b=j61sW8/sUZXIQ/adfLuYN7iklzU0Jh046d4LL2MpfYwz2PoIXQ1f481mkuXoaZB5yHuSRh P1oTRAnynw0luB9D+KJvMc4jOE3Qy6j1etDxw+gDbh/ys3+jOvTv5tWtH3oK8GLC1O1vxv 0hCH4xUN75TbUR4KhfA5+4cZp3RObS02Ola7dPzOYILS9vwnznf+PK8Cpr/ZVXQpvvSDdX 2vWLwIJ8Y95gS5V9OGmK1XvVyWhcWp6U0Eht9usxSuW8kxuYnypOgA7ikLtaVDF4y8pSsB fFayguNBq9Hq2JbTst5jMrc8IZYDS35n+N9MNf5OgdRJOrGcYuYmjhcbNxiMxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697091935; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+1KP8+oYpEZJePS2HiaWvpVh2+B/XGV8vKsjA2aqHYE=; b=Rxu0bIRJMXUeTT0PCRdIyO5IngsCO67b/txdSinbxfO1AV5nS3hyzc4Pr5A711TKVFhDoG JotGywgiy2Sh19DA== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/bugs] objtool: Fix return thunk patching in retpolines Cc: David Kaplan , Josh Poimboeuf , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231012024737.eg5phclogp67ik6x@treble> References: <20231012024737.eg5phclogp67ik6x@treble> MIME-Version: 1.0 Message-ID: <169709193522.3135.3437936240922691575.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 23:26:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779516178032927751 X-GMAIL-MSGID: 1779529944833494949 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: 3ab1bb69862d4477e2ffa556075a251bd7328910 Gitweb: https://git.kernel.org/tip/3ab1bb69862d4477e2ffa556075a251bd7328910 Author: Josh Poimboeuf AuthorDate: Wed, 11 Oct 2023 19:47:37 -07:00 Committer: Ingo Molnar CommitterDate: Thu, 12 Oct 2023 08:21:29 +02:00 objtool: Fix return thunk patching in retpolines With CONFIG_RETHUNK enabled, the compiler replaces every RET with a tail call to a return thunk ('JMP __x86_return_thunk'). Objtool annotates all such return sites so they can be patched during boot by apply_returns(). The implementation of __x86_return_thunk() is just a bare RET. It's only meant to be used temporarily until apply_returns() patches all return sites with either a JMP to another return thunk or an actual RET. The following commit: e92626af3234 ("x86/retpoline: Remove .text..__x86.return_thunk section") broke objtool's detection of return sites in retpolines. Since retpolines and return thunks are now in the same section, the compiler no longer uses relocations for the intra-section jumps between the retpolines and the return thunk, causing objtool to overlook them. As a result, none of the retpolines' return sites get patched. Each one stays at 'JMP __x86_return_thunk', effectively a bare RET. Fix it by teaching objtool to detect when a non-relocated jump target is a return thunk (or retpoline). Fixes: e92626af3234 ("x86/retpoline: Remove .text..__x86.return_thunk section") Reported-by: David Kaplan Signed-off-by: Josh Poimboeuf Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20231012024737.eg5phclogp67ik6x@treble --- tools/objtool/check.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e308d1b..e94756e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1611,6 +1611,22 @@ static int add_jump_destinations(struct objtool_file *file) } /* + * An intra-TU jump in retpoline.o might not have a relocation + * for its jump dest, in which case the above + * add_{retpoline,return}_call() didn't happen. + */ + if (jump_dest->sym && jump_dest->offset == jump_dest->sym->offset) { + if (jump_dest->sym->retpoline_thunk) { + add_retpoline_call(file, insn); + continue; + } + if (jump_dest->sym->return_thunk) { + add_return_call(file, insn, true); + continue; + } + } + + /* * Cross-function jump. */ if (insn_func(insn) && insn_func(jump_dest) &&