Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6266787rwb; Tue, 9 Aug 2022 12:04:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Tnyb54Fj+pEwcHSZ8TPZAWCVCY7/zTY2X/GtspPqNE9Pq4tCTfYEFc9CBDECZFpUSgjxn X-Received: by 2002:aa7:8e91:0:b0:52d:8ebf:29a4 with SMTP id a17-20020aa78e91000000b0052d8ebf29a4mr24484501pfr.1.1660071867330; Tue, 09 Aug 2022 12:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071867; cv=none; d=google.com; s=arc-20160816; b=oINd7b3YM2lm/kbM5t+EF6Qkzr3s+aT1pbWPGsIesfVkX2NvPfi9rxB4p0m7scBPfu JnI+g+I6Bvm13pmopWazY0BfFkaorbOJRTHjT/8BvrlQ/G5sFb8k3o21ueXrogGPawxJ 1Jd3r7M5WtTnEfWLB9xw6hjxPauNwwFnzwUAR8Ec3Mf7oIsWyssWtke0lqjySGw18bcX 7L1R98Mj8RMQ7e64kP8EqyQHBlTZLwMp52jCdBwBGe7r7yUhO8hhYj6/5zInP+8XlgQ4 u6ibyhnfkOl8FFVvUaTRbj4wZRCsbu/AgPnmTA50wDhO5bnP6iAH+jMY6eo0A9ry8piX MNhQ== 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=yGR53XREPCrepoIAB8fx10tJSXdvH+JF9J7vQba87jE=; b=1HDkEBuYCKo88+DhQLajoMtkVD0kJYf7I829tJn4XErT1hnou7rNF5DRkjywUO2gro nsQuKbrB+nzILA77JwMVctFjBniE/3mCySUOp3uI1B1e/0QP56LQLbIdmthyM1TO75JB nOALuHZ6Cc1bKw+dK2D7kq+lp7AkjqFvYjTGPz/uG1/kWa4UPm7nyHNX2okshgbarn2Y 1Iciy5g9ttBJYZdMyDtUndI8SW8BFxybLV0r78qiIGEPJi++8spwHE/pVmO4TD/a44Fm JRGvpIMuPXY/D2nCbTOH0N8iQDl/i2od7RJsoe8mmmac54LuoMmx69/kF+RZlYHVd/Wu 8BGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="bd2P/pI7"; 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 s13-20020a170902ea0d00b0016ec623eac3si16801036plg.239.2022.08.09.12.04.12; Tue, 09 Aug 2022 12:04:27 -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="bd2P/pI7"; 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 S1343579AbiHISHM (ORCPT + 99 others); Tue, 9 Aug 2022 14:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344757AbiHISGh (ORCPT ); Tue, 9 Aug 2022 14:06:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71AFB20192; Tue, 9 Aug 2022 11:02:55 -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 03BDBB8171A; Tue, 9 Aug 2022 18:02:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67F98C43470; Tue, 9 Aug 2022 18:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068172; bh=GKZ5PKCQqTqdXrWsuss0Jv7382G5VfbXuBTColpUSUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bd2P/pI7IbN64JhdOaUW7w7+6K+L6BOV4AqHZbb1WqD/Kd5q9A3VVIZKRZEDEYpSe dFnDkGphnhi5Z3iTAYEFBPIjDXWs6lcj93qkwi6+UzOE5t1g+bwk/uarWx3mxMUJUy MgZe+B3SD1vf40YFcMVzuqvUAgHbiqeLGyG+LBoc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Cooper , Pawan Gupta , Borislav Petkov Subject: [PATCH 4.19 32/32] x86/speculation: Add LFENCE to RSB fill sequence Date: Tue, 9 Aug 2022 20:00:23 +0200 Message-Id: <20220809175514.089995381@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175513.082573955@linuxfoundation.org> References: <20220809175513.082573955@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.7 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,T_SCC_BODY_TEXT_LINE 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: Pawan Gupta commit ba6e31af2be96c4d0536f2152ed6f7b6c11bca47 upstream. RSB fill sequence does not have any protection for miss-prediction of conditional branch at the end of the sequence. CPU can speculatively execute code immediately after the sequence, while RSB filling hasn't completed yet. #define __FILL_RETURN_BUFFER(reg, nr, sp) \ mov $(nr/2), reg; \ 771: \ call 772f; \ 773: /* speculation trap */ \ pause; \ lfence; \ jmp 773b; \ 772: \ call 774f; \ 775: /* speculation trap */ \ pause; \ lfence; \ jmp 775b; \ 774: \ dec reg; \ jnz 771b; <----- CPU can miss-predict here. \ add $(BITS_PER_LONG/8) * nr, sp; Before RSB is filled, RETs that come in program order after this macro can be executed speculatively, making them vulnerable to RSB-based attacks. Mitigate it by adding an LFENCE after the conditional branch to prevent speculation while RSB is being filled. Suggested-by: Andrew Cooper Signed-off-by: Pawan Gupta Signed-off-by: Borislav Petkov Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -52,7 +52,9 @@ 774: \ dec reg; \ jnz 771b; \ - add $(BITS_PER_LONG/8) * nr, sp; + add $(BITS_PER_LONG/8) * nr, sp; \ + /* barrier for jnz misprediction */ \ + lfence; /* Sequence to mitigate PBRSB on eIBRS CPUs */ #define __ISSUE_UNBALANCED_RET_GUARD(sp) \