Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp404466pxu; Tue, 1 Dec 2020 14:24:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzcJotjCPtUX8QJVIvJRiR3rQAW2J0rcEzf2CqVwKJYVoX5qS62eiyBVdAJwO3lgmpLgX2Y X-Received: by 2002:a17:906:1b04:: with SMTP id o4mr5086653ejg.531.1606861494420; Tue, 01 Dec 2020 14:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861494; cv=none; d=google.com; s=arc-20160816; b=oFlgof6Y4smGqGapoCVSBNaEL511YYSqb6U+Eeg2H7nR9YEVqMnauTv3P1zyNthTVm LimZVrHF+W5KzICsE4FGP0J+Lk5HdsJtQSeovXXleUuHvIA5gTR+h8oND0T5Tpz+LAN0 OkyEZ10Ro5oU+ysInwphx9ko/l6LaavsUG0+8xJCQ0O8nPyY2vPlpvdYSd+vnGNDO9GJ fSG1O4j+P/YYCC3kAKSBnOZIky5oxAXThRP6HBT842SOcUOIH4gZjRQaXKS8kBcsxLYy XzDmhekW7wkbCzgtihM9IyqrkB8Ooi0ZswREQbbXWoJSAhTDv8TYo0yDBGKR7ZTI99vM 1Ogg== 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=m6TzLxkl6XbkJtAEHKQh7KCbqHUGnxAcLrototx5Fa0=; b=KCILDvAoFwza8VdhB6xSteeck3eLoEBWIxTqVqxdPlGIZtWMe/r3OBbkyH/XNzudFd w1/dVYplJ7UDRuvW1pBauyNNLd6wWLPI6UnyX95LEuFBFrXj1RTh1+bs436C9v+ZXqwA flM2iAfg/tCeN/FtJnyR0Xbn/Maila/oDOcoFg+N4wrWCpUKsv6dnYXNMVC84z4+FQYl W1R1FoAb9aQn3K5ByIU5AwGkPGZYHpIEFEpeuNspjEgQqnRPDLbd/zGXBN3RsreQPfq8 Og2Cpa5quU3q9lMtBRegWvWjjHl2pTNsFR+o7iwOmkXx4ZYlk/ctY/4g4dmQj3LIs/kY kTmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ODwS3vff; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si730872edw.358.2020.12.01.14.24.32; Tue, 01 Dec 2020 14:24:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ODwS3vff; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2389253AbgLAJIb (ORCPT + 99 others); Tue, 1 Dec 2020 04:08:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:43888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388906AbgLAJHC (ORCPT ); Tue, 1 Dec 2020 04:07:02 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF10520857; Tue, 1 Dec 2020 09:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813581; bh=Fqd08q6ULXgk8oeFymIU9Q5qSM6g/VApXQdxsacXWFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ODwS3vffIS8yZY6Fw6ZanuMcv9zM9MJAyHXu8uWDAl1AKueQRkGI/Udn9+prXSO/Z 9oO4VxG/m0KrTy93FG0PTgAogjTS5BmTWZIyHs/VmfJ7SMZXYvPaor0qw0iyb7haUg PIQni72SeKxdrNJPS2rp1ECix7joCCEACPTdWBhw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand K Mistry , Borislav Petkov Subject: [PATCH 5.4 87/98] x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb Date: Tue, 1 Dec 2020 09:54:04 +0100 Message-Id: <20201201084659.314599580@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084652.827177826@linuxfoundation.org> References: <20201201084652.827177826@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anand K Mistry commit 33fc379df76b4991e5ae312f07bcd6820811971e upstream. When spectre_v2_user={seccomp,prctl},ibpb is specified on the command line, IBPB is force-enabled and STIPB is conditionally-enabled (or not available). However, since 21998a351512 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.") the spectre_v2_user_ibpb variable is set to SPECTRE_V2_USER_{PRCTL,SECCOMP} instead of SPECTRE_V2_USER_STRICT, which is the actual behaviour. Because the issuing of IBPB relies on the switch_mm_*_ibpb static branches, the mitigations behave as expected. Since 1978b3a53a74 ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP") this discrepency caused the misreporting of IB speculation via prctl(). On CPUs with STIBP always-on and spectre_v2_user=seccomp,ibpb, prctl(PR_GET_SPECULATION_CTRL) would return PR_SPEC_PRCTL | PR_SPEC_ENABLE instead of PR_SPEC_DISABLE since both IBPB and STIPB are always on. It also allowed prctl(PR_SET_SPECULATION_CTRL) to set the IB speculation mode, even though the flag is ignored. Similarly, for CPUs without SMT, prctl(PR_GET_SPECULATION_CTRL) should also return PR_SPEC_DISABLE since IBPB is always on and STIBP is not available. [ bp: Massage commit message. ] Fixes: 21998a351512 ("x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS.") Fixes: 1978b3a53a74 ("x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP") Signed-off-by: Anand K Mistry Signed-off-by: Borislav Petkov Cc: Link: https://lkml.kernel.org/r/20201110123349.1.Id0cbf996d2151f4c143c90f9028651a5b49a5908@changeid Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -733,11 +733,13 @@ spectre_v2_user_select_mitigation(enum s if (boot_cpu_has(X86_FEATURE_IBPB)) { setup_force_cpu_cap(X86_FEATURE_USE_IBPB); + spectre_v2_user_ibpb = mode; switch (cmd) { case SPECTRE_V2_USER_CMD_FORCE: case SPECTRE_V2_USER_CMD_PRCTL_IBPB: case SPECTRE_V2_USER_CMD_SECCOMP_IBPB: static_branch_enable(&switch_mm_always_ibpb); + spectre_v2_user_ibpb = SPECTRE_V2_USER_STRICT; break; case SPECTRE_V2_USER_CMD_PRCTL: case SPECTRE_V2_USER_CMD_AUTO: @@ -751,8 +753,6 @@ spectre_v2_user_select_mitigation(enum s pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n", static_key_enabled(&switch_mm_always_ibpb) ? "always-on" : "conditional"); - - spectre_v2_user_ibpb = mode; } /*