Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp401543pxu; Tue, 1 Dec 2020 14:19:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzClSgIJXridsttsLg54n+NGhZLvgRgj1cYHkBJL4gerM9cu9VXS5aDq6Rpr38eq/bCGujV X-Received: by 2002:a50:ff05:: with SMTP id a5mr5321462edu.43.1606861195146; Tue, 01 Dec 2020 14:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861195; cv=none; d=google.com; s=arc-20160816; b=lNMsRQmRT0zJS47xaLfrjEk/GKnCx/8Dq7WqpajljTKrJ9WwAJ7K4r5oYO1fUvDU4m BObXyqdPI3aDWTZ5QHbr2/Y1vrS8LCRyu2/WJZYGVJ6tsBuAeXSnzsJJSGGBOaZEFp3H FSJExe6PV9BKL+KOHuvAysQUbw2+h98c7EAhXG98791c4285SFsmUK1uDWTQH3pWf8RH bkleEEWSqVTIt5c6jAqO7wZxLhiygXhAkxDz0NQGLc6tCIGXZKYhoG86liQsvCp1ykx5 HNQDo5jOShH+GxosTidy4ul4zSjjLTN/6bal3Lv51Wa4MmWy/CjFzxaGYWLk3yQDv4Qs ZDIA== 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=D1e9Zd41kDc5AK5zktQs81hLGLUVoa3wIewu3HcGDW5xKW3AXhU8nMKN7ubnMmG4PR 4b/yBTP38xjl1Iy285Y8zocoBGIrl7jA62thAKrXfSrCzxaIfkh8QLofW8lyn4mIV+XF SBWjyb0M//xA/vTMpPtVE4dAglIFBwFCL4Dm15ocMuNBFgAWyhFrvvY2dIm8ICIXuRJm oY12GR/FfLX+uEokh6Fy5AXBbejcbuSEucMC4W3cVFEIagBKc/OtQDB2ZHA37OW6kRsG eIIBL3z4gWWvNnOIrWiHpxypm152UK23Ch0TLlfDoX2meqXZzrGKhl20vz4A4VcBKdBM VA1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vleLZW4z; 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 e12si797150eje.644.2020.12.01.14.19.32; Tue, 01 Dec 2020 14:19:55 -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=vleLZW4z; 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 S1729041AbgLAI70 (ORCPT + 99 others); Tue, 1 Dec 2020 03:59:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:34198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388099AbgLAI7P (ORCPT ); Tue, 1 Dec 2020 03:59:15 -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 1E480206D8; Tue, 1 Dec 2020 08:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813139; bh=Fqd08q6ULXgk8oeFymIU9Q5qSM6g/VApXQdxsacXWFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vleLZW4znoxRoMQCJnxaPcQBrL+vdpb4GjEAhBxH/gAO4m3MPDiLxTC6sfvBsf+Mo 818JmLhQ5w5oTfYqkkTJBZqW8Gdxl3YMoyfwFvyIAkPSou3u7oUOnCAErjA43ofEIl ZAUrqv0avNR9QpUPyZ287506m14Uo8s5MJzoya+w= 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 4.14 46/50] x86/speculation: Fix prctl() when spectre_v2_user={seccomp,prctl},ibpb Date: Tue, 1 Dec 2020 09:53:45 +0100 Message-Id: <20201201084650.417021030@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084644.803812112@linuxfoundation.org> References: <20201201084644.803812112@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; } /*