Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp207826lqn; Thu, 11 Apr 2024 20:57:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUgDgBfdMs7umplM+5XHlODT4Pln2+yoGmOxzooZh+VNHYUvchyvWpXmFFkTsmB67M6FmAPH29vdyM89p8fvm1Rkv87i5B9oWAwAvlYxw== X-Google-Smtp-Source: AGHT+IG3cJU0+CgnTWhI3pEvyvnnURv7FgGSYcwkXYi1tM3mYgHtRP4OPLhvUjEX0DwIMQQi8obk X-Received: by 2002:a05:6512:e95:b0:518:8d5b:d44b with SMTP id bi21-20020a0565120e9500b005188d5bd44bmr52257lfb.38.1712894279441; Thu, 11 Apr 2024 20:57:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712894279; cv=pass; d=google.com; s=arc-20160816; b=JwWyJ52uwUD5ORh+pQ2p2DjcnrR0h8OHY6ayM6wkoLv8wygMSCY4qVC9nHT/HeqC2H /4FTxm9U+6GDKnBOKuxOhemidHpkjLMv+rwrJGpc9UVnXvBKowrgN19nqlDxMIwTsfak CyJAWIYoggZUgqtU/fGnlUHnCSm+bNrw3Nh/ytypsiS3uh1QQicYnosRB3lPLkllGIHe /h2shANRYeuOib3rUqklRPYrSVvxxRv6QJExU7vobtRkNUrvuAnTwkgJwqm4r78AwX3d 08CD76Vlsxdztyl0DtJlT5+3gUpqt5SG4IvT/0I0rW593sFneUiYewHt8E0+HVZynVTl X4JA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LNk1J3hU+YCHAxDfZXuaBuDYbuuxkfsYwJVcFLIxPr4=; fh=jjxox2ApYGnNf9rRI6s+LRyB2MUb1hTWlSsn5K1LkXA=; b=Og+9fi9hYswRIQH6bnJqTLSy6aFdKCN9e7RqXMDm6PsvRBdLbqmo4gNa9gA5uugkUK ib56ZbcakJqVceLeE7FT7yCIzZwps0t3N9SqOJh2q30CSAdxaHICsu2hKiUIEJu7PVWO 80hk45vbhW59FvQ/qqW2EuhAy+aXfvIphnsNi4agAMfXhDjhhEbgtKlcNOqzEA15ncYp DhfTVuduLCsODmqw1lV4eCygWaw2AV/Ab8hAaviWymU1K2f6/skBbczq2vpX4NiwjNxz AOMrUXJprVmgg8KNN1j39kY7cncsfE6ooRJ9grtwC0WnrVPWkclSl6qxTEtoZr3O4Awe E1xQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gQKYw04F; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141881-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141881-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jz7-20020a170906bb0700b00a51d9c747cdsi1273434ejb.124.2024.04.11.20.57.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 20:57:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141881-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gQKYw04F; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-141881-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141881-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 243D41F23681 for ; Fri, 12 Apr 2024 03:57:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BB4218EA1; Fri, 12 Apr 2024 03:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gQKYw04F" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25D58182DF for ; Fri, 12 Apr 2024 03:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712894263; cv=none; b=jRPRlrjtDoQeUeq+zwEZD4bADOG3oLs11O/7KJ9X1asx9Bsi21ZZPlxdIyHtF7IlZvaDp2NMaTaogSqRBcckUWxKGFGzgqZPzcCjEPyKGxCx/IwYmMvtB5bvVcfGbhliXaYcKb5y9gPaaCAG99yFHhCBFeiE7Nl9GD3hiQwndbw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712894263; c=relaxed/simple; bh=HftxzaE9Ivv2zYcfAmECwLVSWn99hniqvpXpDRHcfyA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JRA0bKHr8dWG75R5rJK5aOfXAlIzcX+G1siVQ6hC4OJmptlCVVhPFVhSczbgIV2XIeCIC0LQat61EcUP+fPtD46fQxPTM0cq/hDQidr7+OA1R1VQAsvzCsqOYjWfLhy3EnZa1rO6lV904RozP4Ae4KrU7Xo9n1lvrmICGIwz7HY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gQKYw04F; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F957C2BBFC; Fri, 12 Apr 2024 03:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712894262; bh=HftxzaE9Ivv2zYcfAmECwLVSWn99hniqvpXpDRHcfyA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gQKYw04FIDJn7vaJT/4CGOiS4NFm+PjZEsSSagn+dwJktckx/sY9pK59P8XRSf2xd DLdTJslYnUwZprjZ0Q8flkUoKeuZ5TK+GuQA7uTKia056LTumKAwr1JBkM51yDPg8S Igso7FWQu3YVtI2rjFtMd/chSNO12cghWoCNYZBA7l57ji9rtuK+Imbos+0KXvWjMd Oi26COcxdVd9IxwO8tZUx7j6I1GCdc/VVHQgP0PkfFCWNACFi9OgzoFh2Ct9+D/crF 2TqK0qdbGhHRFPJXzqyet/YXtxRMfmg6TOm2Ft7/49nY71gPcZCtUgVsx3ATmbxvKp WHccfWaufeXAQ== Date: Thu, 11 Apr 2024 20:57:40 -0700 From: Josh Poimboeuf To: Pawan Gupta Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Daniel Sneddon , Thomas Gleixner , Alexandre Chartre , Konrad Rzeszutek Wilk , Peter Zijlstra , Greg Kroah-Hartman , Sean Christopherson , Andrew Cooper , Dave Hansen , Nikolay Borisov , KP Singh , Waiman Long , Borislav Petkov Subject: Re: [PATCH 5/7] x86/bugs: Only harden syscalls when needed Message-ID: <20240412035740.ojgvlqahqlm2umsx@treble> References: <97befd7c1e008797734dee05181c49056ff6de57.1712813475.git.jpoimboe@kernel.org> <20240412001522.3zp2mzked4ksglkl@desk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240412001522.3zp2mzked4ksglkl@desk> On Thu, Apr 11, 2024 at 05:15:22PM -0700, Pawan Gupta wrote: > > + * Do either a direct or an indirect call, depending on whether indirect calls > > + * are considered safe. > > + */ > > +#define __do_syscall(table, func_direct, nr, regs) \ > > +({ \ > > + unsigned long __rax, __rdi, __rsi; \ > > + \ > > + asm_inline volatile( \ > > + ALTERNATIVE("call " __stringify(func_direct) "\n\t", \ > > + ANNOTATE_RETPOLINE_SAFE \ > > + "call *%[func_ptr]\n\t", \ > > This will likely not insert the lfence before the indirect call in > spectre_v2=eibrs,lfence mode. As X86_FEATURE_INDIRECT_SAFE is not > cleared when eIBRS is enabled, this will not be converted to direct > call. Hm, I think the problem here is that SPECTRE_V2_EIBRS_LFENCE confusingly sets X86_FEATURE_RETPOLINE. So the following bit unintentionally takes effect: /* Retpoline mitigates against BHI unless the CPU has RRSBA behavior */ if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) { spec_ctrl_disable_kernel_rrsba(); if (rrsba_disabled) return; } If RRSBA gets disabled (which is likely), bhi_select_mitigation() returns early and X86_FEATURE_INDIRECT_SAFE doesn't get cleared. "LFENCE; CALL" is most definitely not a retpoline, so it's weird for SPECTRE_V2_EIBRS_LFENCE to be setting X86_FEATURE_RETPOLINE. We should fix that. Honestly, I think SPECTRE_V2_EIBRS_LFENCE is obsolete anyway. It was originally intended to be a BHI mitigation, but the real-world benchmarks I've seen are showing it to be quite a bit slower than the actual BHI mitigations. Plus it's only a partial fix because the speculative window after the branch can still be big enough to do multiple loads. For similar reasons I'm thinking we should also remove the non-eIBRS version (SPECTRE_V2_LFENCE). I'll make some patches to do that, with warnings printed if somebody tries to use them. They can just fall back to the (more secure and generally faster) defaults. > [...] > > @@ -1720,6 +1744,7 @@ static void __init spectre_v2_select_mitigation(void) > > > > case SPECTRE_V2_CMD_RETPOLINE_LFENCE: > > pr_err(SPECTRE_V2_LFENCE_MSG); > > + setup_clear_cpu_cap(X86_FEATURE_INDIRECT_SAFE); > > I don't know if it intentional, this seems to be the duplicate of > X86_FEATURE_INDIRECT_SAFE clear later in SPECTRE_V2_LFENCE mode. Also it > seems a bit odd to do this here in SPECTRE_V2_CMD handling. Yeah, I accidentally left that in from an earlier implementation. It's harmless but I'll clean that up too with a new patch unless Ingo wants to remove that line. -- Josh