From patchwork Thu Oct 12 17:50: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: 152094 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1402652vqb; Thu, 12 Oct 2023 10:51:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFF/aKhFAQl6zwb2t3Fh8nL+H6Mjtxm1ZASyPmSm/kAD8Nx0ZAhwZdFtJnkvvVbzJx8lAZi X-Received: by 2002:a05:6a20:1584:b0:15d:f804:6907 with SMTP id h4-20020a056a20158400b0015df8046907mr29283660pzj.0.1697133063477; Thu, 12 Oct 2023 10:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697133063; cv=none; d=google.com; s=arc-20160816; b=AMN05r534SB9r1d3lfKL9Wnt1FrssNK1ktSw+YXYmUFSgFd2P4ypqYELAvb6R3N3z1 z7o6uJV4SJqKxy/G5wGS3NLuRgEoIuYU1MAux/d3jF1w4gmdx0mD08gxCCUjImzr4C0S zons2gRT5NCy16afxvQg1EXIhCwvmt6M041mMxJ6gZ3WG9ElkBIaz5K1KO+UyLlSTkwz CHU83q7aB5PnpZogmca9HTmNQ8LiSldXtG+T9lC1n3oaFoYnxkfXLpXtTnQgsM77uwuF Aa5crVEhJwl25AtmF7LGq8tYKBqzz2bI8Af5nifBqecmGWf5bvqJpkM8uUZhHfVjtgiF ktSg== 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=u1tRzLxcoMbWxvG+mukyL8m7+kfZ7rIvBFU2zqRdBCY=; fh=1l2Y28xXTttMMQ47jtA1XEJ6GBwinArLYvIP1EDDJ4A=; b=f9z/3aidUFeYu1J+0sMt4krpXXNx4sGJr/sDqwDxSkdT9I0tqLViw9qhkkXm4Qxchu utvBOUnV17RZSTyHA9Ebu6epyMEyRFEYwDntklciXGRrdaITIaFbj7Z+waUtlfIBRUOn GN4tzcQF82SZU4wxfYWVuDMLGA/1AZZ0yLuOXVswemm/CdyRAhAhw1vynDAmiFfYr4TA cjtXyO51bUEVM5zcbh4HART/vSSfANgr9RGtgl6rzaBMzt/OgX+tMXFXw0XH0hV2mrZT VJiGW8802s6UEEICBSbw7pQRL0HCzlB/pur7s1ORp+O4oJfnGqItozRY0gBCvaXXW3Fo Z0Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FmPglg7N; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id u9-20020a170902bf4900b001c755810f80si2585182pls.28.2023.10.12.10.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 10:51:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FmPglg7N; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 789618040DE8; Thu, 12 Oct 2023 10:50:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379647AbjJLRum (ORCPT + 19 others); Thu, 12 Oct 2023 13:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379651AbjJLRuj (ORCPT ); Thu, 12 Oct 2023 13:50:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D504D6; Thu, 12 Oct 2023 10:50:37 -0700 (PDT) Date: Thu, 12 Oct 2023 17:50:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697133036; 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=u1tRzLxcoMbWxvG+mukyL8m7+kfZ7rIvBFU2zqRdBCY=; b=FmPglg7N3Aq85KxQQgdo5HL3aSPu7ftnaFGkOOGFO2xC602jFOlZ+PhVxCo64AgWP9rSRg eIbmngOwHh9UgO4YURmni+ZJD4yaskMTyB7NeAsWzFX41NmWMC2tvLTh+KtBnIOzQdwPwd VsDpU0QgW7R7tTThZa2KLMuIjX8SnsS7hqzFZteTcFyFugswI01WGKnJg3X4NoAAhQN/VZ /tveEwAnhjGA3jsBtfPDixagLq3x8TMOiyOJHbW6xWVBHtTI0FSXb+7qQWEGgbOgt4MDjJ S88k937aVijiM6vGrRvi2GsWiz94Sq9vxDTdJIGkiEhB8vfedrk8L9A88Lw11Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697133036; 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=u1tRzLxcoMbWxvG+mukyL8m7+kfZ7rIvBFU2zqRdBCY=; b=FhqAUCdVyd07m193GPDhmDCWLsDA7wnltmxS0XPHKrZjQaq93+DmqQfn5COEKlCZ5eajat /bOnQV6hfVO6EcDQ== From: "tip-bot2 for David Kaplan" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime Cc: David Kaplan , "Borislav Petkov (AMD)" , Ingo Molnar , Josh Poimboeuf , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231012141031.GHZSf+V1NjjUJTc9a9@fat_crate.local> References: <20231012141031.GHZSf+V1NjjUJTc9a9@fat_crate.local> MIME-Version: 1.0 Message-ID: <169713303534.3135.10558074245117750218.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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 12 Oct 2023 10:50:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779389318000603171 X-GMAIL-MSGID: 1779572998801826874 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: 91174087dcc7565d8bf0d576544e42d5b1de6f39 Gitweb: https://git.kernel.org/tip/91174087dcc7565d8bf0d576544e42d5b1de6f39 Author: David Kaplan AuthorDate: Thu, 12 Oct 2023 16:10:31 +02:00 Committer: Ingo Molnar CommitterDate: Thu, 12 Oct 2023 19:44:34 +02:00 x86/retpoline: Ensure default return thunk isn't used at runtime All CPU bugs that require a return thunk define a special return thunk to use (e.g., srso_return_thunk). The default thunk, __x86_return_thunk, should never be used after apply_returns() completes. Otherwise this could lead to potential speculation holes. Enforce this by replacing this thunk with a ud2 when alternatives are applied. Alternative instructions are applied after apply_returns(). The default thunk is only used during kernel boot, it is not used during module init since that occurs after apply_returns(). Signed-off-by: David Kaplan Signed-off-by: Borislav Petkov (AMD) Signed-off-by: Ingo Molnar Reviewed-by: Josh Poimboeuf Acked-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20231012141031.GHZSf+V1NjjUJTc9a9@fat_crate.local Reviewed-by: Nick Desaulniers Reported-by: Nathan Chancellor Acked-by: Marco Elver Tested-by: Nathan Chancellor --- arch/x86/lib/retpoline.S | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S index 6376d01..fe05c13 100644 --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -356,15 +356,17 @@ SYM_FUNC_END(call_depth_return_thunk) * This function name is magical and is used by -mfunction-return=thunk-extern * for the compiler to generate JMPs to it. * - * This code is only used during kernel boot or module init. All + * This code is only used during kernel boot. All * 'JMP __x86_return_thunk' sites are changed to something else by * apply_returns(). + * + * This thunk is turned into a ud2 to ensure it is never used at runtime. + * Alternative instructions are applied after apply_returns(). */ SYM_CODE_START(__x86_return_thunk) UNWIND_HINT_FUNC ANNOTATE_NOENDBR - ANNOTATE_UNRET_SAFE - ret + ALTERNATIVE __stringify(ANNOTATE_UNRET_SAFE;ret),"ud2", X86_FEATURE_ALWAYS int3 SYM_CODE_END(__x86_return_thunk) EXPORT_SYMBOL(__x86_return_thunk)