Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6267850rwb; Tue, 9 Aug 2022 12:05:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ddnjd8gTWFWgEQLiROrLCLQJv6itQt06C9OVxtu5GGfRgsW6aq6yaZl13w/5+huY07h1i X-Received: by 2002:a17:90a:6007:b0:1f3:3527:609e with SMTP id y7-20020a17090a600700b001f33527609emr27508012pji.52.1660071921909; Tue, 09 Aug 2022 12:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071921; cv=none; d=google.com; s=arc-20160816; b=y3v5Qd/lyvJknt3v4GA7dWp8qfcVNlFLXLoifMvvGFw+qosd8tGNn+IymIFwv8alht znWmx3oMtzjeAyNC6HZXvdJC/5qwEOaCaFQ1P52CgitxDmqnCmU+dJ+dptHZASUsG9LT yKc866U/D/NvyNo7EPNPU8Jhypah5mIU9k/ZPdssNl4vsiGlUGJAR+4KmrdMN3sTsMTe GEukh9rkWCcI4WQnSLUa6K4W52WtFNv/HKeGHdK04WPjxeFz+iDtmgN4qo8be8SOpWun I3bh+MuGDg3er9BHiw+IjgZMTZgqIbBqI33ax4yjBicTpWFfb6YlyEMJWzuZnd/BamU4 4wKA== 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=gTZOxlnQCj0p92j0QHDS9Re8KqA85znF7tvU+ybh1tk=; b=dJOqI4kRErIhr+A68eia97i+YOt1FPlLYSwyKmEgeiIEyLyIkg9gnxPXriH+R8bhwa Su/37qOUnU6wKDCq0S5dV9yLqSUPa5qY9uGz99bw1TaZyrzV67emwpFSTmBhBaF3IOrm NOjqf7WC1lj2aNgbpZYvywz2h2z9jBN3ZIEUWqE2EzUwndwIi4FfyhQyCjuu1KjUrTuQ zRmNfZWsv7W3I8I64aUg+9Cf7wgpVrn3smn8llG5NTrz+E4X2qqqzfnXoLpkQC60i+3O 4FYJW7TJHGYiMEDT69tpEoAsfzuqGkl5p8YKvHf6GtD2uspTrIRjHGtcuGTUFsOCUyxv E+4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Tip/NNZR"; 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 l70-20020a638849000000b00408a759223fsi14375089pgd.776.2022.08.09.12.05.07; Tue, 09 Aug 2022 12:05:21 -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="Tip/NNZR"; 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 S1343723AbiHISOW (ORCPT + 99 others); Tue, 9 Aug 2022 14:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345677AbiHISLc (ORCPT ); Tue, 9 Aug 2022 14:11:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BAF42AE28; Tue, 9 Aug 2022 11:04:44 -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 28A2E61070; Tue, 9 Aug 2022 18:04:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31F1EC433B5; Tue, 9 Aug 2022 18:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068283; bh=Aj/qrZaVX0QhpzS2MUF/ANJF5hHr2wjbfHO7Xx3sWUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tip/NNZRmN0V3j1+9wmdH2YmLLMppS/Jtf9/rFyZ7K0YFIXOctJa6vYH6M4hMhucs HSRhcvgNfD676AVhPYBf8u5gmFhhZXqP9FWFgP3Nej0vRM2ff/w56Lwlh2J6QtQpKJ 3OGdbpCrNUsUkJY0Gjk+V42Xa9yMrTmiXAlgKTOA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Cooper , Pawan Gupta , Borislav Petkov , Daniel Sneddon Subject: [PATCH 5.10 23/23] x86/speculation: Add LFENCE to RSB fill sequence Date: Tue, 9 Aug 2022 20:00:41 +0200 Message-Id: <20220809175513.640042532@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175512.853274191@linuxfoundation.org> References: <20220809175512.853274191@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: \ ANNOTATE_INTRA_FUNCTION_CALL; \ call 772f; \ 773: /* speculation trap */ \ UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 773b; \ 772: \ ANNOTATE_INTRA_FUNCTION_CALL; \ call 774f; \ 775: /* speculation trap */ \ UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 775b; \ 774: \ add $(BITS_PER_LONG/8) * 2, sp; \ dec reg; \ jnz 771b; <----- CPU can miss-predict here. 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: Daniel Sneddon 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 @@ -60,7 +60,9 @@ 774: \ add $(BITS_PER_LONG/8) * 2, sp; \ dec reg; \ - jnz 771b; + jnz 771b; \ + /* barrier for jnz misprediction */ \ + lfence; #ifdef __ASSEMBLY__