Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6267896rwb; Tue, 9 Aug 2022 12:05:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR59xOAxoXcFenOchV5qak62Y1vesj9Jhwfh97JWafWsg8Kwo66cdvi9WfobAeX5FqpVUr+O X-Received: by 2002:a63:124b:0:b0:41b:f0b2:b787 with SMTP id 11-20020a63124b000000b0041bf0b2b787mr20676932pgs.617.1660071923902; Tue, 09 Aug 2022 12:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071923; cv=none; d=google.com; s=arc-20160816; b=XcWNwxuG4sob8gHSe7RXOxVq4eZwDmZDJx3eHwOsPhfTUWGGwQQDxGhWJqTdmrjlDU k8I4r9xR1dBpo85iP1AnJeCObdOU+tgWaW2Qhxr2VAOdu5p8L3BqM6wAcCwOOXjRjUUP 2OwcmmzrcrohOeJW6OGS33iBBUywJhrhxamKHn4CmZLqSDiRu9GzS0ynfHNduMXVrHjZ YJGUcWo5BPmVSapoSv/SKjPwQLYEkS/wwDsYfmopkl9rYYJH3gGbiZ+sQHW4irOpJGfH dCl+4DxfFFpjFsGUDv/vXvI10J2DTWITJQlF4uZaUrOrySaJjMPlGOLXdNtGhGbHuZ6x e+1A== 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=8cjVWftvZi7KJOmj1q5+EesGrFBAaiFBqtD/V2dxLLw=; b=rSMBnrjADQmI7p36HDM4wzj6jP3JOmSMVvhaOZSU/SYPFVuUmkNsOZl5RMc8vcWhi2 jc5E6K589lFDKAAzOC7POhE55lJw+UUyNSr213+Sd2QMZsPijDqNh25GZAetuqbjpGmw NxtHL5ghafP5vzo0v6TTadqzIlf2MVFDolqH43+iIxa/341Rj8HNfoXdbuJdua+VMlQD H+zFt59fc01Mr6HWvev7+vbTnaQVTRqGHHigLZ63u8hp/F6Ob5Vu+ZFf3SaLrUtkhrL0 cvCRTgaDL7Z3JGgCxli59ct5iJKZw+tdnvo2QKpKv/igtm4Ch1aeG5/8u1oxKisw8aWX 5Oww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dUiS6DWR; 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 n12-20020a170902f60c00b0016d8a0c399dsi15062950plg.158.2022.08.09.12.05.10; Tue, 09 Aug 2022 12:05:23 -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=dUiS6DWR; 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 S1345126AbiHISJT (ORCPT + 99 others); Tue, 9 Aug 2022 14:09:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345069AbiHISIn (ORCPT ); Tue, 9 Aug 2022 14:08:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE4792613C; Tue, 9 Aug 2022 11:03:37 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7DBA761118; Tue, 9 Aug 2022 18:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E767AC43470; Tue, 9 Aug 2022 18:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068217; bh=HZjsLh9G/XseI4c+wAmiE/T9/sW2B0EUIKAtM7s2Wyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dUiS6DWR8seUhj39Yb3c6FfiGqNBfv4Q96eJMuEoR5mTM6bPhhavNTdNd1Pmy4hCn QldTQ3lE9MYerpZFQNG2ASTHLF2T6W8Cg7aWRs9bgyCR7C4DaOo7wq8cp1zfH/BIbn YFLHsokwItyDqQJrIZlX1qzimqBtAIxY0LSWFRu8= 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 5.4 15/15] x86/speculation: Add LFENCE to RSB fill sequence Date: Tue, 9 Aug 2022 20:00:33 +0200 Message-Id: <20220809175510.849644425@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175510.312431319@linuxfoundation.org> References: <20220809175510.312431319@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 @@ -61,7 +61,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; #define __ISSUE_UNBALANCED_RET_GUARD(sp) \ call 881f; \